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 dbInit = require('../../helpers/database-init');
|
||||
const { setupApp } = require('../../helpers/test-helper');
|
||||
const getLogger = require('../../../fixtures/no-logger');
|
||||
// const dbInit = require('../../helpers/database-init');
|
||||
const { setupApp } = require('../../helpers/test-helper-2');
|
||||
// const getLogger = require('../../../fixtures/no-logger');
|
||||
|
||||
const MASKED_VALUE = '*****';
|
||||
|
||||
let stores;
|
||||
let db;
|
||||
// let stores;
|
||||
let request;
|
||||
let stop;
|
||||
let currentUser;
|
||||
|
||||
test.before(async () => {
|
||||
db = await dbInit('addon_api_serial', getLogger);
|
||||
stores = db.stores;
|
||||
const preHook = app => {
|
||||
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 () => {
|
||||
await db.destroy();
|
||||
// await db.destroy();
|
||||
await stop();
|
||||
});
|
||||
|
||||
test.serial('gets all addons', async t => {
|
||||
t.plan(3);
|
||||
const request = await setupApp(stores);
|
||||
|
||||
return request
|
||||
.get('/api/admin/addons')
|
||||
.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 => {
|
||||
t.plan(0);
|
||||
const request = await setupApp(stores);
|
||||
return request
|
||||
.post('/api/admin/addons')
|
||||
.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 => {
|
||||
t.plan(0);
|
||||
const request = await setupApp(stores);
|
||||
|
||||
const config = {
|
||||
provider: 'webhook',
|
||||
@ -65,7 +79,6 @@ test.serial('should create addon configuration', async t => {
|
||||
|
||||
test.serial('should delete addon configuration', async t => {
|
||||
t.plan(0);
|
||||
const request = await setupApp(stores);
|
||||
|
||||
const config = {
|
||||
provider: 'webhook',
|
||||
@ -88,7 +101,6 @@ test.serial('should delete addon configuration', async t => {
|
||||
|
||||
test.serial('should update addon configuration', async t => {
|
||||
t.plan(2);
|
||||
const request = await setupApp(stores);
|
||||
|
||||
const config = {
|
||||
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 => {
|
||||
t.plan(0);
|
||||
const request = await setupApp(stores);
|
||||
|
||||
const config = {
|
||||
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 => {
|
||||
t.plan(0);
|
||||
const request = await setupApp(stores);
|
||||
|
||||
const config = {
|
||||
provider: 'webhook',
|
||||
@ -174,7 +184,6 @@ test.serial('should not update unknown addon configuration', async t => {
|
||||
|
||||
test.serial('should get addon configuration', async t => {
|
||||
t.plan(3);
|
||||
const request = await setupApp(stores);
|
||||
|
||||
const config = {
|
||||
provider: 'webhook',
|
||||
@ -208,14 +217,12 @@ test.serial('should get addon configuration', async t => {
|
||||
|
||||
test.serial('should not get unknown addon configuration', async t => {
|
||||
t.plan(0);
|
||||
const request = await setupApp(stores);
|
||||
|
||||
await request.get('/api/admin/addons/445').expect(404);
|
||||
});
|
||||
|
||||
test.serial('should not delete unknown addon configuration', async t => {
|
||||
t.plan(0);
|
||||
const request = await setupApp(stores);
|
||||
|
||||
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