1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-18 20:09:08 +02:00
unleash.unleash/test/e2e/api/admin/metrics.e2e.test.js
Ivar Conradi Østhus d1fd5d3900 fix: e2e tests should only set up one database per test file (#504)
* fix: e2e tests should only set up one database per test file

* fix: Allow e2e-tests to reset db content
2020-02-20 08:34:29 +01:00

104 lines
2.6 KiB
JavaScript

'use strict';
const test = require('ava');
const dbInit = require('../../helpers/database-init');
const { setupApp } = require('../../helpers/test-helper');
const getLogger = require('../../../fixtures/no-logger');
let stores;
let reset = () => {};
test.before(async () => {
const db = await dbInit('metrics_serial', getLogger);
stores = db.stores;
reset = db.reset;
});
test.after(async () => {
await stores.db.destroy();
});
test.afterEach(async () => {
await reset();
});
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);
});
test.serial('should get application details', async t => {
t.plan(3);
const request = await setupApp(stores);
return request
.get('/api/admin/metrics/applications/demo-app-1')
.expect('Content-Type', /json/)
.expect(res => {
t.true(res.status === 200);
t.true(res.body.appName === 'demo-app-1');
t.true(res.body.instances.length === 1);
});
});
test.serial('should get list of applications', async t => {
t.plan(2);
const request = await setupApp(stores);
return request
.get('/api/admin/metrics/applications')
.expect('Content-Type', /json/)
.expect(res => {
t.true(res.status === 200);
t.is(res.body.applications.length, 2);
});
});