2016-12-29 11:42:54 +01:00
|
|
|
'use strict';
|
|
|
|
|
2018-12-17 09:24:49 +01:00
|
|
|
const test = require('ava');
|
2017-06-28 10:20:22 +02:00
|
|
|
const express = require('express');
|
2016-12-29 11:42:54 +01:00
|
|
|
const proxyquire = require('proxyquire');
|
2019-04-30 21:14:23 +02:00
|
|
|
const getLogger = require('../test/fixtures/no-logger');
|
2020-04-14 22:29:11 +02:00
|
|
|
|
2016-12-29 11:42:54 +01:00
|
|
|
const getApp = proxyquire('./app', {
|
2018-11-24 12:58:30 +01:00
|
|
|
'./routes': class Index {
|
|
|
|
router() {
|
|
|
|
return express.Router();
|
|
|
|
}
|
2016-12-29 11:42:54 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should not throw when valid config', t => {
|
2019-04-30 21:14:23 +02:00
|
|
|
const app = getApp({ getLogger });
|
2016-12-29 11:42:54 +01:00
|
|
|
t.true(typeof app.listen === 'function');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should call preHook', t => {
|
|
|
|
let called = 0;
|
2017-06-28 10:17:14 +02:00
|
|
|
getApp({
|
2019-04-30 21:14:23 +02:00
|
|
|
getLogger,
|
2017-06-28 10:17:14 +02:00
|
|
|
preHook: () => {
|
|
|
|
called++;
|
|
|
|
},
|
|
|
|
});
|
2016-12-29 11:42:54 +01:00
|
|
|
t.true(called === 1);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should call preRouterHook', t => {
|
|
|
|
let called = 0;
|
2017-06-28 10:17:14 +02:00
|
|
|
getApp({
|
2019-04-30 21:14:23 +02:00
|
|
|
getLogger,
|
2017-06-28 10:17:14 +02:00
|
|
|
preRouterHook: () => {
|
|
|
|
called++;
|
|
|
|
},
|
|
|
|
});
|
2016-12-29 11:42:54 +01:00
|
|
|
t.true(called === 1);
|
|
|
|
});
|