diff --git a/server/models/Collection.js b/server/models/Collection.js index 61f5d0c7..62ab9f88 100644 --- a/server/models/Collection.js +++ b/server/models/Collection.js @@ -442,7 +442,10 @@ Collection.prototype.getDocumentParents = function ( }); }; - loopChildren(this.documentStructure); + if (this.documentStructure) { + loopChildren(this.documentStructure); + } + return result; }; diff --git a/server/models/Collection.test.js b/server/models/Collection.test.js index 8d65f247..3858d799 100644 --- a/server/models/Collection.test.js +++ b/server/models/Collection.test.js @@ -54,6 +54,15 @@ describe("getDocumentParents", () => { const result = collection.getDocumentParents(parent.id); expect(result.length).toBe(0); }); + + test("should not error if documentStructure is empty", async () => { + const parent = await buildDocument(); + await buildDocument(); + const collection = await buildCollection(); + + const result = collection.getDocumentParents(parent.id); + expect(result).toBe(undefined); + }); }); describe("getDocumentTree", () => {