diff --git a/server/api/__snapshots__/documents.test.js.snap b/server/api/__snapshots__/documents.test.js.snap index d7d09f8ae..cda46a768 100644 --- a/server/api/__snapshots__/documents.test.js.snap +++ b/server/api/__snapshots__/documents.test.js.snap @@ -1,5 +1,14 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`#documents.create should create as a child 1`] = ` +Object { + "error": "invalid_parent_document", + "message": "Invalid parentDocument", + "ok": false, + "status": 400, +} +`; + exports[`#documents.list should require authentication 1`] = ` Object { "error": "authentication_required", diff --git a/server/api/documents.js b/server/api/documents.js index 1c29fead3..949dcb8c1 100644 --- a/server/api/documents.js +++ b/server/api/documents.js @@ -218,6 +218,8 @@ router.post('documents.create', auth(), async ctx => { atlasId: ownerCollection.id, }, }); + if (!parentDocumentObj) + throw httpErrors.BadRequest('Invalid parentDocument'); } const newDocument = await Document.create({ diff --git a/server/api/documents.test.js b/server/api/documents.test.js index d579af822..509050578 100644 --- a/server/api/documents.test.js +++ b/server/api/documents.test.js @@ -281,6 +281,23 @@ describe('#documents.create', async () => { expect(body.data.collection.documents.length).toBe(2); expect(body.data.collection.documents[1].children[0].id).toBe(body.data.id); }); + + it('should create as a child', async () => { + const { user, collection } = await seed(); + const res = await server.post('/api/documents.create', { + body: { + token: user.getJwtToken(), + collection: collection.id, + title: 'new document', + text: 'hello', + parentDocument: 'd7a4eb73-fac1-4028-af45-d7e34d54db8e', + }, + }); + const body = await res.json(); + + expect(res.status).toEqual(400); + expect(body).toMatchSnapshot(); + }); }); describe('#documents.update', async () => {