2022-03-05 22:57:23 +04:00
|
|
|
import fs from 'fs';
|
|
|
|
import path from 'path';
|
|
|
|
import config from 'config';
|
|
|
|
import chai from 'chai';
|
|
|
|
import chaiHTTP from 'chai-http';
|
|
|
|
import server from '../../bin/server';
|
2019-01-25 02:23:00 +03:00
|
|
|
|
|
|
|
const {expect} = chai;
|
2022-03-05 22:57:23 +04:00
|
|
|
const app = server.app;
|
2019-01-25 02:23:00 +03:00
|
|
|
|
|
|
|
chai.use(chaiHTTP);
|
|
|
|
|
|
|
|
describe('Aliases REST: ', () => {
|
2022-03-05 22:57:23 +04:00
|
|
|
let agent: ChaiHttp.Agent;
|
2019-01-25 02:23:00 +03:00
|
|
|
|
|
|
|
before(async () => {
|
|
|
|
agent = chai.request.agent(app);
|
|
|
|
});
|
|
|
|
|
|
|
|
after(async () => {
|
2022-03-05 22:57:23 +04:00
|
|
|
const pathToDB = path.resolve(__dirname, '../../', config.get('database'), './pages.db');
|
2019-01-25 02:23:00 +03:00
|
|
|
|
|
|
|
if (fs.existsSync(pathToDB)) {
|
|
|
|
fs.unlinkSync(pathToDB);
|
|
|
|
}
|
|
|
|
|
2022-03-05 22:57:23 +04:00
|
|
|
const pathToAliasDB = path.resolve(__dirname, '../../', config.get('database'), './aliases.db');
|
2019-01-25 02:23:00 +03:00
|
|
|
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|