This repository has been archived on 2022-08-14. You can view files and clone it, but cannot push or open issues or pull requests.
outline/server/commands/documentMover.test.js
Tom Moor 763f57a3dc
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
2019-04-08 21:25:13 -07:00

86 lines
2.6 KiB
JavaScript

/* eslint-disable flowtype/require-valid-file-annotation */
import documentMover from '../commands/documentMover';
import { flushdb, seed } from '../test/support';
import { buildDocument, buildCollection } from '../test/factories';
beforeEach(flushdb);
describe('documentMover', async () => {
it('should move within a collection', async () => {
const { document, collection } = await seed();
const response = await documentMover({
document,
collectionId: collection.id,
});
expect(response.collections.length).toEqual(1);
expect(response.documents.length).toEqual(1);
});
it('should move with children', async () => {
const { document, collection } = await seed();
const newDocument = await buildDocument({
parentDocumentId: document.id,
collectionId: collection.id,
teamId: collection.teamId,
userId: collection.creatorId,
title: 'Child document',
text: 'content',
});
await collection.addDocumentToStructure(newDocument);
const response = await documentMover({
document,
collectionId: collection.id,
parentDocumentId: undefined,
index: 0,
});
expect(response.collections[0].documentStructure[0].children[0].id).toBe(
newDocument.id
);
expect(response.collections.length).toEqual(1);
expect(response.documents.length).toEqual(1);
});
it('should move with children to another collection', async () => {
const { document, collection } = await seed();
const newCollection = await buildCollection({
teamId: collection.teamId,
});
const newDocument = await buildDocument({
parentDocumentId: document.id,
collectionId: collection.id,
teamId: collection.teamId,
userId: collection.creatorId,
title: 'Child document',
text: 'content',
});
await collection.addDocumentToStructure(newDocument);
const response = await documentMover({
document,
collectionId: newCollection.id,
parentDocumentId: undefined,
index: 0,
});
// check document ids where updated
await newDocument.reload();
expect(newDocument.collectionId).toBe(newCollection.id);
await document.reload();
expect(document.collectionId).toBe(newCollection.id);
// check collection structure updated
expect(response.collections[0].id).toBe(collection.id);
expect(response.collections[1].id).toBe(newCollection.id);
expect(response.collections[1].documentStructure[0].children[0].id).toBe(
newDocument.id
);
expect(response.collections.length).toEqual(2);
expect(response.documents.length).toEqual(2);
});
});