Fixes: 500 error when attempting to load a deleted document from view

This commit is contained in:
Tom Moor 2017-09-13 23:04:58 -07:00
parent 2bfeb78359
commit 229cd3271a
2 changed files with 15 additions and 0 deletions

View File

@ -43,6 +43,7 @@ router.post('documents.viewed', auth(), pagination(), async ctx => {
include: [
{
model: Document,
required: true,
include: [
{
model: Star,

View File

@ -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();