mirror of
https://github.com/codex-team/codex.docs.git
synced 2025-08-09 07:25:21 +02:00
Added missed files
This commit is contained in:
parent
d4ce1b4ce9
commit
180194c5b3
3 changed files with 41 additions and 120 deletions
|
@ -86,7 +86,8 @@ class Page {
|
||||||
this.title = this.extractTitleFromBody();
|
this.title = this.extractTitleFromBody();
|
||||||
this.uri = uri || translateString(this.title
|
this.uri = uri || translateString(this.title
|
||||||
.replace(/ /g, ' ')
|
.replace(/ /g, ' ')
|
||||||
.replace(/-/g, ' ')
|
.replace(/[^a-zA-Z0-9А-Яа-яЁё ]/g, ' ')
|
||||||
|
.replace(/ +/g, ' ')
|
||||||
.trim()
|
.trim()
|
||||||
.toLowerCase()
|
.toLowerCase()
|
||||||
.split(' ')
|
.split(' ')
|
||||||
|
|
|
@ -7,6 +7,18 @@ const {pages} = require('../../src/utils/database');
|
||||||
const translateString = require('../../src/utils/translation');
|
const translateString = require('../../src/utils/translation');
|
||||||
|
|
||||||
describe('Page model', () => {
|
describe('Page model', () => {
|
||||||
|
|
||||||
|
const transformToUri = (string) => {
|
||||||
|
return translateString(string
|
||||||
|
.replace(/ /g, ' ')
|
||||||
|
.replace(/[^a-zA-Z0-9А-Яа-яЁё ]/g, ' ')
|
||||||
|
.replace(/ +/g, ' ')
|
||||||
|
.trim()
|
||||||
|
.toLowerCase()
|
||||||
|
.split(' ')
|
||||||
|
.join('-'));
|
||||||
|
};
|
||||||
|
|
||||||
after(() => {
|
after(() => {
|
||||||
const pathToDB = path.resolve(__dirname, '../../', config.database, './pages.db');
|
const pathToDB = path.resolve(__dirname, '../../', config.database, './pages.db');
|
||||||
|
|
||||||
|
@ -60,13 +72,7 @@ describe('Page model', () => {
|
||||||
|
|
||||||
expect(data._id).to.equal(initialData._id);
|
expect(data._id).to.equal(initialData._id);
|
||||||
expect(data.title).to.equal(initialData.body.blocks[0].data.text);
|
expect(data.title).to.equal(initialData.body.blocks[0].data.text);
|
||||||
expect(data.uri).to.equal(translateString(initialData.body.blocks[0].data.text
|
expect(data.uri).to.equal(transformToUri(initialData.body.blocks[0].data.text));
|
||||||
.replace(/ /g, ' ')
|
|
||||||
.replace(/-/g, ' ')
|
|
||||||
.trim()
|
|
||||||
.toLowerCase()
|
|
||||||
.split(' ')
|
|
||||||
.join('-')));
|
|
||||||
expect(data.body).to.deep.equal(initialData.body);
|
expect(data.body).to.deep.equal(initialData.body);
|
||||||
expect(data.parent).to.be.undefined;
|
expect(data.parent).to.be.undefined;
|
||||||
|
|
||||||
|
@ -96,13 +102,7 @@ describe('Page model', () => {
|
||||||
|
|
||||||
expect(data._id).to.equal(initialData._id);
|
expect(data._id).to.equal(initialData._id);
|
||||||
expect(data.title).to.equal(update.body.blocks[0].data.text);
|
expect(data.title).to.equal(update.body.blocks[0].data.text);
|
||||||
expect(data.uri).to.equal(translateString(update.body.blocks[0].data.text
|
expect(data.uri).to.equal(transformToUri(update.body.blocks[0].data.text));
|
||||||
.replace(/ /g, ' ')
|
|
||||||
.replace(/-/g, ' ')
|
|
||||||
.trim()
|
|
||||||
.toLowerCase()
|
|
||||||
.split(' ')
|
|
||||||
.join('-')));
|
|
||||||
expect(data.body).to.equal(update.body);
|
expect(data.body).to.equal(update.body);
|
||||||
expect(data.parent).to.be.undefined;
|
expect(data.parent).to.be.undefined;
|
||||||
});
|
});
|
||||||
|
@ -126,13 +126,7 @@ describe('Page model', () => {
|
||||||
|
|
||||||
expect(savedPage._id).not.be.undefined;
|
expect(savedPage._id).not.be.undefined;
|
||||||
expect(savedPage.title).to.equal(initialData.body.blocks[0].data.text);
|
expect(savedPage.title).to.equal(initialData.body.blocks[0].data.text);
|
||||||
expect(savedPage.uri).to.equal(translateString(initialData.body.blocks[0].data.text
|
expect(savedPage.uri).to.equal(transformToUri(initialData.body.blocks[0].data.text));
|
||||||
.replace(/ /g, ' ')
|
|
||||||
.replace(/-/g, ' ')
|
|
||||||
.trim()
|
|
||||||
.toLowerCase()
|
|
||||||
.split(' ')
|
|
||||||
.join('-')));
|
|
||||||
expect(savedPage.body).to.equal(initialData.body);
|
expect(savedPage.body).to.equal(initialData.body);
|
||||||
expect(page._id).not.be.undefined;
|
expect(page._id).not.be.undefined;
|
||||||
|
|
||||||
|
@ -196,13 +190,7 @@ describe('Page model', () => {
|
||||||
const secondPage = new Page(initialData);
|
const secondPage = new Page(initialData);
|
||||||
let secondSavedPage = await secondPage.save();
|
let secondSavedPage = await secondPage.save();
|
||||||
|
|
||||||
expect(secondSavedPage.uri).to.equal(translateString(initialData.body.blocks[0].data.text
|
expect(secondSavedPage.uri).to.equal(transformToUri(initialData.body.blocks[0].data.text) + '-1');
|
||||||
.replace(/ /g, ' ')
|
|
||||||
.replace(/-/g, ' ')
|
|
||||||
.trim()
|
|
||||||
.toLowerCase()
|
|
||||||
.split(' ')
|
|
||||||
.join('-')) + '-1');
|
|
||||||
|
|
||||||
const newUri = 'new-uri';
|
const newUri = 'new-uri';
|
||||||
|
|
||||||
|
@ -214,13 +202,7 @@ describe('Page model', () => {
|
||||||
const thirdPage = new Page(initialData);
|
const thirdPage = new Page(initialData);
|
||||||
let thirdSavedPage = await thirdPage.save();
|
let thirdSavedPage = await thirdPage.save();
|
||||||
|
|
||||||
expect(thirdSavedPage.uri).to.equal(translateString(initialData.body.blocks[0].data.text
|
expect(thirdSavedPage.uri).to.equal(transformToUri(initialData.body.blocks[0].data.text));
|
||||||
.replace(/ /g, ' ')
|
|
||||||
.replace(/-/g, ' ')
|
|
||||||
.trim()
|
|
||||||
.toLowerCase()
|
|
||||||
.split(' ')
|
|
||||||
.join('-')));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Static get method', async () => {
|
it('Static get method', async () => {
|
||||||
|
@ -246,13 +228,7 @@ describe('Page model', () => {
|
||||||
|
|
||||||
expect(data._id).to.equal(savedPage._id);
|
expect(data._id).to.equal(savedPage._id);
|
||||||
expect(data.title).to.equal(initialData.body.blocks[0].data.text);
|
expect(data.title).to.equal(initialData.body.blocks[0].data.text);
|
||||||
expect(data.uri).to.equal(translateString(initialData.body.blocks[0].data.text
|
expect(data.uri).to.equal(transformToUri(initialData.body.blocks[0].data.text));
|
||||||
.replace(/ /g, ' ')
|
|
||||||
.replace(/-/g, ' ')
|
|
||||||
.trim()
|
|
||||||
.toLowerCase()
|
|
||||||
.split(' ')
|
|
||||||
.join('-')));
|
|
||||||
expect(data.body).to.deep.equal(initialData.body);
|
expect(data.body).to.deep.equal(initialData.body);
|
||||||
|
|
||||||
await page.destroy();
|
await page.destroy();
|
||||||
|
@ -293,13 +269,7 @@ describe('Page model', () => {
|
||||||
expect(foundPages.length).to.equal(2);
|
expect(foundPages.length).to.equal(2);
|
||||||
foundPages.forEach((page, i) => {
|
foundPages.forEach((page, i) => {
|
||||||
expect(page.title).to.equal(pagesToSave[i].body.blocks[0].data.text);
|
expect(page.title).to.equal(pagesToSave[i].body.blocks[0].data.text);
|
||||||
expect(page.uri).to.equal(translateString(pagesToSave[i].body.blocks[0].data.text
|
expect(page.uri).to.equal(transformToUri(pagesToSave[i].body.blocks[0].data.text));
|
||||||
.replace(/ /g, ' ')
|
|
||||||
.replace(/-/g, ' ')
|
|
||||||
.trim()
|
|
||||||
.toLowerCase()
|
|
||||||
.split(' ')
|
|
||||||
.join('-')));
|
|
||||||
expect(page.body).to.deep.equal(pagesToSave[i].body);
|
expect(page.body).to.deep.equal(pagesToSave[i].body);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -344,13 +314,7 @@ describe('Page model', () => {
|
||||||
|
|
||||||
expect(testedParent._id).to.equal(parentId);
|
expect(testedParent._id).to.equal(parentId);
|
||||||
expect(testedParent.title).to.equal(parent.body.blocks[0].data.text);
|
expect(testedParent.title).to.equal(parent.body.blocks[0].data.text);
|
||||||
expect(testedParent.uri).to.equal(translateString(parent.body.blocks[0].data.text
|
expect(testedParent.uri).to.equal(transformToUri(parent.body.blocks[0].data.text));
|
||||||
.replace(/ /g, ' ')
|
|
||||||
.replace(/-/g, ' ')
|
|
||||||
.trim()
|
|
||||||
.toLowerCase()
|
|
||||||
.split(' ')
|
|
||||||
.join('-')));
|
|
||||||
expect(testedParent.body).to.deep.equal(parent.body);
|
expect(testedParent.body).to.deep.equal(parent.body);
|
||||||
|
|
||||||
const children = await parent.children;
|
const children = await parent.children;
|
||||||
|
@ -361,13 +325,7 @@ describe('Page model', () => {
|
||||||
|
|
||||||
expect(testedChild._id).to.equal(childId);
|
expect(testedChild._id).to.equal(childId);
|
||||||
expect(testedChild.title).to.equal(child.body.blocks[0].data.text);
|
expect(testedChild.title).to.equal(child.body.blocks[0].data.text);
|
||||||
expect(testedChild.uri).to.equal(translateString(child.body.blocks[0].data.text
|
expect(testedChild.uri).to.equal(transformToUri(child.body.blocks[0].data.text));
|
||||||
.replace(/ /g, ' ')
|
|
||||||
.replace(/-/g, ' ')
|
|
||||||
.trim()
|
|
||||||
.toLowerCase()
|
|
||||||
.split(' ')
|
|
||||||
.join('-')));
|
|
||||||
expect(testedChild.body).to.deep.equal(child.body);
|
expect(testedChild.body).to.deep.equal(child.body);
|
||||||
expect(testedChild._parent).to.equal(child._parent);
|
expect(testedChild._parent).to.equal(child._parent);
|
||||||
expect(testedChild._parent).to.equal(parent._id);
|
expect(testedChild._parent).to.equal(parent._id);
|
||||||
|
|
|
@ -13,6 +13,16 @@ chai.use(chaiHTTP);
|
||||||
|
|
||||||
describe('Pages REST: ', () => {
|
describe('Pages REST: ', () => {
|
||||||
let agent;
|
let agent;
|
||||||
|
const transformToUri = (string) => {
|
||||||
|
return translateString(string
|
||||||
|
.replace(/ /g, ' ')
|
||||||
|
.replace(/[^a-zA-Z0-9А-Яа-яЁё ]/g, ' ')
|
||||||
|
.replace(/ +/g, ' ')
|
||||||
|
.trim()
|
||||||
|
.toLowerCase()
|
||||||
|
.split(' ')
|
||||||
|
.join('-'));
|
||||||
|
};
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
agent = chai.request.agent(app);
|
agent = chai.request.agent(app);
|
||||||
|
@ -50,13 +60,7 @@ describe('Pages REST: ', () => {
|
||||||
expect(success).to.be.true;
|
expect(success).to.be.true;
|
||||||
expect(result._id).to.be.a('string');
|
expect(result._id).to.be.a('string');
|
||||||
expect(result.title).to.equal(body.blocks[0].data.text);
|
expect(result.title).to.equal(body.blocks[0].data.text);
|
||||||
expect(result.uri).to.equal(translateString(body.blocks[0].data.text
|
expect(result.uri).to.equal(transformToUri(body.blocks[0].data.text));
|
||||||
.replace(/ /g, ' ')
|
|
||||||
.replace(/-/g, ' ')
|
|
||||||
.trim()
|
|
||||||
.toLowerCase()
|
|
||||||
.split(' ')
|
|
||||||
.join('-')));
|
|
||||||
expect(result.body).to.deep.equal(body);
|
expect(result.body).to.deep.equal(body);
|
||||||
|
|
||||||
const createdPage = await model.get(result._id);
|
const createdPage = await model.get(result._id);
|
||||||
|
@ -64,13 +68,7 @@ describe('Pages REST: ', () => {
|
||||||
expect(createdPage).not.be.null;
|
expect(createdPage).not.be.null;
|
||||||
expect(createdPage._id).to.equal(result._id);
|
expect(createdPage._id).to.equal(result._id);
|
||||||
expect(createdPage.title).to.equal(body.blocks[0].data.text);
|
expect(createdPage.title).to.equal(body.blocks[0].data.text);
|
||||||
expect(createdPage.uri).to.equal(translateString(body.blocks[0].data.text
|
expect(createdPage.uri).to.equal(transformToUri(body.blocks[0].data.text));
|
||||||
.replace(/ /g, ' ')
|
|
||||||
.replace(/-/g, ' ')
|
|
||||||
.trim()
|
|
||||||
.toLowerCase()
|
|
||||||
.split(' ')
|
|
||||||
.join('-')));
|
|
||||||
expect(createdPage.body).to.deep.equal(body);
|
expect(createdPage.body).to.deep.equal(body);
|
||||||
|
|
||||||
createdPage.destroy();
|
createdPage.destroy();
|
||||||
|
@ -124,13 +122,7 @@ describe('Pages REST: ', () => {
|
||||||
|
|
||||||
expect(foundPage._id).to.equal(_id);
|
expect(foundPage._id).to.equal(_id);
|
||||||
expect(foundPage.title).to.equal(body.blocks[0].data.text);
|
expect(foundPage.title).to.equal(body.blocks[0].data.text);
|
||||||
expect(foundPage.uri).to.equal(translateString(body.blocks[0].data.text
|
expect(foundPage.uri).to.equal(transformToUri(body.blocks[0].data.text));
|
||||||
.replace(/ /g, ' ')
|
|
||||||
.replace(/-/g, ' ')
|
|
||||||
.trim()
|
|
||||||
.toLowerCase()
|
|
||||||
.split(' ')
|
|
||||||
.join('-')));
|
|
||||||
expect(foundPage.body).to.deep.equal(body);
|
expect(foundPage.body).to.deep.equal(body);
|
||||||
|
|
||||||
foundPage.destroy();
|
foundPage.destroy();
|
||||||
|
@ -194,13 +186,7 @@ describe('Pages REST: ', () => {
|
||||||
expect(result._id).to.equal(_id);
|
expect(result._id).to.equal(_id);
|
||||||
expect(result.title).not.equal(body.blocks[0].data.text);
|
expect(result.title).not.equal(body.blocks[0].data.text);
|
||||||
expect(result.title).to.equal(updatedBody.blocks[0].data.text);
|
expect(result.title).to.equal(updatedBody.blocks[0].data.text);
|
||||||
expect(result.uri).not.equal(translateString(body.blocks[0].data.text
|
expect(result.uri).not.equal(transformToUri(body.blocks[0].data.text));
|
||||||
.replace(/ /g, ' ')
|
|
||||||
.replace(/-/g, ' ')
|
|
||||||
.trim()
|
|
||||||
.toLowerCase()
|
|
||||||
.split(' ')
|
|
||||||
.join('-')));
|
|
||||||
expect(result.uri).to.equal(updatedUri);
|
expect(result.uri).to.equal(updatedUri);
|
||||||
expect(result.body).not.equal(body);
|
expect(result.body).not.equal(body);
|
||||||
expect(result.body).to.deep.equal(updatedBody);
|
expect(result.body).to.deep.equal(updatedBody);
|
||||||
|
@ -210,13 +196,7 @@ describe('Pages REST: ', () => {
|
||||||
expect(updatedPage._id).to.equal(_id);
|
expect(updatedPage._id).to.equal(_id);
|
||||||
expect(updatedPage.title).not.equal(body.blocks[0].data.text);
|
expect(updatedPage.title).not.equal(body.blocks[0].data.text);
|
||||||
expect(updatedPage.title).to.equal(updatedBody.blocks[0].data.text);
|
expect(updatedPage.title).to.equal(updatedBody.blocks[0].data.text);
|
||||||
expect(updatedPage.uri).not.equal(translateString(body.blocks[0].data.text
|
expect(updatedPage.uri).not.equal(transformToUri(body.blocks[0].data.text));
|
||||||
.replace(/ /g, ' ')
|
|
||||||
.replace(/-/g, ' ')
|
|
||||||
.trim()
|
|
||||||
.toLowerCase()
|
|
||||||
.split(' ')
|
|
||||||
.join('-')));
|
|
||||||
expect(updatedPage.uri).to.equal(updatedUri);
|
expect(updatedPage.uri).to.equal(updatedUri);
|
||||||
expect(updatedPage.body).not.equal(body);
|
expect(updatedPage.body).not.equal(body);
|
||||||
expect(updatedPage.body).to.deep.equal(updatedBody);
|
expect(updatedPage.body).to.deep.equal(updatedBody);
|
||||||
|
@ -256,13 +236,7 @@ describe('Pages REST: ', () => {
|
||||||
|
|
||||||
expect(secondPageSuccess).to.be.true;
|
expect(secondPageSuccess).to.be.true;
|
||||||
expect(secondPageResult.title).to.equal(body.blocks[0].data.text);
|
expect(secondPageResult.title).to.equal(body.blocks[0].data.text);
|
||||||
expect(secondPageResult.uri).to.equal(translateString(body.blocks[0].data.text
|
expect(secondPageResult.uri).to.equal(transformToUri(body.blocks[0].data.text) + '-1');
|
||||||
.replace(/ /g, ' ')
|
|
||||||
.replace(/-/g, ' ')
|
|
||||||
.trim()
|
|
||||||
.toLowerCase()
|
|
||||||
.split(' ')
|
|
||||||
.join('-')) + '-1');
|
|
||||||
expect(secondPageResult.body).to.deep.equal(body);
|
expect(secondPageResult.body).to.deep.equal(body);
|
||||||
|
|
||||||
const newFirstPageUri = 'New uri';
|
const newFirstPageUri = 'New uri';
|
||||||
|
@ -285,13 +259,7 @@ describe('Pages REST: ', () => {
|
||||||
|
|
||||||
expect(thirdPageSuccess).to.be.true;
|
expect(thirdPageSuccess).to.be.true;
|
||||||
expect(thirdPageResult.title).to.equal(body.blocks[0].data.text);
|
expect(thirdPageResult.title).to.equal(body.blocks[0].data.text);
|
||||||
expect(thirdPageResult.uri).to.equal(translateString(body.blocks[0].data.text
|
expect(thirdPageResult.uri).to.equal(transformToUri(body.blocks[0].data.text));
|
||||||
.replace(/ /g, ' ')
|
|
||||||
.replace(/-/g, ' ')
|
|
||||||
.trim()
|
|
||||||
.toLowerCase()
|
|
||||||
.split(' ')
|
|
||||||
.join('-')));
|
|
||||||
expect(thirdPageResult.body).to.deep.equal(body);
|
expect(thirdPageResult.body).to.deep.equal(body);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -350,13 +318,7 @@ describe('Pages REST: ', () => {
|
||||||
expect(success).to.be.true;
|
expect(success).to.be.true;
|
||||||
expect(result._id).to.be.undefined;
|
expect(result._id).to.be.undefined;
|
||||||
expect(result.title).to.equal(body.blocks[0].data.text);
|
expect(result.title).to.equal(body.blocks[0].data.text);
|
||||||
expect(result.uri).to.equal(translateString(body.blocks[0].data.text
|
expect(result.uri).to.equal(transformToUri(body.blocks[0].data.text));
|
||||||
.replace(/ /g, ' ')
|
|
||||||
.replace(/-/g, ' ')
|
|
||||||
.trim()
|
|
||||||
.toLowerCase()
|
|
||||||
.split(' ')
|
|
||||||
.join('-')));
|
|
||||||
expect(result.body).to.deep.equal(body);
|
expect(result.body).to.deep.equal(body);
|
||||||
|
|
||||||
const deletedPage = await model.get(_id);
|
const deletedPage = await model.get(_id);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue