1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-28 00:06:53 +01:00
unleash.unleash/test/unit/routes/feature.test.js

89 lines
2.5 KiB
JavaScript
Raw Normal View History

2016-08-23 01:29:47 +02:00
'use strict';
2016-11-13 15:41:35 +01:00
const test = require('ava');
const store = require('./fixtures/store');
const supertest = require('supertest');
2016-11-13 15:41:35 +01:00
const logger = require('../../../lib/logger');
const getApp = require('../../../lib/app');
2016-11-11 15:46:59 +01:00
const { EventEmitter } = require('events');
const eventBus = new EventEmitter();
2016-11-13 15:41:35 +01:00
test.beforeEach(() => {
logger.setLevel('FATAL');
});
2016-08-23 01:29:47 +02:00
2016-11-13 15:41:35 +01:00
function getSetup () {
const base = `/random${Math.round(Math.random() * 1000)}`;
const stores = store.createStores();
const app = getApp({
2016-11-13 15:41:35 +01:00
baseUriPath: base,
stores,
eventBus,
2016-11-13 15:41:35 +01:00
});
2016-08-23 01:29:47 +02:00
2016-11-13 15:41:35 +01:00
return {
base,
featureToggleStore: stores.featureToggleStore,
request: supertest(app),
};
}
test('should get empty getFeatures', t => {
const { request, base } = getSetup();
return request
.get(`${base}/features`)
.expect('Content-Type', /json/)
.expect(200)
.expect((res) => {
t.true(res.body.features.length === 0);
2016-08-23 01:29:47 +02:00
});
2016-11-13 15:41:35 +01:00
});
2016-08-23 01:29:47 +02:00
2016-11-13 15:41:35 +01:00
test('should get one getFeature', t => {
const { request, featureToggleStore, base } = getSetup();
featureToggleStore.addFeature({ name: 'test_', strategies: [{ name: 'default_' }] });
2016-08-23 01:29:47 +02:00
2016-11-13 15:41:35 +01:00
return request
.get(`${base}/features`)
.expect('Content-Type', /json/)
.expect(200)
.expect((res) => {
t.true(res.body.features.length === 1);
});
});
2016-08-23 01:29:47 +02:00
2016-11-13 15:41:35 +01:00
test('should add version numbers for /features', t => {
const { request, featureToggleStore, base } = getSetup();
featureToggleStore.addFeature({ name: 'test2', strategies: [{ name: 'default' }] });
2016-11-13 15:41:35 +01:00
return request
.get(`${base}/features`)
.expect('Content-Type', /json/)
.expect(200)
.expect((res) => {
t.true(res.body.version === 1);
});
2016-08-23 01:29:47 +02:00
});
2016-11-13 15:41:35 +01:00
test('should require at least one strategy when creating a feature toggle', t => {
const { request, base } = getSetup();
return request
.post(`${base}/features`)
.send({ name: 'sample.missing.strategy' })
.set('Content-Type', 'application/json')
.expect(400)
});
test('should require at least one strategy when updating a feature toggle', t => {
const { request, featureToggleStore, base } = getSetup();
featureToggleStore.addFeature({ name: 'ts', strategies: [{ name: 'default' }] });
return request
.put(`${base}/features/ts`)
.send({ name: 'ts' })
.set('Content-Type', 'application/json')
.expect(400)
});