1
0
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:
ivaosthu 2018-01-17 15:31:53 +01:00
parent b222c9acd9
commit 28d6a1b46e
4 changed files with 42 additions and 17 deletions

View File

@ -4,7 +4,11 @@ const { Router } = require('express');
const logger = require('../../logger')('/admin-api/metrics.js'); const logger = require('../../logger')('/admin-api/metrics.js');
const ClientMetrics = require('../../client-metrics'); 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) { exports.router = function(config) {
const { const {
@ -67,10 +71,7 @@ exports.router = function(config) {
clientApplicationsStore clientApplicationsStore
.upsert(input) .upsert(input)
.then(() => res.status(202).end()) .then(() => res.status(202).end())
.catch(e => { .catch(err => catchLogAndSendErrorResponse(err, res));
logger.error(e);
res.status(500).end();
});
}); });
function toLookup(metaData) { function toLookup(metaData) {

View File

@ -93,3 +93,31 @@ test('should return metrics for all toggles', t => {
t.true(metrics.lastMinute !== undefined); 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);
});

View File

@ -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 };

View File

@ -1,6 +1,12 @@
'use strict'; 'use strict';
const _appliations = [];
module.exports = () => ({ module.exports = () => ({
upsert: () => Promise.resolve(), upsert: app => {
getApplications: () => Promise.resolve([]), _appliations.push(app);
return Promise.resolve();
},
getApplications: () => Promise.resolve(_appliations),
getApplication: appName => _appliations.filter(a => a.name === appName)[0],
}); });