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

Order child pages (#21)

* save ordering pages

* move to another collection

* requested changes. Code improvements

* add margin

* unit tests

* fix

* requested changes

* recursive method: create menu tree

* update comments

* fix bug

* requested changes

* move const

* fix error message on catch

* add migration

* rewrite to splices

* move methods

* testing put above method

* linter fix
This commit is contained in:
Murod Khaydarov 2019-01-19 17:09:11 +03:00 committed by GitHub
parent dbfc594e66
commit d61818761e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 1069 additions and 2563 deletions

View file

@ -1,5 +1,6 @@
const {app} = require('../../bin/www');
const model = require('../../src/models/page');
const PageOrder = require('../../src/models/pageOrder');
const fs = require('fs');
const path = require('path');
@ -34,12 +35,12 @@ describe('Pages REST: ', () => {
text: 'Page header'
}
}
]
],
};
const parent = 0;
const res = await agent
.put('/api/page')
.send({body});
.send({body, parent});
expect(res).to.have.status(200);
expect(res).to.be.json;
@ -58,7 +59,11 @@ describe('Pages REST: ', () => {
expect(createdPage.title).to.equal(body.blocks[0].data.text);
expect(createdPage.body).to.deep.equal(body);
createdPage.destroy();
const pageOrder = await PageOrder.get('' + (createdPage.data.parent || 0));
expect(pageOrder.order).to.be.an('array');
await createdPage.destroy();
await pageOrder.destroy()
});
it('Page data validation on create', async () => {
@ -106,12 +111,14 @@ describe('Pages REST: ', () => {
expect(success).to.be.true;
const foundPage = await model.get(_id);
const pageOrder = await PageOrder.get('' + foundPage._parent);
expect(foundPage._id).to.equal(_id);
expect(foundPage.title).to.equal(body.blocks[0].data.text);
expect(foundPage.body).to.deep.equal(body);
foundPage.destroy();
await pageOrder.destroy();
await foundPage.destroy();
});
it('Finding page with not existing id', async () => {
@ -175,6 +182,7 @@ describe('Pages REST: ', () => {
expect(result.body).to.deep.equal(updatedBody);
const updatedPage = await model.get(_id);
const pageOrder = await PageOrder.get('' + updatedPage._parent);
expect(updatedPage._id).to.equal(_id);
expect(updatedPage.title).not.equal(body.blocks[0].data.text);
@ -182,7 +190,8 @@ describe('Pages REST: ', () => {
expect(updatedPage.body).not.equal(body);
expect(updatedPage.body).to.deep.equal(updatedBody);
updatedPage.destroy();
await pageOrder.destroy();
await updatedPage.destroy();
});
it('Updating page with not existing id', async () => {