2016-04-24 22:41:37 +02:00
|
|
|
'use strict';
|
2014-11-25 15:28:08 +01:00
|
|
|
var specHelper = require('./specHelper');
|
2014-12-05 17:20:17 +01:00
|
|
|
var request = specHelper.request;
|
2014-11-25 15:28:08 +01:00
|
|
|
|
|
|
|
describe('The strategy api', function () {
|
2014-12-05 17:20:17 +01:00
|
|
|
beforeEach(function (done) {
|
|
|
|
specHelper.db.resetAndSetup()
|
|
|
|
.then(done.bind(null, null))
|
|
|
|
.catch(done);
|
|
|
|
});
|
2014-11-25 15:28:08 +01:00
|
|
|
|
|
|
|
it('gets all strategies', function (done) {
|
|
|
|
request
|
|
|
|
.get('/strategies')
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect(200, done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('gets a strategy by name', function (done) {
|
|
|
|
request
|
|
|
|
.get('/strategies/default')
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect(200, done);
|
|
|
|
});
|
|
|
|
|
2015-02-10 18:28:17 +01:00
|
|
|
it('cant get a strategy by name that dose not exist', function (done) {
|
|
|
|
request
|
|
|
|
.get('/strategies/mystrategy')
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect(404, done);
|
|
|
|
});
|
|
|
|
|
2014-11-25 15:28:08 +01:00
|
|
|
it('creates a new strategy', function (done) {
|
|
|
|
request
|
|
|
|
.post('/strategies')
|
2016-04-24 22:41:37 +02:00
|
|
|
.send({ name: 'myCustomStrategy', description: 'Best strategy ever.' })
|
2014-11-25 15:28:08 +01:00
|
|
|
.set('Content-Type', 'application/json')
|
|
|
|
.expect(201, done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('requires new strategies to have a name', function (done) {
|
|
|
|
request
|
|
|
|
.post('/strategies')
|
2016-04-24 22:41:37 +02:00
|
|
|
.send({ name: '' })
|
2014-11-25 15:28:08 +01:00
|
|
|
.set('Content-Type', 'application/json')
|
|
|
|
.expect(400, done);
|
|
|
|
});
|
|
|
|
|
2014-11-25 16:34:24 +01:00
|
|
|
it('refuses to create a strategy with an existing name', function (done) {
|
|
|
|
request
|
|
|
|
.post('/strategies')
|
2016-04-24 22:41:37 +02:00
|
|
|
.send({ name: 'default' })
|
2014-11-25 16:34:24 +01:00
|
|
|
.set('Content-Type', 'application/json')
|
|
|
|
.expect(403, done);
|
|
|
|
});
|
|
|
|
|
2014-12-08 20:56:22 +01:00
|
|
|
it('deletes a new strategy', function (done) {
|
|
|
|
request
|
2015-02-12 11:41:30 +01:00
|
|
|
.delete('/strategies/usersWithEmail')
|
2014-12-08 20:56:22 +01:00
|
|
|
.expect(200, done);
|
|
|
|
});
|
2015-02-12 11:41:30 +01:00
|
|
|
|
|
|
|
it('can\'t delete a strategy that dose not exist', function(done) {
|
|
|
|
request
|
|
|
|
.delete('/strategies/unknown')
|
|
|
|
.expect(404, done);
|
|
|
|
});
|
2016-04-24 22:41:37 +02:00
|
|
|
});
|