From 2e64972574cfb9734c66e475c6b75b839af1eec1 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Wed, 31 Mar 2021 18:04:40 -0700 Subject: [PATCH] fix: Error in shares.info endpoint when user originally creating share has been deleted --- server/api/shares.test.js | 22 ++++++++++++++++++++++ server/models/Share.js | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/server/api/shares.test.js b/server/api/shares.test.js index 49b316c1..20402490 100644 --- a/server/api/shares.test.js +++ b/server/api/shares.test.js @@ -257,6 +257,28 @@ describe("#shares.info", () => { expect(res.status).toEqual(200); expect(body.data.id).toBe(share.id); + expect(body.data.createdBy.id).toBe(user.id); + }); + + it("should allow reading share creaded by deleted user", async () => { + const { user, document } = await seed(); + const author = await buildUser({ teamId: user.teamId }); + const share = await buildShare({ + documentId: document.id, + teamId: author.teamId, + userId: author.id, + }); + + await author.destroy(); + + const res = await server.post("/api/shares.info", { + body: { token: user.getJwtToken(), id: share.id }, + }); + const body = await res.json(); + + expect(res.status).toEqual(200); + expect(body.data.id).toBe(share.id); + expect(body.data.createdBy.id).toBe(author.id); }); it("should allow reading share by documentId", async () => { diff --git a/server/models/Share.js b/server/models/Share.js index b8ddec13..ae28f40c 100644 --- a/server/models/Share.js +++ b/server/models/Share.js @@ -37,7 +37,7 @@ Share.associate = (models) => { }); Share.addScope("defaultScope", { include: [ - { association: "user" }, + { association: "user", paranoid: false }, { association: "document" }, { association: "team" }, ],