1
0
Fork 0
mirror of https://github.com/codex-team/codex.docs.git synced 2025-07-23 07:09:42 +02:00

Page creation basics (#7)

* Page cration basics

* remove unused code

* add client-side Header validation

* remove static method

* rm await duplication
This commit is contained in:
Peter Savchenko 2018-10-04 22:08:21 +03:00 committed by GitHub
parent 5c0560a2ed
commit 073772c047
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 476 additions and 93 deletions

View file

@ -15,12 +15,20 @@ describe('Pages REST: ', () => {
});
it('Creating page', async () => {
const title = 'Test page';
const body = 'Test page body';
const body = {
blocks: [
{
type: 'header',
data: {
text: 'Page header'
}
}
]
};
const res = await agent
.put('/page')
.send({title, body});
.send({body});
expect(res).to.have.status(200);
expect(res).to.be.json;
@ -29,15 +37,15 @@ describe('Pages REST: ', () => {
expect(success).to.be.true;
expect(result._id).to.be.a('string');
expect(result.title).to.equal(title);
expect(result.body).to.equal(body);
expect(result.title).to.equal(body.blocks[0].data.text);
expect(result.body).to.deep.equal(body);
const createdPage = await model.get(result._id);
expect(createdPage).not.be.null;
expect(createdPage._id).to.equal(result._id);
expect(createdPage.title).to.equal(title);
expect(createdPage.body).to.equal(body);
expect(createdPage.title).to.equal(body.blocks[0].data.text);
expect(createdPage.body).to.deep.equal(body);
createdPage.destroy();
});
@ -53,16 +61,24 @@ describe('Pages REST: ', () => {
const {success, error} = res.body;
expect(success).to.be.false;
expect(error).to.equal('Invalid request format');
expect(error).to.equal('Error: Some of required fields is missed');
});
it('Finding page', async () => {
const title = 'Test page';
const body = 'Test page body';
const body = {
blocks: [
{
type: 'header',
data: {
text: 'Page header'
}
}
]
};
const put = await agent
.put('/page')
.send({title, body});
.send({body});
expect(put).to.have.status(200);
expect(put).to.be.json;
@ -81,8 +97,8 @@ describe('Pages REST: ', () => {
const foundPage = await model.get(_id);
expect(foundPage._id).to.equal(_id);
expect(foundPage.title).to.equal(title);
expect(foundPage.body).to.equal(body);
expect(foundPage.title).to.equal(body.blocks[0].data.text);
expect(foundPage.body).to.deep.equal(body);
foundPage.destroy();
});
@ -100,24 +116,40 @@ describe('Pages REST: ', () => {
});
it('Updating page', async () => {
const title = 'Test page';
const body = 'Test page body';
const body = {
blocks: [
{
type: 'header',
data: {
text: 'Page header'
}
}
]
};
let res = await agent
.put('/page')
.send({title, body});
.send({body});
expect(res).to.have.status(200);
expect(res).to.be.json;
const {result: {_id}} = res.body;
const updatedTitle = 'Updated test page';
const updatedBody = 'Updated test page body';
const updatedBody = {
blocks: [
{
type: 'header',
data: {
text: 'Updated page header'
}
}
]
};
res = await agent
.post(`/page/${_id}`)
.send({title: updatedTitle, body: updatedBody});
.send({body: updatedBody});
expect(res).to.have.status(200);
expect(res).to.be.json;
@ -126,26 +158,35 @@ describe('Pages REST: ', () => {
expect(success).to.be.true;
expect(result._id).to.equal(_id);
expect(result.title).not.equal(title);
expect(result.title).to.equal(updatedTitle);
expect(result.title).not.equal(body.blocks[0].data.text);
expect(result.title).to.equal(updatedBody.blocks[0].data.text);
expect(result.body).not.equal(body);
expect(result.body).to.equal(updatedBody);
expect(result.body).to.deep.equal(updatedBody);
const updatedPage = await model.get(_id);
expect(updatedPage._id).to.equal(_id);
expect(updatedPage.title).not.equal(title);
expect(updatedPage.title).to.equal(updatedTitle);
expect(updatedPage.title).not.equal(body.blocks[0].data.text);
expect(updatedPage.title).to.equal(updatedBody.blocks[0].data.text);
expect(updatedPage.body).not.equal(body);
expect(updatedPage.body).to.equal(updatedBody);
expect(updatedPage.body).to.deep.equal(updatedBody);
updatedPage.destroy();
});
it('Updating page with not existing id', async () => {
const res = await agent
. post('/page/not-existing-id')
.send({title: 'Updated title', body: 'Updated body'});
.post('/page/not-existing-id')
.send({body: {
blocks: [
{
type: 'header',
data: {
text: 'Page header'
}
}
]
}});
expect(res).to.have.status(400);
expect(res).to.be.json;
@ -157,12 +198,20 @@ describe('Pages REST: ', () => {
});
it('Removing page', async () => {
const title = 'Test page';
const body = 'Test page body';
const body = {
blocks: [
{
type: 'header',
data: {
text: 'Page header'
}
}
]
};
let res = await agent
.put('/page')
.send({title, body});
.send({body});
expect(res).to.have.status(200);
expect(res).to.be.json;
@ -179,8 +228,8 @@ describe('Pages REST: ', () => {
expect(success).to.be.true;
expect(result._id).to.be.undefined;
expect(result.title).to.equal(title);
expect(result.body).to.equal(body);
expect(result.title).to.equal(body.blocks[0].data.text);
expect(result.body).to.deep.equal(body);
const deletedPage = await model.get(_id);