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');
|
2017-06-28 10:20:22 +02:00
|
|
|
const { setupApp } = require('./../../helpers/test-helper');
|
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);
|
2016-11-13 15:41:35 +01:00
|
|
|
const { request, destroy } = await setupApp('strategy_api_serial');
|
|
|
|
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,
|
|
|
|
'expected to have two strategies'
|
|
|
|
);
|
2016-12-12 17:09:44 +01:00
|
|
|
})
|
2016-11-13 15:41:35 +01:00
|
|
|
.then(destroy);
|
|
|
|
});
|
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);
|
2016-11-13 15:41:35 +01:00
|
|
|
const { request, destroy } = await setupApp('strategy_api_serial');
|
|
|
|
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/)
|
|
|
|
.expect(200)
|
|
|
|
.then(destroy);
|
|
|
|
});
|
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);
|
2016-11-13 15:41:35 +01:00
|
|
|
const { request, destroy } = await setupApp('strategy_api_serial');
|
|
|
|
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/)
|
|
|
|
.expect(404)
|
|
|
|
.then(destroy);
|
|
|
|
});
|
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);
|
2016-11-13 15:41:35 +01:00
|
|
|
const { request, destroy } = await setupApp('strategy_api_serial');
|
|
|
|
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')
|
|
|
|
.expect(201)
|
|
|
|
.then(destroy);
|
|
|
|
});
|
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);
|
2016-11-13 15:41:35 +01:00
|
|
|
const { request, destroy } = await setupApp('strategy_api_serial');
|
|
|
|
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')
|
|
|
|
.expect(400)
|
|
|
|
.then(destroy);
|
|
|
|
});
|
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);
|
2016-11-13 15:41:35 +01:00
|
|
|
const { request, destroy } = await setupApp('strategy_api_serial');
|
|
|
|
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')
|
2019-01-02 12:38:58 +01:00
|
|
|
.expect(400)
|
2016-11-13 15:41:35 +01:00
|
|
|
.then(destroy);
|
|
|
|
});
|
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);
|
2016-11-13 15:41:35 +01:00
|
|
|
const { request, destroy } = await setupApp('strategy_api_serial');
|
|
|
|
return request
|
2017-06-28 10:20:22 +02:00
|
|
|
.delete('/api/admin/strategies/usersWithEmail')
|
2016-11-13 15:41:35 +01:00
|
|
|
.expect(200)
|
|
|
|
.then(destroy);
|
|
|
|
});
|
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);
|
2016-11-13 15:41:35 +01:00
|
|
|
const { request, destroy } = await setupApp('strategy_api_serial', false);
|
|
|
|
return request
|
2017-06-28 10:20:22 +02:00
|
|
|
.delete('/api/admin/strategies/unknown')
|
|
|
|
.expect(404)
|
|
|
|
.then(destroy);
|
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);
|
2016-12-17 12:31:23 +01:00
|
|
|
const { request, destroy } = await setupApp('strategy_api_serial');
|
|
|
|
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')
|
|
|
|
.expect(200)
|
|
|
|
.then(destroy);
|
|
|
|
});
|
|
|
|
|
2017-06-28 10:20:22 +02:00
|
|
|
test.serial('cant update a unknown strategy', async t => {
|
|
|
|
t.plan(0);
|
2016-12-17 12:31:23 +01:00
|
|
|
const { request, destroy } = await setupApp('strategy_api_serial');
|
|
|
|
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')
|
|
|
|
.expect(404)
|
|
|
|
.then(destroy);
|
|
|
|
});
|