1
0
Fork 0
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:
DorofeevMark 2018-12-30 22:30:25 +03:00
parent 06280ae0f6
commit b611b41a5c
2 changed files with 60 additions and 2 deletions

View file

@ -3,8 +3,8 @@ const fs = require('fs');
const path = require('path');
const config = require('../../config');
const Alias = require('../../src/models/alias');
const md5 = require('../utils/md5');
const aliasTypes = require('../constants/aliasTypes');
const md5 = require('../../src/utils/md5');
const aliasTypes = require('../../src/constants/aliasTypes');
const {aliases} = require('../../src/utils/database');
describe('Alias model', () => {

58
test/rest/aliases.js Normal file
View 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);
});
});