2019-01-25 02:23:00 +03:00
|
|
|
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 = {
|
2019-01-25 06:19:37 +03:00
|
|
|
time: 1548375408533,
|
2019-01-25 02:23:00 +03:00
|
|
|
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: {uri}} = put.body;
|
|
|
|
|
2019-01-25 06:19:37 +03:00
|
|
|
const get = await agent.get('/' + uri);
|
2019-01-25 02:23:00 +03:00
|
|
|
|
|
|
|
expect(get).to.have.status(200);
|
|
|
|
});
|
|
|
|
});
|