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:
parent
abb00f8e1e
commit
8beb4b8876
19
lib/routes/api.js
Normal file
19
lib/routes/api.js
Normal 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);
|
||||
});
|
||||
};
|
@ -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);
|
||||
|
41
test/unit/routes/api.test.js
Normal file
41
test/unit/routes/api.test.js
Normal 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');
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user