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:
Tom Moor
2019-04-08 21:25:13 -07:00
committed by GitHub
parent 16066c0b24
commit 763f57a3dc
16 changed files with 313 additions and 146 deletions

View File

@ -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([]);
});
});
});