2017-06-06 09:56:29 +02:00
|
|
|
'use strict';
|
|
|
|
|
2017-06-28 10:17:14 +02:00
|
|
|
const { test } = require('ava');
|
2017-06-06 09:56:29 +02:00
|
|
|
const proxyquire = require('proxyquire');
|
2017-06-28 10:20:22 +02:00
|
|
|
const express = require('express');
|
2017-06-06 09:56:29 +02:00
|
|
|
|
|
|
|
const getApp = proxyquire('./app', {
|
2018-11-24 12:58:30 +01:00
|
|
|
'./routes': class Index {
|
|
|
|
router() {
|
|
|
|
return express.Router();
|
|
|
|
}
|
2017-06-06 09:56:29 +02:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const serverImpl = proxyquire('./server-impl', {
|
|
|
|
'./app': getApp,
|
|
|
|
'./metrics': {
|
2017-06-28 10:17:14 +02:00
|
|
|
startMonitoring(o) {
|
2017-06-06 09:56:29 +02:00
|
|
|
return o;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'./db': {
|
2017-06-28 10:17:14 +02:00
|
|
|
createStores(o) {
|
2017-06-06 09:56:29 +02:00
|
|
|
return o;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'./options': {
|
2017-06-28 10:17:14 +02:00
|
|
|
createOptions(o) {
|
2017-06-06 09:56:29 +02:00
|
|
|
return o;
|
|
|
|
},
|
|
|
|
},
|
2017-06-28 10:17:14 +02:00
|
|
|
'../migrator'() {
|
2017-06-06 09:56:29 +02:00
|
|
|
return Promise.resolve();
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should call preHook', async t => {
|
|
|
|
let called = 0;
|
|
|
|
await serverImpl.start({
|
2017-06-28 10:20:22 +02:00
|
|
|
port: 0,
|
2017-06-06 09:56:29 +02:00
|
|
|
preHook: () => {
|
|
|
|
called++;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
t.true(called === 1);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should call preRouterHook', async t => {
|
|
|
|
let called = 0;
|
2017-06-28 10:20:22 +02:00
|
|
|
await serverImpl.start({
|
|
|
|
port: 0,
|
|
|
|
preRouterHook: () => {
|
|
|
|
called++;
|
|
|
|
},
|
|
|
|
});
|
2017-06-06 09:56:29 +02:00
|
|
|
t.true(called === 1);
|
|
|
|
});
|