Draft Documents (#518)

* Mostly there

* Fix up specs

* Working scope, updated tests

* Don't record view on draft

* PR feedback

* Highlight drafts nav item

* Bugaboos

* Styling

* Refactoring, gradually addressing Jori feedback

* Show collection in drafts list
Flow fixes

* Ensure menu actions are hidden when draft
This commit is contained in:
Tom Moor
2018-02-27 22:41:12 -08:00
committed by GitHub
parent 79a0272230
commit 9142d975df
30 changed files with 519 additions and 194 deletions

View File

@@ -10,9 +10,37 @@ const server = new TestServer(app.callback());
beforeEach(flushdb);
afterAll(server.close);
describe('#documents.info', async () => {
it('should return published document', async () => {
const { user, document } = await seed();
const res = await server.post('/api/documents.info', {
body: { token: user.getJwtToken(), id: document.id },
});
const body = await res.json();
expect(res.status).toEqual(200);
expect(body.data.id).toEqual(document.id);
});
it('should return drafts', async () => {
const { user, document } = await seed();
document.publishedAt = null;
await document.save();
const res = await server.post('/api/documents.info', {
body: { token: user.getJwtToken(), id: document.id },
});
const body = await res.json();
expect(res.status).toEqual(200);
expect(body.data.id).toEqual(document.id);
});
});
describe('#documents.list', async () => {
it('should return documents', async () => {
const { user, document } = await seed();
const res = await server.post('/api/documents.list', {
body: { token: user.getJwtToken() },
});
@@ -23,6 +51,20 @@ describe('#documents.list', async () => {
expect(body.data[0].id).toEqual(document.id);
});
it('should not return unpublished documents', async () => {
const { user, document } = await seed();
document.publishedAt = null;
await document.save();
const res = await server.post('/api/documents.list', {
body: { token: user.getJwtToken() },
});
const body = await res.json();
expect(res.status).toEqual(200);
expect(body.data.length).toEqual(1);
});
it('should allow changing sort direction', async () => {
const { user, document } = await seed();
const res = await server.post('/api/documents.list', {
@@ -54,6 +96,22 @@ describe('#documents.list', async () => {
});
});
describe('#documents.drafts', async () => {
it('should return unpublished documents', async () => {
const { user, document } = await seed();
document.publishedAt = null;
await document.save();
const res = await server.post('/api/documents.drafts', {
body: { token: user.getJwtToken() },
});
const body = await res.json();
expect(res.status).toEqual(200);
expect(body.data.length).toEqual(1);
});
});
describe('#documents.revision', async () => {
it("should return a document's revisions", async () => {
const { user, document } = await seed();
@@ -263,6 +321,7 @@ describe('#documents.create', async () => {
collection: collection.id,
title: 'new document',
text: 'hello',
publish: true,
},
});
const body = await res.json();
@@ -293,7 +352,7 @@ describe('#documents.create', async () => {
expect(body.data.text).toBe('# Untitled document');
});
it('should create as a child', async () => {
it('should create as a child and add to collection if published', async () => {
const { user, document, collection } = await seed();
const res = await server.post('/api/documents.create', {
body: {
@@ -302,6 +361,7 @@ describe('#documents.create', async () => {
title: 'new document',
text: 'hello',
parentDocument: document.id,
publish: true,
},
});
const body = await res.json();
@@ -328,6 +388,24 @@ describe('#documents.create', async () => {
expect(res.status).toEqual(403);
expect(body).toMatchSnapshot();
});
it('should create as a child and not add to collection', async () => {
const { user, document, collection } = await seed();
const res = await server.post('/api/documents.create', {
body: {
token: user.getJwtToken(),
collection: collection.id,
title: 'new document',
text: 'hello',
parentDocument: document.id,
},
});
const body = await res.json();
expect(res.status).toEqual(200);
expect(body.data.title).toBe('new document');
expect(body.data.collection.documents.length).toBe(2);
});
});
describe('#documents.update', async () => {