2017-01-06 15:58:02 +01:00
|
|
|
'use strict';
|
|
|
|
|
2018-12-17 09:24:49 +01:00
|
|
|
const test = require('ava');
|
2017-01-06 15:58:02 +01:00
|
|
|
const supertest = require('supertest');
|
2020-04-14 22:29:11 +02:00
|
|
|
const { EventEmitter } = require('events');
|
|
|
|
const store = require('../../../test/fixtures/store');
|
|
|
|
const getLogger = require('../../../test/fixtures/no-logger');
|
2017-06-28 10:20:22 +02:00
|
|
|
const getApp = require('../../app');
|
2017-01-06 15:58:02 +01:00
|
|
|
|
|
|
|
const eventBus = new EventEmitter();
|
|
|
|
|
2017-06-28 10:20:22 +02:00
|
|
|
function getSetup() {
|
2017-01-06 15:58:02 +01:00
|
|
|
const base = `/random${Math.round(Math.random() * 1000)}`;
|
|
|
|
const stores = store.createStores();
|
|
|
|
const app = getApp({
|
|
|
|
baseUriPath: base,
|
|
|
|
stores,
|
|
|
|
eventBus,
|
2019-04-30 21:14:23 +02:00
|
|
|
getLogger,
|
2017-01-06 15:58:02 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
base,
|
|
|
|
featureToggleStore: stores.featureToggleStore,
|
|
|
|
request: supertest(app),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-06-28 10:20:22 +02:00
|
|
|
test('should get empty getFeatures via client', t => {
|
|
|
|
t.plan(1);
|
2017-01-06 15:58:02 +01:00
|
|
|
const { request, base } = getSetup();
|
|
|
|
return request
|
2017-06-28 10:20:22 +02:00
|
|
|
.get(`${base}/api/client/features`)
|
2017-01-06 15:58:02 +01:00
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect(200)
|
2017-06-28 10:20:22 +02:00
|
|
|
.expect(res => {
|
|
|
|
t.true(res.body.features.length === 0);
|
2017-01-06 15:58:02 +01:00
|
|
|
});
|
|
|
|
});
|
2017-06-28 12:52:27 +02:00
|
|
|
|
|
|
|
test('fetch single feature', t => {
|
|
|
|
t.plan(1);
|
|
|
|
const { request, featureToggleStore, base } = getSetup();
|
|
|
|
featureToggleStore.addFeature({
|
|
|
|
name: 'test_',
|
|
|
|
strategies: [{ name: 'default' }],
|
|
|
|
});
|
|
|
|
|
|
|
|
return request
|
|
|
|
.get(`${base}/api/client/features/test_`)
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect(200)
|
|
|
|
.expect(res => {
|
|
|
|
t.true(res.body.name === 'test_');
|
|
|
|
});
|
|
|
|
});
|
2018-11-16 15:56:14 +01:00
|
|
|
|
|
|
|
test('support name prefix', t => {
|
|
|
|
t.plan(2);
|
|
|
|
const { request, featureToggleStore, base } = getSetup();
|
|
|
|
featureToggleStore.addFeature({ name: 'a_test1' });
|
|
|
|
featureToggleStore.addFeature({ name: 'a_test2' });
|
|
|
|
featureToggleStore.addFeature({ name: 'b_test1' });
|
|
|
|
featureToggleStore.addFeature({ name: 'b_test2' });
|
|
|
|
|
|
|
|
const namePrefix = 'b_';
|
|
|
|
|
|
|
|
return request
|
|
|
|
.get(`${base}/api/client/features?namePrefix=${namePrefix}`)
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect(200)
|
|
|
|
.expect(res => {
|
|
|
|
t.true(res.body.features.length === 2);
|
|
|
|
t.true(res.body.features[1].name === 'b_test2');
|
|
|
|
});
|
|
|
|
});
|