From 229cd3271a9d8efb2fe317bf4aed3943c09702dc Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Wed, 13 Sep 2017 23:04:58 -0700 Subject: [PATCH] Fixes: 500 error when attempting to load a deleted document from view --- server/api/documents.js | 1 + server/api/documents.test.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/server/api/documents.js b/server/api/documents.js index 2eb51b4f9..b617b29c5 100644 --- a/server/api/documents.js +++ b/server/api/documents.js @@ -43,6 +43,7 @@ router.post('documents.viewed', auth(), pagination(), async ctx => { include: [ { model: Document, + required: true, include: [ { model: Star, diff --git a/server/api/documents.test.js b/server/api/documents.test.js index 97ea9b02a..67cf44882 100644 --- a/server/api/documents.test.js +++ b/server/api/documents.test.js @@ -90,6 +90,20 @@ describe('#documents.viewed', async () => { expect(body.data[0].id).toEqual(document.id); }); + it('should not return recently viewed but deleted documents', async () => { + const { user, document } = await seed(); + await View.increment({ documentId: document.id, userId: user.id }); + await document.destroy(); + + const res = await server.post('/api/documents.viewed', { + body: { token: user.getJwtToken() }, + }); + const body = await res.json(); + + expect(res.status).toEqual(200); + expect(body.data.length).toEqual(0); + }); + it('should require authentication', async () => { const res = await server.post('/api/documents.viewed'); const body = await res.json();