2016-11-11 17:39:33 +01:00
|
|
|
'use strict';
|
2016-11-13 15:41:35 +01:00
|
|
|
const test = require('ava');
|
2016-11-13 20:33:23 +01:00
|
|
|
const { setupApp } = require('./helpers/test-helper');
|
2016-11-13 15:41:35 +01:00
|
|
|
const logger = require('../../lib/logger');
|
2016-11-11 17:39:33 +01:00
|
|
|
|
2016-11-13 15:41:35 +01:00
|
|
|
test.beforeEach(() => {
|
|
|
|
logger.setLevel('FATAL');
|
|
|
|
});
|
2016-11-11 17:39:33 +01:00
|
|
|
|
2016-11-13 15:41:35 +01:00
|
|
|
test.serial('should register client', async (t) => {
|
|
|
|
const { request, destroy } = await setupApp('metrics_serial');
|
|
|
|
return request
|
|
|
|
.post('/api/client/register')
|
|
|
|
.send({
|
|
|
|
appName: 'demo',
|
|
|
|
instanceId: 'test',
|
|
|
|
strategies: ['default'],
|
|
|
|
started: Date.now(),
|
|
|
|
interval: 10
|
|
|
|
})
|
|
|
|
.expect(202)
|
|
|
|
.then(destroy);
|
|
|
|
});
|
2016-11-11 17:39:33 +01:00
|
|
|
|
2016-12-02 17:19:59 +01:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
|
2016-11-13 15:41:35 +01:00
|
|
|
test.serial('should accept client metrics', async t => {
|
|
|
|
const { request, destroy } = await setupApp('metrics_serial');
|
|
|
|
return request
|
|
|
|
.post('/api/client/metrics')
|
|
|
|
.send({
|
|
|
|
appName: 'demo',
|
|
|
|
instanceId: '1',
|
|
|
|
bucket: {
|
|
|
|
start: Date.now(),
|
|
|
|
stop: Date.now(),
|
|
|
|
toggles: {}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.expect(202)
|
|
|
|
.then(destroy);
|
|
|
|
});
|
2016-11-11 17:39:33 +01:00
|
|
|
|
2016-11-28 17:11:11 +01:00
|
|
|
test.serial('should get application details', async t => {
|
2016-11-13 15:41:35 +01:00
|
|
|
const { request, destroy } = await setupApp('metrics_serial');
|
|
|
|
return request
|
2016-12-09 17:30:12 +01:00
|
|
|
.get('/api/client/applications/demo-app-1')
|
2016-11-13 15:41:35 +01:00
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect((res) => {
|
|
|
|
t.true(res.status === 200);
|
2016-12-09 17:30:12 +01:00
|
|
|
t.true(res.body.appName === 'demo-app-1');
|
2016-11-28 17:11:11 +01:00
|
|
|
t.true(res.body.instances.length === 1);
|
|
|
|
})
|
|
|
|
.then(destroy);
|
|
|
|
});
|
|
|
|
|
|
|
|
test.serial('should get list of applications', async t => {
|
|
|
|
const { request, destroy } = await setupApp('metrics_serial');
|
|
|
|
return request
|
|
|
|
.get('/api/client/applications')
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect((res) => {
|
|
|
|
t.true(res.status === 200);
|
2016-12-09 17:30:12 +01:00
|
|
|
t.true(res.body.applications.length === 2);
|
2016-11-13 15:41:35 +01:00
|
|
|
})
|
|
|
|
.then(destroy);
|
2016-11-11 17:39:33 +01:00
|
|
|
});
|