diff --git a/test/e2e/metrics-api.test.js b/test/e2e/metrics-api.test.js new file mode 100644 index 0000000000..1d404a9ac7 --- /dev/null +++ b/test/e2e/metrics-api.test.js @@ -0,0 +1,64 @@ +'use strict'; + +const specHelper = require('./util/test-helper'); +const assert = require('assert'); +let request; + +describe('The metrics api', () => { + beforeEach(done => { + specHelper.setupApp().then((app) => { + request = app.request; + done(); + }); + }); + + it('should register client', (done) => { + request + .post('/api/client/register') + .send({ + appName: 'demo', + instanceId: 'test', + strategies: ['default'], + started: Date.now(), + interval: 10 + }) + .expect(202, done); + }); + + it('should accept client metrics', (done) => { + request + .post('/api/client/metrics') + .send({ + appName: 'demo', + instanceId: '1', + bucket: { + start: Date.now(), + stop: Date.now(), + toggles: {} + } + }) + .expect(202, done) + }); + + it('should get client strategies', done => { + request + .get('/api/client/strategies') + .expect('Content-Type', /json/) + .end((err, res) => { + assert(res.status, 200); + assert(res.body.length === 1, `expected 1 registerd client, got ${res.body}`); + done(); + });; + }); + + it('should get client instances', done => { + request + .get('/api/client/instances') + .expect('Content-Type', /json/) + .end((err, res) => { + assert(res.status, 200); + assert(res.body.length === 1, `expected 1 registerd client, got ${res.body}`); + done(); + });; + }); +}); diff --git a/test/e2e/util/test-helper.js b/test/e2e/util/test-helper.js index 52cfe9f9b1..175d90c7c5 100644 --- a/test/e2e/util/test-helper.js +++ b/test/e2e/util/test-helper.js @@ -36,6 +36,30 @@ function createStrategies (stores) { ].map(strategy => stores.strategyStore._createStrategy(strategy)); } +function createClientStrategy (stores) { + return [ + { + appName: 'demo-sed', + instanceId: 'test-1', + strategies: ['default'], + started: Date.now(), + interval: 10 + }, + ].map(client => stores.clientStrategyStore.insert(client)); +} + +function createClientInstance (stores) { + return [ + { + appName: 'demo-seed', + instanceId: 'test-1', + strategies: ['default'], + started: Date.now(), + interval: 10 + }, + ].map(client => stores.clientInstanceStore.insert(client)); +} + function createFeatures (stores) { return [ { @@ -100,20 +124,21 @@ function createFeatures (stores) { ].map(feature => stores.featureToggleStore._createFeature(feature)); } -function destroyStrategies (stores) { - return stores.db('strategies').del(); -} - -function destroyFeatures (stores) { - return stores.db('features').del(); -} - function resetDatabase (stores) { - return Promise.all([destroyStrategies(stores), destroyFeatures(stores)]); + return Promise.all([ + stores.db('strategies').del(), + stores.db('features').del(), + stores.db('client_strategies').del(), + stores.db('client_instances').del() + ]); } function setupDatabase (stores) { - return Promise.all(createStrategies(stores).concat(createFeatures(stores))) + return Promise.all( + createStrategies(stores) + .concat(createFeatures(stores) + .concat(createClientInstance(stores)) + .concat(createClientStrategy(stores)))) } module.exports = {