1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-28 00:06:53 +01:00
unleash.unleash/test/e2e/api/admin/strategy.e2e.test.js

122 lines
3.3 KiB
JavaScript
Raw Normal View History

'use strict';
2016-10-26 10:43:11 +02:00
2018-12-17 09:24:49 +01:00
const test = require('ava');
const dbInit = require('../../helpers/database-init');
const { setupApp } = require('../../helpers/test-helper');
const getLogger = require('../../../fixtures/no-logger');
let stores;
test.before(async () => {
const db = await dbInit('strategy_api_serial', getLogger);
stores = db.stores;
});
test.after(async () => {
await stores.db.destroy();
});
test.serial('gets all strategies', async t => {
t.plan(1);
const request = await setupApp(stores);
2016-11-13 15:41:35 +01:00
return request
.get('/api/admin/strategies')
2016-11-13 15:41:35 +01:00
.expect('Content-Type', /json/)
.expect(200)
.expect(res => {
t.true(
res.body.strategies.length === 2,
'expected to have two strategies',
);
});
2016-11-13 15:41:35 +01:00
});
test.serial('gets a strategy by name', async t => {
t.plan(0);
const request = await setupApp(stores);
2016-11-13 15:41:35 +01:00
return request
.get('/api/admin/strategies/default')
2016-11-13 15:41:35 +01:00
.expect('Content-Type', /json/)
.expect(200);
2016-11-13 15:41:35 +01:00
});
test.serial('cant get a strategy by name that dose not exist', async t => {
t.plan(0);
const request = await setupApp(stores);
2016-11-13 15:41:35 +01:00
return request
.get('/api/admin/strategies/mystrategy')
2016-11-13 15:41:35 +01:00
.expect('Content-Type', /json/)
.expect(404);
2016-11-13 15:41:35 +01:00
});
test.serial('creates a new strategy', async t => {
t.plan(0);
const request = await setupApp(stores);
2016-11-13 15:41:35 +01:00
return request
.post('/api/admin/strategies')
.send({
name: 'myCustomStrategy',
description: 'Best strategy ever.',
parameters: [],
})
2016-11-13 15:41:35 +01:00
.set('Content-Type', 'application/json')
.expect(201);
2016-11-13 15:41:35 +01:00
});
test.serial('requires new strategies to have a name', async t => {
t.plan(0);
const request = await setupApp(stores);
2016-11-13 15:41:35 +01:00
return request
.post('/api/admin/strategies')
2016-11-13 15:41:35 +01:00
.send({ name: '' })
.set('Content-Type', 'application/json')
.expect(400);
2016-11-13 15:41:35 +01:00
});
test.serial('refuses to create a strategy with an existing name', async t => {
t.plan(0);
const request = await setupApp(stores);
2016-11-13 15:41:35 +01:00
return request
.post('/api/admin/strategies')
2016-12-12 21:44:21 +01:00
.send({ name: 'default', parameters: [] })
2016-11-13 15:41:35 +01:00
.set('Content-Type', 'application/json')
2020-09-25 22:31:35 +02:00
.expect(409);
2016-11-13 15:41:35 +01:00
});
test.serial('deletes a new strategy', async t => {
t.plan(0);
const request = await setupApp(stores);
return request.delete('/api/admin/strategies/usersWithEmail').expect(200);
2016-11-13 15:41:35 +01:00
});
test.serial("can't delete a strategy that dose not exist", async t => {
t.plan(0);
const request = await setupApp(stores);
return request.delete('/api/admin/strategies/unknown').expect(404);
});
test.serial('updates a exiting strategy', async t => {
t.plan(0);
const request = await setupApp(stores);
return request
.put('/api/admin/strategies/default')
.send({
name: 'default',
description: 'Default is the best!',
parameters: [],
})
.set('Content-Type', 'application/json')
.expect(200);
});
test.serial('cant update a unknown strategy', async t => {
t.plan(0);
const request = await setupApp(stores);
return request
.put('/api/admin/strategies/unknown')
.send({ name: 'unkown', parameters: [] })
.set('Content-Type', 'application/json')
.expect(404);
});