chore: Improvements to document move behavior (#4689)
* chore: Improvements to document move behavior * test
This commit is contained in:
@@ -1,10 +1,6 @@
|
||||
import { sequelize } from "@server/database/sequelize";
|
||||
import Pin from "@server/models/Pin";
|
||||
import {
|
||||
buildDocument,
|
||||
buildCollection,
|
||||
buildUser,
|
||||
} from "@server/test/factories";
|
||||
import { buildDocument, buildCollection } from "@server/test/factories";
|
||||
import { setupTestDatabase, seed } from "@server/test/support";
|
||||
import documentMover from "./documentMover";
|
||||
|
||||
@@ -25,28 +21,31 @@ describe("documentMover", () => {
|
||||
expect(response.documents.length).toEqual(1);
|
||||
});
|
||||
|
||||
it("should error when not in source collection documentStructure", async () => {
|
||||
const user = await buildUser();
|
||||
const collection = await buildCollection({
|
||||
teamId: user.teamId,
|
||||
});
|
||||
const document = await buildDocument({
|
||||
it("should succeed when not in source collection documentStructure", async () => {
|
||||
const { document, user, collection } = await seed();
|
||||
const newDocument = await buildDocument({
|
||||
parentDocumentId: document.id,
|
||||
collectionId: collection.id,
|
||||
teamId: collection.teamId,
|
||||
userId: collection.createdById,
|
||||
title: "Child document",
|
||||
text: "content",
|
||||
});
|
||||
await document.archive(user.id);
|
||||
|
||||
let error;
|
||||
try {
|
||||
await documentMover({
|
||||
user,
|
||||
document,
|
||||
collectionId: collection.id,
|
||||
ip,
|
||||
});
|
||||
} catch (err) {
|
||||
error = err;
|
||||
}
|
||||
expect(error).toBeTruthy();
|
||||
const response = await documentMover({
|
||||
user,
|
||||
document,
|
||||
collectionId: collection.id,
|
||||
parentDocumentId: undefined,
|
||||
index: 0,
|
||||
ip,
|
||||
});
|
||||
expect(response.collections[0].documentStructure![0].children[0].id).toBe(
|
||||
newDocument.id
|
||||
);
|
||||
expect(response.collections.length).toEqual(1);
|
||||
expect(response.documents.length).toEqual(1);
|
||||
expect(response.documents[0].collection?.id).toEqual(collection.id);
|
||||
expect(response.documents[0].updatedBy.id).toEqual(user.id);
|
||||
});
|
||||
|
||||
it("should move with children", async () => {
|
||||
|
||||
Reference in New Issue
Block a user