Move title validation to server (#552)

closes issue-546
This commit is contained in:
Tom Moor
2018-01-31 19:23:33 -08:00
committed by Jori Lallo
parent c24ef20a24
commit ae4aed6fe0
4 changed files with 54 additions and 17 deletions

View File

@ -247,6 +247,22 @@ describe('#documents.create', async () => {
expect(newDocument.collection.id).toBe(collection.id);
});
it('should fallback to a default title', async () => {
const { user, collection } = await seed();
const res = await server.post('/api/documents.create', {
body: {
token: user.getJwtToken(),
collection: collection.id,
title: ' ',
text: ' ',
},
});
const body = await res.json();
expect(res.status).toEqual(200);
expect(body.data.title).toBe('Untitled document');
expect(body.data.text).toBe('# Untitled document');
});
it('should create as a child', async () => {
const { user, document, collection } = await seed();
const res = await server.post('/api/documents.create', {
@ -288,6 +304,26 @@ describe('#documents.update', async () => {
expect(body.data.collection.documents[1].title).toBe('Updated title');
});
it('should fallback to a default title', async () => {
const { user, document } = await seed();
const res = await server.post('/api/documents.update', {
body: {
token: user.getJwtToken(),
id: document.id,
title: ' ',
text: ' ',
lastRevision: document.revision,
},
});
const body = await res.json();
expect(res.status).toEqual(200);
expect(body.data.title).toBe('Untitled document');
expect(body.data.text).toBe('# Untitled document');
expect(body.data.collection.documents[1].title).toBe('Untitled document');
});
it('should fail if document lastRevision does not match', async () => {
const { user, document } = await seed();