2016-08-23 01:29:47 +02:00
|
|
|
'use strict';
|
|
|
|
|
2017-06-28 10:20:22 +02:00
|
|
|
const { test } = require('ava');
|
|
|
|
const store = require('./../../../test/fixtures/store');
|
2016-09-05 16:50:52 +02:00
|
|
|
const supertest = require('supertest');
|
2017-06-28 10:20:22 +02:00
|
|
|
const getApp = require('../../app');
|
2016-11-11 15:46:59 +01:00
|
|
|
|
2016-11-30 23:41:57 +01:00
|
|
|
const { EventEmitter } = require('events');
|
|
|
|
const eventBus = new EventEmitter();
|
|
|
|
|
2017-06-28 10:20:22 +02:00
|
|
|
function getSetup() {
|
2016-11-13 15:41:35 +01:00
|
|
|
const base = `/random${Math.round(Math.random() * 1000)}`;
|
|
|
|
const stores = store.createStores();
|
2016-11-13 21:07:14 +01:00
|
|
|
const app = getApp({
|
2016-11-13 15:41:35 +01:00
|
|
|
baseUriPath: base,
|
|
|
|
stores,
|
2016-11-30 23:41:57 +01:00
|
|
|
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),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-06-28 10:20:22 +02:00
|
|
|
test('should get empty getFeatures via admin', t => {
|
|
|
|
t.plan(1);
|
2016-11-13 15:41:35 +01:00
|
|
|
const { request, base } = getSetup();
|
|
|
|
return request
|
2017-06-28 10:20:22 +02:00
|
|
|
.get(`${base}/api/admin/features`)
|
2016-11-13 15:41:35 +01:00
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect(200)
|
2017-06-28 10:20:22 +02:00
|
|
|
.expect(res => {
|
2016-11-13 15:41:35 +01:00
|
|
|
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 => {
|
2017-06-28 10:20:22 +02:00
|
|
|
t.plan(1);
|
2016-11-13 15:41:35 +01:00
|
|
|
const { request, featureToggleStore, base } = getSetup();
|
2017-06-28 10:20:22 +02:00
|
|
|
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
|
2017-06-28 10:20:22 +02:00
|
|
|
.get(`${base}/api/admin/features`)
|
2016-11-13 15:41:35 +01:00
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect(200)
|
2017-06-28 10:20:22 +02:00
|
|
|
.expect(res => {
|
2016-11-13 15:41:35 +01:00
|
|
|
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 => {
|
2017-06-28 10:20:22 +02:00
|
|
|
t.plan(1);
|
2016-11-13 15:41:35 +01:00
|
|
|
const { request, featureToggleStore, base } = getSetup();
|
2017-06-28 10:20:22 +02:00
|
|
|
featureToggleStore.addFeature({
|
|
|
|
name: 'test2',
|
|
|
|
strategies: [{ name: 'default' }],
|
|
|
|
});
|
2016-09-05 16:50:52 +02:00
|
|
|
|
2016-11-13 15:41:35 +01:00
|
|
|
return request
|
2017-06-28 10:20:22 +02:00
|
|
|
.get(`${base}/api/admin/features`)
|
2016-11-13 15:41:35 +01:00
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect(200)
|
2017-06-28 10:20:22 +02:00
|
|
|
.expect(res => {
|
2016-11-13 15:41:35 +01:00
|
|
|
t.true(res.body.version === 1);
|
|
|
|
});
|
2016-08-23 01:29:47 +02:00
|
|
|
});
|
2016-11-13 15:41:35 +01:00
|
|
|
|
2016-11-15 21:27:03 +01:00
|
|
|
test('should require at least one strategy when creating a feature toggle', t => {
|
2017-06-28 10:20:22 +02:00
|
|
|
t.plan(0);
|
2016-11-15 21:27:03 +01:00
|
|
|
const { request, base } = getSetup();
|
|
|
|
|
|
|
|
return request
|
2017-06-28 10:20:22 +02:00
|
|
|
.post(`${base}/api/admin/features`)
|
2016-11-15 21:27:03 +01:00
|
|
|
.send({ name: 'sample.missing.strategy' })
|
|
|
|
.set('Content-Type', 'application/json')
|
2017-06-28 10:20:22 +02:00
|
|
|
.expect(400);
|
2016-11-15 21:27:03 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test('should require at least one strategy when updating a feature toggle', t => {
|
2017-06-28 10:20:22 +02:00
|
|
|
t.plan(0);
|
2016-11-15 21:27:03 +01:00
|
|
|
const { request, featureToggleStore, base } = getSetup();
|
2017-06-28 10:20:22 +02:00
|
|
|
featureToggleStore.addFeature({
|
|
|
|
name: 'ts',
|
|
|
|
strategies: [{ name: 'default' }],
|
|
|
|
});
|
2016-11-15 21:27:03 +01:00
|
|
|
|
|
|
|
return request
|
2017-06-28 10:20:22 +02:00
|
|
|
.put(`${base}/api/admin/features/ts`)
|
2016-11-15 21:27:03 +01:00
|
|
|
.send({ name: 'ts' })
|
|
|
|
.set('Content-Type', 'application/json')
|
2017-06-28 10:20:22 +02:00
|
|
|
.expect(400);
|
2016-11-15 21:27:03 +01:00
|
|
|
});
|