mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-28 00:17:12 +01:00
Add unit tests for archived toggles
This commit is contained in:
parent
2ba3823de0
commit
1695a35555
@ -1,5 +1,69 @@
|
||||
'use strict';
|
||||
|
||||
const { test } = require('ava');
|
||||
const store = require('./../../../test/fixtures/store');
|
||||
const supertest = require('supertest');
|
||||
const getApp = require('../../app');
|
||||
|
||||
test.todo('should unit test archive');
|
||||
const { EventEmitter } = require('events');
|
||||
const eventBus = new EventEmitter();
|
||||
|
||||
function getSetup() {
|
||||
const base = `/random${Math.round(Math.random() * 1000)}`;
|
||||
const stores = store.createStores();
|
||||
const app = getApp({
|
||||
baseUriPath: base,
|
||||
stores,
|
||||
eventBus,
|
||||
});
|
||||
|
||||
return {
|
||||
base,
|
||||
archiveStore: stores.featureToggleStore,
|
||||
request: supertest(app),
|
||||
};
|
||||
}
|
||||
|
||||
test('should get empty getFeatures via admin', t => {
|
||||
t.plan(1);
|
||||
const { request, base } = getSetup();
|
||||
return request
|
||||
.get(`${base}/api/admin/archive/features`)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(200)
|
||||
.expect(res => {
|
||||
t.true(res.body.features.length === 0);
|
||||
});
|
||||
});
|
||||
|
||||
test('should get archived toggles via admin', t => {
|
||||
t.plan(1);
|
||||
const { request, base, archiveStore } = getSetup();
|
||||
archiveStore.addArchivedFeature({
|
||||
name: 'test1',
|
||||
strategies: [{ name: 'default' }],
|
||||
});
|
||||
archiveStore.addArchivedFeature({
|
||||
name: 'test2',
|
||||
strategies: [{ name: 'default' }],
|
||||
});
|
||||
return request
|
||||
.get(`${base}/api/admin/archive/features`)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(200)
|
||||
.expect(res => {
|
||||
t.true(res.body.features.length === 2);
|
||||
});
|
||||
});
|
||||
|
||||
test('should revive toggle', t => {
|
||||
t.plan(0);
|
||||
const name = 'name1';
|
||||
const { request, base, archiveStore } = getSetup();
|
||||
archiveStore.addArchivedFeature({
|
||||
name,
|
||||
strategies: [{ name: 'default' }],
|
||||
});
|
||||
|
||||
return request.post(`${base}/api/admin/archive/revive/${name}`).expect(200);
|
||||
});
|
||||
|
3
test/fixtures/fake-feature-toggle-store.js
vendored
3
test/fixtures/fake-feature-toggle-store.js
vendored
@ -2,6 +2,7 @@
|
||||
|
||||
module.exports = () => {
|
||||
const _features = [];
|
||||
const _archive = [];
|
||||
return {
|
||||
getFeature: name => {
|
||||
const toggle = _features.find(f => f.name === name);
|
||||
@ -14,5 +15,7 @@ module.exports = () => {
|
||||
getFeatures: () => Promise.resolve(_features),
|
||||
hasFeatureName: () => Promise.resolve(false),
|
||||
addFeature: feature => _features.push(feature),
|
||||
getArchivedFeatures: () => Promise.resolve(_archive),
|
||||
addArchivedFeature: feature => _archive.push(feature),
|
||||
};
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user