chore: documentStructure database locking (#3254)
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { sequelize } from "@server/database/sequelize";
|
||||
import Pin from "@server/models/Pin";
|
||||
import {
|
||||
buildDocument,
|
||||
buildCollection,
|
||||
@@ -23,7 +25,7 @@ describe("documentMover", () => {
|
||||
expect(response.documents.length).toEqual(1);
|
||||
});
|
||||
|
||||
it("should not error when not in source collection documentStructure", async () => {
|
||||
it("should error when not in source collection documentStructure", async () => {
|
||||
const user = await buildUser();
|
||||
const collection = await buildCollection({
|
||||
teamId: user.teamId,
|
||||
@@ -32,14 +34,19 @@ describe("documentMover", () => {
|
||||
collectionId: collection.id,
|
||||
});
|
||||
await document.archive(user.id);
|
||||
const response = await documentMover({
|
||||
user,
|
||||
document,
|
||||
collectionId: collection.id,
|
||||
ip,
|
||||
});
|
||||
expect(response.collections.length).toEqual(1);
|
||||
expect(response.documents.length).toEqual(1);
|
||||
|
||||
let error;
|
||||
try {
|
||||
await documentMover({
|
||||
user,
|
||||
document,
|
||||
collectionId: collection.id,
|
||||
ip,
|
||||
});
|
||||
} catch (err) {
|
||||
error = err;
|
||||
}
|
||||
expect(error).toBeTruthy();
|
||||
});
|
||||
|
||||
it("should move with children", async () => {
|
||||
@@ -67,6 +74,7 @@ describe("documentMover", () => {
|
||||
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 to another collection", async () => {
|
||||
@@ -105,6 +113,45 @@ describe("documentMover", () => {
|
||||
expect(response.documents.length).toEqual(2);
|
||||
|
||||
expect(response.documents[0].collection.id).toEqual(newCollection.id);
|
||||
expect(response.documents[0].updatedBy.id).toEqual(user.id);
|
||||
expect(response.documents[1].collection.id).toEqual(newCollection.id);
|
||||
expect(response.documents[1].updatedBy.id).toEqual(user.id);
|
||||
});
|
||||
|
||||
it("should remove associated collection pin if moved to another collection", async () => {
|
||||
const { document, user, collection } = await seed();
|
||||
const newCollection = await buildCollection({
|
||||
teamId: collection.teamId,
|
||||
});
|
||||
await Pin.create({
|
||||
createdById: user.id,
|
||||
collectionId: collection.id,
|
||||
documentId: document.id,
|
||||
teamId: collection.teamId,
|
||||
});
|
||||
|
||||
const response = await sequelize.transaction(async (transaction) =>
|
||||
documentMover({
|
||||
user,
|
||||
document,
|
||||
collectionId: newCollection.id,
|
||||
parentDocumentId: undefined,
|
||||
index: 0,
|
||||
ip,
|
||||
transaction,
|
||||
})
|
||||
);
|
||||
|
||||
const pinCount = await Pin.count();
|
||||
expect(pinCount).toBe(0);
|
||||
|
||||
// check collection structure updated
|
||||
expect(response.collections[0].id).toBe(collection.id);
|
||||
expect(response.collections[1].id).toBe(newCollection.id);
|
||||
expect(response.collections.length).toEqual(2);
|
||||
expect(response.documents.length).toEqual(1);
|
||||
|
||||
expect(response.documents[0].collection.id).toEqual(newCollection.id);
|
||||
expect(response.documents[0].updatedBy.id).toEqual(user.id);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user