2022-01-09 20:51:50 +01:00
|
|
|
import express from 'express';
|
2023-08-28 23:03:36 +02:00
|
|
|
import got from 'got-cjs';
|
|
|
|
import { rimrafSync } from 'rimraf';
|
2014-12-22 20:58:25 +03:00
|
|
|
|
2022-01-09 20:51:50 +01:00
|
|
|
import endPointAPI from '../../../src/api/index';
|
|
|
|
import { API_ERROR } from '../../../src/lib/constants';
|
2019-07-16 08:40:01 +02:00
|
|
|
import { setup } from '../../../src/lib/logger';
|
2022-01-09 20:51:50 +01:00
|
|
|
import config from '../partials/config/index';
|
2019-07-16 08:40:01 +02:00
|
|
|
|
2021-03-14 08:42:46 +01:00
|
|
|
setup([{ type: 'stdout', format: 'pretty', level: 'trace' }]);
|
2019-07-16 08:40:01 +02:00
|
|
|
|
2017-11-01 17:47:20 +01:00
|
|
|
const app = express();
|
|
|
|
const server = require('http').createServer(app);
|
|
|
|
|
|
|
|
describe('basic system test', () => {
|
2017-04-19 21:15:28 +02:00
|
|
|
let port;
|
2019-07-08 09:20:16 +02:00
|
|
|
jest.setTimeout(20000);
|
2014-12-22 20:58:25 +03:00
|
|
|
|
2023-08-28 23:03:36 +02:00
|
|
|
beforeAll(function () {
|
|
|
|
rimrafSync(__dirname + '/store/test-storage');
|
2017-04-19 21:15:28 +02:00
|
|
|
});
|
2014-12-22 20:58:25 +03:00
|
|
|
|
2023-01-19 00:09:24 +01:00
|
|
|
beforeAll(async function () {
|
2019-02-24 23:20:25 +01:00
|
|
|
app.use(await endPointAPI(config()));
|
2014-12-22 20:58:25 +03:00
|
|
|
|
2023-01-19 00:09:24 +01:00
|
|
|
await new Promise((resolve) => {
|
|
|
|
server.listen(0, function () {
|
|
|
|
port = server.address().port;
|
2023-08-28 23:03:36 +02:00
|
|
|
resolve(true);
|
2023-01-19 00:09:24 +01:00
|
|
|
});
|
2017-04-19 21:15:28 +02:00
|
|
|
});
|
|
|
|
});
|
2014-12-22 20:58:25 +03:00
|
|
|
|
2017-11-01 17:47:20 +01:00
|
|
|
afterAll((done) => {
|
|
|
|
server.close(done);
|
|
|
|
});
|
|
|
|
|
2023-08-28 23:03:36 +02:00
|
|
|
test('server should respond on /', (done) => {
|
|
|
|
got.get('http://localhost:' + port + '/').then((res) => {
|
|
|
|
expect(res.body).toMatch('DOCTYPE');
|
|
|
|
done();
|
|
|
|
});
|
2022-01-09 20:31:26 +01:00
|
|
|
}, 10000);
|
2014-12-22 20:58:25 +03:00
|
|
|
|
2021-03-14 08:42:46 +01:00
|
|
|
test('server should respond on /___not_found_package', (done) => {
|
2023-08-28 23:03:36 +02:00
|
|
|
got
|
|
|
|
.get(`http://localhost:${port}/___not_found_package`, { responseType: 'json' })
|
|
|
|
.then((res) => {})
|
|
|
|
.catch((err) => {
|
|
|
|
expect(err.code).toEqual('ERR_NON_2XX_3XX_RESPONSE');
|
2021-03-14 08:42:46 +01:00
|
|
|
done();
|
2023-08-28 23:03:36 +02:00
|
|
|
});
|
2022-01-09 20:31:26 +01:00
|
|
|
}, 10000);
|
2017-04-19 21:15:28 +02:00
|
|
|
});
|