2016-12-29 11:42:54 +01:00
|
|
|
'use strict';
|
|
|
|
|
2017-06-28 10:20:22 +02:00
|
|
|
const express = require('express');
|
2021-05-28 11:10:24 +02:00
|
|
|
const { createTestConfig } = require('../test/config/test-config');
|
2020-04-14 22:29:11 +02:00
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
jest.mock(
|
|
|
|
'./routes',
|
|
|
|
() =>
|
|
|
|
class Index {
|
|
|
|
router() {
|
|
|
|
return express.Router();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
const getApp = require('./app');
|
2016-12-29 11:42:54 +01:00
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('should not throw when valid config', () => {
|
2021-04-22 10:07:10 +02:00
|
|
|
const config = createTestConfig();
|
|
|
|
const app = getApp(config, {}, {});
|
2021-05-28 11:10:24 +02:00
|
|
|
expect(typeof app.listen).toBe('function');
|
2016-12-29 11:42:54 +01:00
|
|
|
});
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('should call preHook', () => {
|
2016-12-29 11:42:54 +01:00
|
|
|
let called = 0;
|
2021-04-22 10:07:10 +02:00
|
|
|
const config = createTestConfig({
|
2017-06-28 10:17:14 +02:00
|
|
|
preHook: () => {
|
|
|
|
called++;
|
|
|
|
},
|
|
|
|
});
|
2021-04-22 10:07:10 +02:00
|
|
|
getApp(config, {}, {});
|
2021-05-28 11:10:24 +02:00
|
|
|
expect(called).toBe(1);
|
2016-12-29 11:42:54 +01:00
|
|
|
});
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('should call preRouterHook', () => {
|
2016-12-29 11:42:54 +01:00
|
|
|
let called = 0;
|
2021-04-22 10:07:10 +02:00
|
|
|
const config = createTestConfig({
|
2017-06-28 10:17:14 +02:00
|
|
|
preRouterHook: () => {
|
|
|
|
called++;
|
|
|
|
},
|
|
|
|
});
|
2021-04-22 10:07:10 +02:00
|
|
|
getApp(config, {}, {});
|
2021-05-28 11:10:24 +02:00
|
|
|
expect(called).toBe(1);
|
2016-12-29 11:42:54 +01:00
|
|
|
});
|