fix: Error in shares.info endpoint when requesting share record for deleted document

This commit is contained in:
Tom Moor
2020-09-03 23:22:41 -07:00
parent dd7436f78c
commit e8648d4611
2 changed files with 18 additions and 4 deletions

View File

@ -29,7 +29,7 @@ router.post("shares.info", auth(), async (ctx) => {
revokedAt: { [Op.eq]: null },
},
});
if (!share) {
if (!share || !share.document) {
throw new NotFoundError();
}

View File

@ -288,11 +288,11 @@ describe("#shares.info", () => {
});
it("should not find revoked share", async () => {
const { user, admin, document } = await seed();
const { user, document } = await seed();
const share = await buildShare({
documentId: document.id,
teamId: admin.teamId,
userId: admin.id,
teamId: user.teamId,
userId: user.id,
});
await share.revoke();
const res = await server.post("/api/shares.info", {
@ -301,6 +301,20 @@ describe("#shares.info", () => {
expect(res.status).toEqual(404);
});
it("should not find share for deleted document", async () => {
const { user, document } = await seed();
await buildShare({
documentId: document.id,
teamId: user.teamId,
userId: user.id,
});
await document.delete(user.id);
const res = await server.post("/api/shares.info", {
body: { token: user.getJwtToken(), documentId: document.id },
});
expect(res.status).toEqual(404);
});
it("should require authentication", async () => {
const { user, document } = await seed();
const share = await buildShare({