From 8d8bde4b8b76a8683ce90802c520c49545fdf495 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Mon, 22 Mar 2021 22:23:03 -0700 Subject: [PATCH] closes #1784 --- server/commands/documentMover.js | 4 ++-- server/commands/documentMover.test.js | 21 +++++++++++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/server/commands/documentMover.js b/server/commands/documentMover.js index b09422867..66572ccfd 100644 --- a/server/commands/documentMover.js +++ b/server/commands/documentMover.js @@ -45,9 +45,9 @@ export default async function documentMover({ const [ documentJson, fromIndex, - ] = await collection.removeDocumentInStructure(document, { + ] = (await collection.removeDocumentInStructure(document, { save: false, - }); + })) || [undefined, index]; // if we're reordering from within the same parent // the original and destination collection are the same, diff --git a/server/commands/documentMover.test.js b/server/commands/documentMover.test.js index 3ccee597b..dbd0b1e1c 100644 --- a/server/commands/documentMover.test.js +++ b/server/commands/documentMover.test.js @@ -1,5 +1,5 @@ -/* eslint-disable flowtype/require-valid-file-annotation */ -import { buildDocument, buildCollection } from "../test/factories"; +// @flow +import { buildDocument, buildCollection, buildUser } from "../test/factories"; import { flushdb, seed } from "../test/support"; import documentMover from "./documentMover"; @@ -22,6 +22,23 @@ describe("documentMover", () => { expect(response.documents.length).toEqual(1); }); + it("should not error when not in source collection documentStructure", async () => { + const user = await buildUser(); + const collection = await buildCollection({ teamId: user.teamId }); + const document = await buildDocument({ collectionId: collection.id }); + await document.archive(); + + const response = await documentMover({ + user, + document, + collectionId: collection.id, + ip, + }); + + expect(response.collections.length).toEqual(1); + expect(response.documents.length).toEqual(1); + }); + it("should move with children", async () => { const { document, user, collection } = await seed(); const newDocument = await buildDocument({