2016-04-24 22:41:37 +02:00
|
|
|
'use strict';
|
2016-10-26 10:43:11 +02:00
|
|
|
|
2014-12-03 15:22:03 +01:00
|
|
|
process.env.NODE_ENV = 'test';
|
|
|
|
|
2016-11-13 15:41:35 +01:00
|
|
|
const supertest = require('supertest');
|
2016-11-05 14:08:47 +01:00
|
|
|
|
2017-11-16 16:45:01 +01:00
|
|
|
const getApp = require('../../../lib/app');
|
|
|
|
const dbInit = require('./database-init');
|
2019-03-14 17:56:02 +01:00
|
|
|
const StateService = require('../../../lib/state-service');
|
2016-05-01 22:53:09 +02:00
|
|
|
|
2016-11-30 23:41:57 +01:00
|
|
|
const { EventEmitter } = require('events');
|
|
|
|
const eventBus = new EventEmitter();
|
|
|
|
|
2017-11-16 16:45:01 +01:00
|
|
|
function createApp(stores, adminAuthentication = 'none', preHook) {
|
|
|
|
return getApp({
|
|
|
|
stores,
|
|
|
|
eventBus,
|
|
|
|
preHook,
|
|
|
|
adminAuthentication,
|
|
|
|
secret: 'super-secret',
|
|
|
|
sessionAge: 4000,
|
2019-03-14 17:56:02 +01:00
|
|
|
stateService: new StateService({ stores }),
|
2017-06-28 10:20:22 +02:00
|
|
|
});
|
2014-12-05 17:20:17 +01:00
|
|
|
}
|
2014-11-25 14:41:11 +01:00
|
|
|
|
2017-11-16 16:45:01 +01:00
|
|
|
module.exports = {
|
|
|
|
async setupApp(name) {
|
|
|
|
const stores = await dbInit(name);
|
|
|
|
const app = createApp(stores);
|
|
|
|
|
|
|
|
return {
|
|
|
|
request: supertest.agent(app),
|
|
|
|
destroy: () => stores.db.destroy(),
|
|
|
|
};
|
|
|
|
},
|
|
|
|
async setupAppWithAuth(name) {
|
|
|
|
const stores = await dbInit(name);
|
|
|
|
const app = createApp(stores, 'unsecure');
|
|
|
|
|
|
|
|
return {
|
|
|
|
request: supertest.agent(app),
|
|
|
|
destroy: () => stores.db.destroy(),
|
|
|
|
};
|
|
|
|
},
|
2014-11-25 14:41:11 +01:00
|
|
|
|
2017-11-16 16:45:01 +01:00
|
|
|
async setupAppWithCustomAuth(name, preHook) {
|
|
|
|
const stores = await dbInit(name);
|
|
|
|
const app = createApp(stores, 'custom', preHook);
|
2014-11-25 14:41:11 +01:00
|
|
|
|
2017-11-16 16:45:01 +01:00
|
|
|
return {
|
|
|
|
request: supertest.agent(app),
|
|
|
|
destroy: () => stores.db.destroy(),
|
|
|
|
};
|
2016-11-13 15:41:35 +01:00
|
|
|
},
|
2016-04-24 22:41:37 +02:00
|
|
|
};
|