2017-06-28 10:20:22 +02:00
|
|
|
'use strict';
|
|
|
|
|
2018-12-17 09:24:49 +01:00
|
|
|
const test = require('ava');
|
2017-06-28 10:20:22 +02:00
|
|
|
|
2020-04-14 22:29:11 +02:00
|
|
|
const { setupApp } = require('../../helpers/test-helper');
|
2017-12-18 14:21:11 +01:00
|
|
|
const metricsExample = require('../../../examples/client-metrics.json');
|
2019-10-03 15:01:33 +02:00
|
|
|
const dbInit = require('../../helpers/database-init');
|
|
|
|
const getLogger = require('../../../fixtures/no-logger');
|
|
|
|
|
|
|
|
let stores;
|
|
|
|
|
|
|
|
test.before(async () => {
|
|
|
|
const db = await dbInit('metrics_api_client', getLogger);
|
|
|
|
stores = db.stores;
|
|
|
|
});
|
|
|
|
|
|
|
|
test.after(async () => {
|
|
|
|
await stores.db.destroy();
|
|
|
|
});
|
2017-12-18 14:21:11 +01:00
|
|
|
|
|
|
|
test.serial('should be possble to send metrics', async t => {
|
|
|
|
t.plan(0);
|
2019-10-03 15:01:33 +02:00
|
|
|
const request = await setupApp(stores);
|
2017-12-18 14:21:11 +01:00
|
|
|
return request
|
|
|
|
.post('/api/client/metrics')
|
|
|
|
.send(metricsExample)
|
2019-10-03 15:01:33 +02:00
|
|
|
.expect(202);
|
2017-12-18 14:21:11 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test.serial('should require valid send metrics', async t => {
|
|
|
|
t.plan(0);
|
2019-10-03 15:01:33 +02:00
|
|
|
const request = await setupApp(stores);
|
2017-12-18 14:21:11 +01:00
|
|
|
return request
|
|
|
|
.post('/api/client/metrics')
|
|
|
|
.send({
|
|
|
|
appName: 'test',
|
|
|
|
})
|
2019-10-03 15:01:33 +02:00
|
|
|
.expect(400);
|
2017-12-18 14:21:11 +01:00
|
|
|
});
|
2020-09-25 09:39:12 +02:00
|
|
|
|
|
|
|
test.serial('should register client', async t => {
|
|
|
|
t.plan(0);
|
|
|
|
const request = await setupApp(stores);
|
|
|
|
return request
|
|
|
|
.post('/api/client/register')
|
|
|
|
.send({
|
|
|
|
appName: 'demo',
|
|
|
|
instanceId: 'test',
|
|
|
|
strategies: ['default'],
|
|
|
|
started: Date.now(),
|
|
|
|
interval: 10,
|
|
|
|
})
|
|
|
|
.expect(202);
|
|
|
|
});
|
|
|
|
|
|
|
|
test.serial('should allow client to register multiple times', async t => {
|
|
|
|
t.plan(0);
|
|
|
|
const request = await setupApp(stores);
|
|
|
|
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),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test.serial('should accept client metrics', async t => {
|
|
|
|
t.plan(0);
|
|
|
|
const request = await setupApp(stores);
|
|
|
|
return request
|
|
|
|
.post('/api/client/metrics')
|
|
|
|
.send({
|
|
|
|
appName: 'demo',
|
|
|
|
instanceId: '1',
|
|
|
|
bucket: {
|
|
|
|
start: Date.now(),
|
|
|
|
stop: Date.now(),
|
|
|
|
toggles: {},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
.expect(202);
|
|
|
|
});
|