mirror of
https://github.com/codex-team/codex.docs.git
synced 2025-07-22 14:49:41 +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:
parent
d872e78339
commit
ccd627151f
20 changed files with 265 additions and 44 deletions
|
@ -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);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue