1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-18 20:09:08 +02:00
unleash.unleash/test/strategyApiSpec.js
Jari Bakken 642c06f6ba Begin work on running tests against the database:
* Add Travis postgresql setup.
* Replace "db mocks" with a before hook that creates the same data
  through the HTTP API.
* Reset DB and re-create all fixtures for each test. We'll need
  something  better here.
* CAVEAT: no concept of a dev vs test database. Running tests will
  clear data from the currently configured database.
2020-02-20 08:30:18 +01:00

54 lines
1.5 KiB
JavaScript

var specHelper = require('./specHelper');
var request = specHelper.request;
describe('The strategy api', function () {
beforeEach(function (done) {
specHelper.db.resetAndSetup()
.then(done.bind(null, null))
.catch(done);
});
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);
});
it('creates a new strategy', function (done) {
request
.post('/strategies')
.send({name: 'myCustomStrategy', description: 'Best strategy ever.'})
.set('Content-Type', 'application/json')
.expect(201, done);
});
it('requires new strategies to have a name', function (done) {
request
.post('/strategies')
.send({name: ''})
.set('Content-Type', 'application/json')
.expect(400, done);
});
it('refuses to create a strategy with an existing name', function (done) {
request
.post('/strategies')
.send({name: 'default'})
.set('Content-Type', 'application/json')
.expect(403, done);
});
it('deletes a new strategy', function (done) {
request
.delete('/strategies/deletable')
.expect(200, done);
});
});