1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-28 00:06:53 +01:00
unleash.unleash/test/e2e/helpers/test-helper.js
2020-02-20 08:34:06 +01:00

54 lines
1.3 KiB
JavaScript

'use strict';
process.env.NODE_ENV = 'test';
const supertest = require('supertest');
const getApp = require('../../../lib/app');
const dbInit = require('./database-init');
const { EventEmitter } = require('events');
const eventBus = new EventEmitter();
function createApp(stores, adminAuthentication = 'none', preHook) {
return getApp({
stores,
eventBus,
preHook,
adminAuthentication,
secret: 'super-secret',
sessionAge: 4000,
});
}
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(),
};
},
async setupAppWithCustomAuth(name, preHook) {
const stores = await dbInit(name);
const app = createApp(stores, 'custom', preHook);
return {
request: supertest.agent(app),
destroy: () => stores.db.destroy(),
};
},
};