mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-14 00:19:16 +01:00
fix: simplify e2e tests by leverarging unelash.create method
This commit is contained in:
parent
ba09ca317c
commit
9354c5a15e
@ -2,27 +2,43 @@
|
|||||||
|
|
||||||
const test = require('ava');
|
const test = require('ava');
|
||||||
|
|
||||||
const dbInit = require('../../helpers/database-init');
|
// const dbInit = require('../../helpers/database-init');
|
||||||
const { setupApp } = require('../../helpers/test-helper');
|
const { setupApp } = require('../../helpers/test-helper-2');
|
||||||
const getLogger = require('../../../fixtures/no-logger');
|
// const getLogger = require('../../../fixtures/no-logger');
|
||||||
|
|
||||||
const MASKED_VALUE = '*****';
|
const MASKED_VALUE = '*****';
|
||||||
|
|
||||||
let stores;
|
// let stores;
|
||||||
let db;
|
let request;
|
||||||
|
let stop;
|
||||||
|
let currentUser;
|
||||||
|
|
||||||
test.before(async () => {
|
test.before(async () => {
|
||||||
db = await dbInit('addon_api_serial', getLogger);
|
const preHook = app => {
|
||||||
stores = db.stores;
|
app.use((req, res, next) => {
|
||||||
|
req.user = currentUser;
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
const data = await setupApp('addon_api_serial', preHook);
|
||||||
|
request = data.request;
|
||||||
|
currentUser = await data.services.userService.loginUserWithoutPassword(
|
||||||
|
'regular-test@getunleash.io',
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
|
||||||
|
stop = data.stop;
|
||||||
|
// stores = db.stores;
|
||||||
});
|
});
|
||||||
|
|
||||||
test.after(async () => {
|
test.after(async () => {
|
||||||
await db.destroy();
|
// await db.destroy();
|
||||||
|
await stop();
|
||||||
});
|
});
|
||||||
|
|
||||||
test.serial('gets all addons', async t => {
|
test.serial('gets all addons', async t => {
|
||||||
t.plan(3);
|
t.plan(3);
|
||||||
const request = await setupApp(stores);
|
|
||||||
return request
|
return request
|
||||||
.get('/api/admin/addons')
|
.get('/api/admin/addons')
|
||||||
.expect('Content-Type', /json/)
|
.expect('Content-Type', /json/)
|
||||||
@ -36,7 +52,6 @@ test.serial('gets all addons', async t => {
|
|||||||
|
|
||||||
test.serial('should not be able to create invalid addon', async t => {
|
test.serial('should not be able to create invalid addon', async t => {
|
||||||
t.plan(0);
|
t.plan(0);
|
||||||
const request = await setupApp(stores);
|
|
||||||
return request
|
return request
|
||||||
.post('/api/admin/addons')
|
.post('/api/admin/addons')
|
||||||
.send({ invalid: 'field' })
|
.send({ invalid: 'field' })
|
||||||
@ -45,7 +60,6 @@ test.serial('should not be able to create invalid addon', async t => {
|
|||||||
|
|
||||||
test.serial('should create addon configuration', async t => {
|
test.serial('should create addon configuration', async t => {
|
||||||
t.plan(0);
|
t.plan(0);
|
||||||
const request = await setupApp(stores);
|
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
provider: 'webhook',
|
provider: 'webhook',
|
||||||
@ -65,7 +79,6 @@ test.serial('should create addon configuration', async t => {
|
|||||||
|
|
||||||
test.serial('should delete addon configuration', async t => {
|
test.serial('should delete addon configuration', async t => {
|
||||||
t.plan(0);
|
t.plan(0);
|
||||||
const request = await setupApp(stores);
|
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
provider: 'webhook',
|
provider: 'webhook',
|
||||||
@ -88,7 +101,6 @@ test.serial('should delete addon configuration', async t => {
|
|||||||
|
|
||||||
test.serial('should update addon configuration', async t => {
|
test.serial('should update addon configuration', async t => {
|
||||||
t.plan(2);
|
t.plan(2);
|
||||||
const request = await setupApp(stores);
|
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
provider: 'webhook',
|
provider: 'webhook',
|
||||||
@ -135,7 +147,6 @@ test.serial('should update addon configuration', async t => {
|
|||||||
|
|
||||||
test.serial('should not update with invalid addon configuration', async t => {
|
test.serial('should not update with invalid addon configuration', async t => {
|
||||||
t.plan(0);
|
t.plan(0);
|
||||||
const request = await setupApp(stores);
|
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
@ -154,7 +165,6 @@ test.serial('should not update with invalid addon configuration', async t => {
|
|||||||
|
|
||||||
test.serial('should not update unknown addon configuration', async t => {
|
test.serial('should not update unknown addon configuration', async t => {
|
||||||
t.plan(0);
|
t.plan(0);
|
||||||
const request = await setupApp(stores);
|
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
provider: 'webhook',
|
provider: 'webhook',
|
||||||
@ -174,7 +184,6 @@ test.serial('should not update unknown addon configuration', async t => {
|
|||||||
|
|
||||||
test.serial('should get addon configuration', async t => {
|
test.serial('should get addon configuration', async t => {
|
||||||
t.plan(3);
|
t.plan(3);
|
||||||
const request = await setupApp(stores);
|
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
provider: 'webhook',
|
provider: 'webhook',
|
||||||
@ -208,14 +217,12 @@ test.serial('should get addon configuration', async t => {
|
|||||||
|
|
||||||
test.serial('should not get unknown addon configuration', async t => {
|
test.serial('should not get unknown addon configuration', async t => {
|
||||||
t.plan(0);
|
t.plan(0);
|
||||||
const request = await setupApp(stores);
|
|
||||||
|
|
||||||
await request.get('/api/admin/addons/445').expect(404);
|
await request.get('/api/admin/addons/445').expect(404);
|
||||||
});
|
});
|
||||||
|
|
||||||
test.serial('should not delete unknown addon configuration', async t => {
|
test.serial('should not delete unknown addon configuration', async t => {
|
||||||
t.plan(0);
|
t.plan(0);
|
||||||
const request = await setupApp(stores);
|
|
||||||
|
|
||||||
return request.delete('/api/admin/addons/21231').expect(404);
|
return request.delete('/api/admin/addons/21231').expect(404);
|
||||||
});
|
});
|
||||||
|
42
src/test/e2e/helpers/test-helper-2.js
Normal file
42
src/test/e2e/helpers/test-helper-2.js
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
process.env.NODE_ENV = 'test';
|
||||||
|
/* eslint-disable-next-line */
|
||||||
|
const supertest = require('supertest');
|
||||||
|
|
||||||
|
const { create } = require('../../../lib/server-impl');
|
||||||
|
const getLogger = require('../../fixtures/no-logger');
|
||||||
|
const dbConfig = require('./database-config');
|
||||||
|
const migrator = require('../../../migrator');
|
||||||
|
|
||||||
|
process.setMaxListeners(0);
|
||||||
|
|
||||||
|
async function prepareDatabase(db, databaseSchema) {
|
||||||
|
await db.raw(`DROP SCHEMA IF EXISTS ${databaseSchema} CASCADE`);
|
||||||
|
await db.raw(`CREATE SCHEMA IF NOT EXISTS ${databaseSchema}`);
|
||||||
|
await migrator({ db: dbConfig.getDb(), databaseSchema });
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
async setupApp(databaseSchema, preHook) {
|
||||||
|
const { app, config, stop, services } = await create({
|
||||||
|
preHook,
|
||||||
|
serverMetrics: false,
|
||||||
|
databaseSchema,
|
||||||
|
disableDBMigration: true,
|
||||||
|
db: dbConfig.getDb(),
|
||||||
|
session: {
|
||||||
|
db: false,
|
||||||
|
age: 4000,
|
||||||
|
},
|
||||||
|
getLogger,
|
||||||
|
});
|
||||||
|
config.stores.clientMetricsStore.setMaxListeners(0);
|
||||||
|
config.stores.eventStore.setMaxListeners(0);
|
||||||
|
await prepareDatabase(config.stores.db, databaseSchema);
|
||||||
|
return {
|
||||||
|
request: supertest.agent(app),
|
||||||
|
stop,
|
||||||
|
config,
|
||||||
|
services,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user