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

remove pages (#27)

* remove pages

* requested changes and unit tests

* update

* fix unit test

* requested changes

* add confirmation

* remove deeply

* remove log

* bugfix

* update placeholder
This commit is contained in:
Murod Khaydarov 2019-01-25 06:19:37 +03:00 committed by GitHub
parent d872e78339
commit ccd627151f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 265 additions and 44 deletions

View file

@ -38,7 +38,7 @@ describe('Page model', () => {
expect(data.title).to.be.empty;
expect(data.uri).to.be.empty;
expect(data.body).to.be.undefined;
expect(data.parent).to.be.undefined;
expect(data.parent).to.be.equal('0');
page = new Page(null);
@ -48,7 +48,7 @@ describe('Page model', () => {
expect(data.title).to.be.empty;
expect(data.uri).to.be.empty;
expect(data.body).to.be.undefined;
expect(data.parent).to.be.undefined;
expect(data.parent).to.be.equal('0');
const initialData = {
_id: 'page_id',
@ -74,13 +74,13 @@ describe('Page model', () => {
expect(data.title).to.equal(initialData.body.blocks[0].data.text);
expect(data.uri).to.be.empty;
expect(data.body).to.deep.equal(initialData.body);
expect(data.parent).to.be.undefined;
expect(data.parent).to.be.equal('0');
expect(json._id).to.equal(initialData._id);
expect(json.title).to.equal(initialData.body.blocks[0].data.text);
expect(json.title).to.equal(initialData.body.blocks[0].data.text);
expect(json.body).to.deep.equal(initialData.body);
expect(json.parent).to.be.undefined;
expect(json.parent).to.be.equal('0');
const update = {
_id: 12345,
@ -104,7 +104,7 @@ describe('Page model', () => {
expect(data.title).to.equal(update.body.blocks[0].data.text);
expect(data.uri).to.be.empty;
expect(data.body).to.equal(update.body);
expect(data.parent).to.be.undefined;
expect(data.parent).to.be.equal('0');
});
it('Saving, updating and deleting model in the database', async () => {
@ -352,4 +352,31 @@ describe('Page model', () => {
expect(page.title).to.equal(pageData.body.blocks[0].data.text);
});
it('test deletion', async () => {
const pages = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
const orders = {
'0' : ['1', '2', '3'],
'1' : ['4', '5'],
'5' : ['6', '7', '8'],
'3' : ['9']
};
function deleteRecursively(startFrom) {
const order = orders[startFrom];
if (!order) {
const found = pages.indexOf(startFrom);
pages.splice(found, 1);
return;
}
order.forEach(id => {
deleteRecursively(id);
});
const found = pages.indexOf(startFrom);
pages.splice(found, 1);
}
});
});

View file

@ -7,7 +7,7 @@ const {pagesOrder} = require('../../src/utils/database');
describe('PageOrder model', () => {
after(() => {
const pathToDB = path.resolve(__dirname, '../../', config.database, './pages.db');
const pathToDB = path.resolve(__dirname, '../../', config.database, './pagesOrder.db');
if (fs.existsSync(pathToDB)) {
fs.unlinkSync(pathToDB);

View file

@ -32,6 +32,7 @@ describe('Aliases REST: ', () => {
it('Finding page with alias', async () => {
const body = {
time: 1548375408533,
blocks: [
{
type: 'header',
@ -51,7 +52,7 @@ describe('Aliases REST: ', () => {
const {result: {uri}} = put.body;
const get = await agent.get(`/${uri}`);
const get = await agent.get('/' + uri);
expect(get).to.have.status(200);
});

View file

@ -30,10 +30,20 @@ describe('Pages REST: ', () => {
});
after(async () => {
const pathToDB = path.resolve(__dirname, '../../', config.database, './pages.db');
const pathToPagesDB = path.resolve(__dirname, '../../', config.database, './pages.db');
const pathToPagesOrderDB = path.resolve(__dirname, '../../', config.database, './pagesOrder.db');
const pathToAliasesDB = path.resolve(__dirname, '../../', config.database, './aliases.db');
if (fs.existsSync(pathToDB)) {
fs.unlinkSync(pathToDB);
if (fs.existsSync(pathToPagesDB)) {
fs.unlinkSync(pathToPagesDB);
}
if (fs.existsSync(pathToPagesOrderDB)) {
fs.unlinkSync(pathToPagesOrderDB);
}
if (fs.existsSync(pathToAliasesDB)) {
fs.unlinkSync(pathToAliasesDB);
}
});
@ -325,14 +335,18 @@ describe('Pages REST: ', () => {
const {success, result} = res.body;
expect(success).to.be.true;
expect(result._id).to.be.undefined;
expect(result.title).to.equal(body.blocks[0].data.text);
expect(result.uri).to.equal(transformToUri(body.blocks[0].data.text));
expect(result.body).to.deep.equal(body);
const deletedPage = await model.get(_id);
if (result) {
expect(result._id).to.be.undefined;
expect(result.title).to.equal(body.blocks[0].data.text);
expect(result.uri).to.equal(transformToUri(body.blocks[0].data.text));
expect(result.body).to.deep.equal(body);
const deletedPage = await model.get(_id);
expect(deletedPage._id).to.be.undefined;
expect(deletedPage._id).to.be.undefined;
} else {
expect(result).to.be.null;
}
});
it('Removing page with not existing id', async () => {