mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-04 00:18:01 +01:00
A bit of house-keeping
This commit is contained in:
parent
b222c9acd9
commit
28d6a1b46e
@ -4,7 +4,11 @@ const { Router } = require('express');
|
||||
|
||||
const logger = require('../../logger')('/admin-api/metrics.js');
|
||||
const ClientMetrics = require('../../client-metrics');
|
||||
const { catchLogAndSendErrorResponse } = require('./route-utils');
|
||||
|
||||
const catchLogAndSendErrorResponse = (err, res) => {
|
||||
logger.error(err);
|
||||
res.status(500).end();
|
||||
};
|
||||
|
||||
exports.router = function(config) {
|
||||
const {
|
||||
@ -67,10 +71,7 @@ exports.router = function(config) {
|
||||
clientApplicationsStore
|
||||
.upsert(input)
|
||||
.then(() => res.status(202).end())
|
||||
.catch(e => {
|
||||
logger.error(e);
|
||||
res.status(500).end();
|
||||
});
|
||||
.catch(err => catchLogAndSendErrorResponse(err, res));
|
||||
});
|
||||
|
||||
function toLookup(metaData) {
|
||||
|
@ -93,3 +93,31 @@ test('should return metrics for all toggles', t => {
|
||||
t.true(metrics.lastMinute !== undefined);
|
||||
});
|
||||
});
|
||||
|
||||
test('should return applications', t => {
|
||||
t.plan(2);
|
||||
const { request, stores } = getSetup();
|
||||
const appName = '123!23';
|
||||
|
||||
stores.clientApplicationsStore.upsert({ appName });
|
||||
|
||||
return request
|
||||
.get(`/api/admin/metrics/applications/`)
|
||||
.expect(200)
|
||||
.expect(res => {
|
||||
const metrics = res.body;
|
||||
t.true(metrics.applications.length === 1);
|
||||
t.true(metrics.applications[0].appName === appName);
|
||||
});
|
||||
});
|
||||
|
||||
test('should store application', t => {
|
||||
t.plan(0);
|
||||
const { request } = getSetup();
|
||||
const appName = '123!23';
|
||||
|
||||
return request
|
||||
.post(`/api/admin/metrics/applications/${appName}`)
|
||||
.send({ appName })
|
||||
.expect(202);
|
||||
});
|
||||
|
@ -1,10 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
const logger = require('../../logger')('route-utils.js');
|
||||
|
||||
const catchLogAndSendErrorResponse = (err, res) => {
|
||||
logger.error(err);
|
||||
res.status(500).end();
|
||||
};
|
||||
|
||||
module.exports = { catchLogAndSendErrorResponse };
|
10
test/fixtures/fake-client-applications-store.js
vendored
10
test/fixtures/fake-client-applications-store.js
vendored
@ -1,6 +1,12 @@
|
||||
'use strict';
|
||||
|
||||
const _appliations = [];
|
||||
|
||||
module.exports = () => ({
|
||||
upsert: () => Promise.resolve(),
|
||||
getApplications: () => Promise.resolve([]),
|
||||
upsert: app => {
|
||||
_appliations.push(app);
|
||||
return Promise.resolve();
|
||||
},
|
||||
getApplications: () => Promise.resolve(_appliations),
|
||||
getApplication: appName => _appliations.filter(a => a.name === appName)[0],
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user