2016-04-24 22:41:37 +02:00
|
|
|
'use strict';
|
2016-10-26 10:43:11 +02:00
|
|
|
|
2018-12-17 09:24:49 +01:00
|
|
|
const test = require('ava');
|
2019-10-03 15:01:33 +02:00
|
|
|
|
|
|
|
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();
|
|
|
|
});
|
2014-11-25 15:28:08 +01:00
|
|
|
|
2017-06-28 10:20:22 +02:00
|
|
|
test.serial('gets all strategies', async t => {
|
|
|
|
t.plan(1);
|
2019-10-03 15:01:33 +02:00
|
|
|
const request = await setupApp(stores);
|
2016-11-13 15:41:35 +01:00
|
|
|
return request
|
2017-06-28 10:20:22 +02:00
|
|
|
.get('/api/admin/strategies')
|
2016-11-13 15:41:35 +01:00
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect(200)
|
2017-06-28 10:20:22 +02:00
|
|
|
.expect(res => {
|
|
|
|
t.true(
|
|
|
|
res.body.strategies.length === 2,
|
2020-04-14 22:29:11 +02:00
|
|
|
'expected to have two strategies',
|
2017-06-28 10:20:22 +02:00
|
|
|
);
|
2019-10-03 15:01:33 +02:00
|
|
|
});
|
2016-11-13 15:41:35 +01:00
|
|
|
});
|
2014-11-25 15:28:08 +01:00
|
|
|
|
2017-06-28 10:20:22 +02:00
|
|
|
test.serial('gets a strategy by name', async t => {
|
|
|
|
t.plan(0);
|
2019-10-03 15:01:33 +02:00
|
|
|
const request = await setupApp(stores);
|
2016-11-13 15:41:35 +01:00
|
|
|
return request
|
2017-06-28 10:20:22 +02:00
|
|
|
.get('/api/admin/strategies/default')
|
2016-11-13 15:41:35 +01:00
|
|
|
.expect('Content-Type', /json/)
|
2019-10-03 15:01:33 +02:00
|
|
|
.expect(200);
|
2016-11-13 15:41:35 +01:00
|
|
|
});
|
2014-11-25 15:28:08 +01:00
|
|
|
|
2017-06-28 10:20:22 +02:00
|
|
|
test.serial('cant get a strategy by name that dose not exist', async t => {
|
|
|
|
t.plan(0);
|
2019-10-03 15:01:33 +02:00
|
|
|
const request = await setupApp(stores);
|
2016-11-13 15:41:35 +01:00
|
|
|
return request
|
2017-06-28 10:20:22 +02:00
|
|
|
.get('/api/admin/strategies/mystrategy')
|
2016-11-13 15:41:35 +01:00
|
|
|
.expect('Content-Type', /json/)
|
2019-10-03 15:01:33 +02:00
|
|
|
.expect(404);
|
2016-11-13 15:41:35 +01:00
|
|
|
});
|
2015-02-10 18:28:17 +01:00
|
|
|
|
2017-06-28 10:20:22 +02:00
|
|
|
test.serial('creates a new strategy', async t => {
|
|
|
|
t.plan(0);
|
2019-10-03 15:01:33 +02:00
|
|
|
const request = await setupApp(stores);
|
2016-11-13 15:41:35 +01:00
|
|
|
return request
|
2017-06-28 10:20:22 +02:00
|
|
|
.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')
|
2019-10-03 15:01:33 +02:00
|
|
|
.expect(201);
|
2016-11-13 15:41:35 +01:00
|
|
|
});
|
2014-11-25 15:28:08 +01:00
|
|
|
|
2017-06-28 10:20:22 +02:00
|
|
|
test.serial('requires new strategies to have a name', async t => {
|
|
|
|
t.plan(0);
|
2019-10-03 15:01:33 +02:00
|
|
|
const request = await setupApp(stores);
|
2016-11-13 15:41:35 +01:00
|
|
|
return request
|
2017-06-28 10:20:22 +02:00
|
|
|
.post('/api/admin/strategies')
|
2016-11-13 15:41:35 +01:00
|
|
|
.send({ name: '' })
|
|
|
|
.set('Content-Type', 'application/json')
|
2019-10-03 15:01:33 +02:00
|
|
|
.expect(400);
|
2016-11-13 15:41:35 +01:00
|
|
|
});
|
2014-11-25 15:28:08 +01:00
|
|
|
|
2017-06-28 10:20:22 +02:00
|
|
|
test.serial('refuses to create a strategy with an existing name', async t => {
|
|
|
|
t.plan(0);
|
2019-10-03 15:01:33 +02:00
|
|
|
const request = await setupApp(stores);
|
2016-11-13 15:41:35 +01:00
|
|
|
return request
|
2017-06-28 10:20:22 +02:00
|
|
|
.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
|
|
|
});
|
2014-11-25 16:34:24 +01:00
|
|
|
|
2017-06-28 10:20:22 +02:00
|
|
|
test.serial('deletes a new strategy', async t => {
|
|
|
|
t.plan(0);
|
2019-10-03 15:01:33 +02:00
|
|
|
const request = await setupApp(stores);
|
|
|
|
return request.delete('/api/admin/strategies/usersWithEmail').expect(200);
|
2016-11-13 15:41:35 +01:00
|
|
|
});
|
2015-02-12 11:41:30 +01:00
|
|
|
|
2017-06-28 10:20:22 +02:00
|
|
|
test.serial("can't delete a strategy that dose not exist", async t => {
|
|
|
|
t.plan(0);
|
2019-10-03 15:01:33 +02:00
|
|
|
const request = await setupApp(stores);
|
|
|
|
return request.delete('/api/admin/strategies/unknown').expect(404);
|
2016-04-24 22:41:37 +02:00
|
|
|
});
|
2016-12-17 12:31:23 +01:00
|
|
|
|
2017-06-28 10:20:22 +02:00
|
|
|
test.serial('updates a exiting strategy', async t => {
|
|
|
|
t.plan(0);
|
2019-10-03 15:01:33 +02:00
|
|
|
const request = await setupApp(stores);
|
2016-12-17 12:31:23 +01:00
|
|
|
return request
|
2017-06-28 10:20:22 +02:00
|
|
|
.put('/api/admin/strategies/default')
|
|
|
|
.send({
|
|
|
|
name: 'default',
|
|
|
|
description: 'Default is the best!',
|
|
|
|
parameters: [],
|
|
|
|
})
|
2016-12-17 12:31:23 +01:00
|
|
|
.set('Content-Type', 'application/json')
|
2019-10-03 15:01:33 +02:00
|
|
|
.expect(200);
|
2016-12-17 12:31:23 +01:00
|
|
|
});
|
|
|
|
|
2017-06-28 10:20:22 +02:00
|
|
|
test.serial('cant update a unknown strategy', async t => {
|
|
|
|
t.plan(0);
|
2019-10-03 15:01:33 +02:00
|
|
|
const request = await setupApp(stores);
|
2016-12-17 12:31:23 +01:00
|
|
|
return request
|
2017-06-28 10:20:22 +02:00
|
|
|
.put('/api/admin/strategies/unknown')
|
2016-12-17 12:31:23 +01:00
|
|
|
.send({ name: 'unkown', parameters: [] })
|
|
|
|
.set('Content-Type', 'application/json')
|
2019-10-03 15:01:33 +02:00
|
|
|
.expect(404);
|
2016-12-17 12:31:23 +01:00
|
|
|
});
|