Move document improvements (#927)
* Show all collections in UI * Introduce command pattern * Actually remove from previous collection * Stash * Fixes: Promises resolved outside of response lifecycle * 💚 * 💚 * documentMover tests * Transaction * Perf. More in transactions
This commit is contained in:
@ -145,37 +145,7 @@ describe('#updateDocument', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#moveDocument', () => {
|
||||
test('should move a document without children', async () => {
|
||||
const { collection, document } = await seed();
|
||||
|
||||
expect(collection.documentStructure[1].id).toBe(document.id);
|
||||
await collection.moveDocument(document, 0);
|
||||
expect(collection.documentStructure[0].id).toBe(document.id);
|
||||
});
|
||||
|
||||
test('should move a document with children', async () => {
|
||||
const { collection, document } = await seed();
|
||||
const newDocument = await Document.create({
|
||||
parentDocumentId: document.id,
|
||||
collectionId: collection.id,
|
||||
teamId: collection.teamId,
|
||||
userId: collection.creatorId,
|
||||
lastModifiedById: collection.creatorId,
|
||||
createdById: collection.creatorId,
|
||||
title: 'Child document',
|
||||
text: 'content',
|
||||
});
|
||||
await collection.addDocumentToStructure(newDocument);
|
||||
|
||||
await collection.moveDocument(document, 0);
|
||||
expect(collection.documentStructure[0].children[0].id).toBe(newDocument.id);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#removeDocument', () => {
|
||||
const destroyMock = jest.fn();
|
||||
|
||||
test('should save if removing', async () => {
|
||||
const { collection, document } = await seed();
|
||||
jest.spyOn(collection, 'save');
|
||||
@ -260,18 +230,4 @@ describe('#removeDocument', () => {
|
||||
});
|
||||
expect(collectionDocuments.count).toBe(2);
|
||||
});
|
||||
|
||||
describe('options: deleteDocument = false', () => {
|
||||
test('should remove documents from the structure but not destroy them from the DB', async () => {
|
||||
const { collection, document } = await seed();
|
||||
jest.spyOn(collection, 'save');
|
||||
|
||||
const removedNode = await collection.removeDocumentInStructure(document);
|
||||
expect(collection.documentStructure.length).toBe(1);
|
||||
expect(destroyMock).not.toBeCalled();
|
||||
expect(collection.save).not.toBeCalled();
|
||||
expect(removedNode.id).toBe(document.id);
|
||||
expect(removedNode.children).toEqual([]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user