From 06a3258b99553909f46c5c6ac9a864bdcd49d4bf Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Thu, 7 May 2020 20:52:02 -0700 Subject: [PATCH] fix: Allow empty document body to be saved closes #1258 --- server/api/documents.js | 2 +- server/api/documents.test.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/server/api/documents.js b/server/api/documents.js index bf73b1c3..fb071556 100644 --- a/server/api/documents.js +++ b/server/api/documents.js @@ -809,7 +809,7 @@ router.post('documents.update', auth(), async ctx => { if (append) { document.text += text; - } else if (text) { + } else if (text !== undefined) { document.text = text; } document.lastModifiedById = user.id; diff --git a/server/api/documents.test.js b/server/api/documents.test.js index 7f132d74..40bb4d02 100644 --- a/server/api/documents.test.js +++ b/server/api/documents.test.js @@ -1495,6 +1495,24 @@ describe('#documents.update', async () => { expect(body).toMatchSnapshot(); }); + it('should allow setting empty text', async () => { + const { user, document } = await seed(); + + const res = await server.post('/api/documents.update', { + body: { + token: user.getJwtToken(), + id: document.id, + lastRevision: document.revision, + title: 'Updated Title', + text: '', + }, + }); + const body = await res.json(); + + expect(res.status).toEqual(200); + expect(body.data.text).toBe(''); + }); + it('should require authentication', async () => { const { document } = await seed(); const res = await server.post('/api/documents.update', {