1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-28 00:06:53 +01:00
unleash.unleash/test/e2e/api/client/metrics.e2e.test.js

95 lines
2.3 KiB
JavaScript
Raw Normal View History

'use strict';
2018-12-17 09:24:49 +01:00
const test = require('ava');
const { setupApp } = require('../../helpers/test-helper');
2017-12-18 14:21:11 +01:00
const metricsExample = require('../../../examples/client-metrics.json');
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);
const request = await setupApp(stores);
2017-12-18 14:21:11 +01:00
return request
.post('/api/client/metrics')
.send(metricsExample)
.expect(202);
2017-12-18 14:21:11 +01:00
});
test.serial('should require valid send metrics', async t => {
t.plan(0);
const request = await setupApp(stores);
2017-12-18 14:21:11 +01:00
return request
.post('/api/client/metrics')
.send({
appName: 'test',
})
.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);
});