From bec646d7979067ffd936a9fe8a31ad699adcd948 Mon Sep 17 00:00:00 2001 From: ivaosthu Date: Fri, 2 Dec 2016 17:19:59 +0100 Subject: [PATCH] more tests --- lib/data-helper/legacy-feature-mapper.test.js | 13 +++++++++++ lib/routes/metrics.js | 4 ++-- test/e2e/metrics-api.test.js | 22 ++++++++++++++++++- test/unit/routes/metrics.test.js | 8 +++++++ 4 files changed, 44 insertions(+), 3 deletions(-) diff --git a/lib/data-helper/legacy-feature-mapper.test.js b/lib/data-helper/legacy-feature-mapper.test.js index dab20184a7..b64efd5402 100644 --- a/lib/data-helper/legacy-feature-mapper.test.js +++ b/lib/data-helper/legacy-feature-mapper.test.js @@ -24,6 +24,19 @@ test('adds old fields to feature', t => { t.deepEqual(mappedFeature.parameters, feature.strategies[0].parameters); }); +test('adds old fields to feature handles missing strategies field', t => { + const feature = { + name: 'test', + enabled: 0 + }; + + const mappedFeature = mapper.addOldFields(feature); + + t.true(mappedFeature.name === feature.name); + t.true(mappedFeature.enabled === feature.enabled); + t.true(mappedFeature.strategies.length === 0); +}); + test('transforms fields to new format', t => { const feature = { name: 'test', diff --git a/lib/routes/metrics.js b/lib/routes/metrics.js index 906d4b8538..2c5f71b9b0 100644 --- a/lib/routes/metrics.js +++ b/lib/routes/metrics.js @@ -40,7 +40,7 @@ module.exports = function (app, config) { instanceId: cleaned.instanceId, clientIp, })) - .catch(err => catchLogAndSendErrorResponse(err, res)); + .catch(err => logger.error('failed to store metrics', err)); res.status(202).end(); }); @@ -64,7 +64,7 @@ module.exports = function (app, config) { })) .then(() => logger.info(`New client registered with appName=${cleaned.appName} and instanceId=${cleaned.instanceId}`)) - .catch(err => catchLogAndSendErrorResponse(err, res)); + .catch(err => logger.error('failed to register client', err)); res.status(202).end(); }); diff --git a/test/e2e/metrics-api.test.js b/test/e2e/metrics-api.test.js index c407c3604f..3b90f1b643 100644 --- a/test/e2e/metrics-api.test.js +++ b/test/e2e/metrics-api.test.js @@ -22,6 +22,27 @@ test.serial('should register client', async (t) => { .then(destroy); }); +test.serial('should allow client to register multiple times', async (t) => { + const { request, destroy } = await setupApp('metrics_serial'); + const clientRegistration = { + appName: 'multipleRegistration', + instanceId: 'test', + strategies: ['default', 'another'], + started: Date.now(), + interval: 10 + }; + + return request + .post('/api/client/register') + .send(clientRegistration) + .expect(202) + .then(() => request + .post('/api/client/register') + .send(clientRegistration) + .expect(202)) + .then(destroy); +}); + test.serial('should accept client metrics', async t => { const { request, destroy } = await setupApp('metrics_serial'); return request @@ -75,4 +96,3 @@ test.serial('should get list of applications', async t => { }) .then(destroy); }); - diff --git a/test/unit/routes/metrics.test.js b/test/unit/routes/metrics.test.js index 07bd55d436..1ff132cedf 100644 --- a/test/unit/routes/metrics.test.js +++ b/test/unit/routes/metrics.test.js @@ -62,6 +62,14 @@ test('should require strategies field', () => { .expect(400); }); +test('should validate client metrics', () => { + const { request } = getSetup(); + return request + .post('/api/client/metrics') + .send({random: 'blush'}) + .expect(400); +}); + test('should accept client metrics', () => { const { request } = getSetup();