mirror of
https://github.com/codex-team/codex.docs.git
synced 2025-08-08 15:05:26 +02:00
Added tests for aliases
This commit is contained in:
parent
06280ae0f6
commit
b611b41a5c
2 changed files with 60 additions and 2 deletions
|
@ -3,8 +3,8 @@ const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const config = require('../../config');
|
const config = require('../../config');
|
||||||
const Alias = require('../../src/models/alias');
|
const Alias = require('../../src/models/alias');
|
||||||
const md5 = require('../utils/md5');
|
const md5 = require('../../src/utils/md5');
|
||||||
const aliasTypes = require('../constants/aliasTypes');
|
const aliasTypes = require('../../src/constants/aliasTypes');
|
||||||
const {aliases} = require('../../src/utils/database');
|
const {aliases} = require('../../src/utils/database');
|
||||||
|
|
||||||
describe('Alias model', () => {
|
describe('Alias model', () => {
|
||||||
|
|
58
test/rest/aliases.js
Normal file
58
test/rest/aliases.js
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
const {app} = require('../../bin/www');
|
||||||
|
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
const config = require('../../config');
|
||||||
|
const chai = require('chai');
|
||||||
|
const chaiHTTP = require('chai-http');
|
||||||
|
const {expect} = chai;
|
||||||
|
|
||||||
|
chai.use(chaiHTTP);
|
||||||
|
|
||||||
|
describe('Aliases REST: ', () => {
|
||||||
|
let agent;
|
||||||
|
|
||||||
|
before(async () => {
|
||||||
|
agent = chai.request.agent(app);
|
||||||
|
});
|
||||||
|
|
||||||
|
after(async () => {
|
||||||
|
const pathToDB = path.resolve(__dirname, '../../', config.database, './pages.db');
|
||||||
|
|
||||||
|
if (fs.existsSync(pathToDB)) {
|
||||||
|
fs.unlinkSync(pathToDB);
|
||||||
|
}
|
||||||
|
|
||||||
|
const pathToAliasDB = path.resolve(__dirname, '../../', config.database, './aliases.db');
|
||||||
|
|
||||||
|
if (fs.existsSync(pathToAliasDB)) {
|
||||||
|
fs.unlinkSync(pathToAliasDB);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Finding page with alias', async () => {
|
||||||
|
const body = {
|
||||||
|
blocks: [
|
||||||
|
{
|
||||||
|
type: 'header',
|
||||||
|
data: {
|
||||||
|
text: 'Test header'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
const put = await agent
|
||||||
|
.put('/api/page')
|
||||||
|
.send({body});
|
||||||
|
|
||||||
|
expect(put).to.have.status(200);
|
||||||
|
expect(put).to.be.json;
|
||||||
|
|
||||||
|
const {result: {_id}} = put.body;
|
||||||
|
|
||||||
|
const get = await agent.get(`/api/page/${_id}`);
|
||||||
|
|
||||||
|
expect(get).to.have.status(200);
|
||||||
|
});
|
||||||
|
});
|
Loading…
Add table
Add a link
Reference in a new issue