1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00

Add simple API resource #191

This commit is contained in:
ivaosthu 2017-01-06 15:58:02 +01:00 committed by Ivar Conradi Østhus
parent abb00f8e1e
commit 8beb4b8876
3 changed files with 61 additions and 0 deletions

19
lib/routes/api.js Normal file
View File

@ -0,0 +1,19 @@
'use strict';
const apiDef = {
version: 1,
links: {
'feature-toggles': { uri: '/api/features' },
'strategies': { uri: '/api/strategies' },
'events': { uri: '/api/events' },
'client-register': { uri: '/api/client/register' },
'client-metrics': { uri: '/api/client/register' },
'seen-toggles': { uri: '/api/client/seen-toggles' },
},
};
module.exports = (app) => {
app.get('/', (req, res) => {
res.json(apiDef);
});
};

View File

@ -2,6 +2,7 @@
exports.createAPI = function (router, config) {
require('./api')(router, config);
require('./event')(router, config);
require('./feature')(router, config);
require('./feature-archive')(router, config);

View File

@ -0,0 +1,41 @@
'use strict';
const test = require('ava');
const store = require('./fixtures/store');
const supertest = require('supertest');
const logger = require('../../../lib/logger');
const getApp = require('../../../lib/app');
const { EventEmitter } = require('events');
const eventBus = new EventEmitter();
test.beforeEach(() => {
logger.setLevel('FATAL');
});
function getSetup () {
const base = `/random${Math.round(Math.random() * 1000)}`;
const stores = store.createStores();
const app = getApp({
baseUriPath: base,
stores,
eventBus,
});
return {
base,
featureToggleStore: stores.featureToggleStore,
request: supertest(app),
};
}
test('should get api defintion', t => {
const { request, base } = getSetup();
return request
.get(`${base}/api/`)
.expect('Content-Type', /json/)
.expect(200)
.expect((res) => {
t.true(res.body.links['feature-toggles'].uri === '/api/features');
});
});