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
|
|
|
|
2020-04-14 22:29:11 +02:00
|
|
|
const { EventEmitter } = require('events');
|
2017-11-16 16:45:01 +01:00
|
|
|
const getApp = require('../../../lib/app');
|
2019-04-30 21:14:23 +02:00
|
|
|
const getLogger = require('../../fixtures/no-logger');
|
2020-12-17 19:22:30 +01:00
|
|
|
const { createServices } = require('../../../lib/services');
|
2016-05-01 22:53:09 +02:00
|
|
|
|
2016-11-30 23:41:57 +01:00
|
|
|
const eventBus = new EventEmitter();
|
|
|
|
|
2017-11-16 16:45:01 +01:00
|
|
|
function createApp(stores, adminAuthentication = 'none', preHook) {
|
2020-12-17 19:22:30 +01:00
|
|
|
const config = {
|
|
|
|
stores,
|
|
|
|
eventBus,
|
|
|
|
preHook,
|
|
|
|
adminAuthentication,
|
|
|
|
secret: 'super-secret',
|
|
|
|
sessionAge: 4000,
|
|
|
|
getLogger,
|
2020-12-17 19:43:01 +01:00
|
|
|
};
|
2020-12-17 19:22:30 +01:00
|
|
|
const services = createServices(stores, config);
|
|
|
|
// TODO: use create from server-impl instead?
|
|
|
|
return getApp(config, services);
|
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 = {
|
2019-10-03 15:01:33 +02:00
|
|
|
async setupApp(stores) {
|
2017-11-16 16:45:01 +01:00
|
|
|
const app = createApp(stores);
|
2019-10-03 15:01:33 +02:00
|
|
|
return supertest.agent(app);
|
2017-11-16 16:45:01 +01:00
|
|
|
},
|
|
|
|
|
2019-10-03 15:01:33 +02:00
|
|
|
async setupAppWithAuth(stores) {
|
|
|
|
const app = createApp(stores, 'unsecure');
|
|
|
|
return supertest.agent(app);
|
2017-11-16 16:45:01 +01:00
|
|
|
},
|
2014-11-25 14:41:11 +01:00
|
|
|
|
2019-10-03 15:01:33 +02:00
|
|
|
async setupAppWithCustomAuth(stores, preHook) {
|
2017-11-16 16:45:01 +01:00
|
|
|
const app = createApp(stores, 'custom', preHook);
|
2019-10-03 15:01:33 +02:00
|
|
|
return supertest.agent(app);
|
2016-11-13 15:41:35 +01:00
|
|
|
},
|
2016-04-24 22:41:37 +02:00
|
|
|
};
|