mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-11 00:08:30 +01:00
added e2e for metrics api
This commit is contained in:
parent
0b71d64651
commit
bc8b1d572a
64
test/e2e/metrics-api.test.js
Normal file
64
test/e2e/metrics-api.test.js
Normal file
@ -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();
|
||||
});;
|
||||
});
|
||||
});
|
@ -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 = {
|
||||
|
Loading…
Reference in New Issue
Block a user