1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-23 20:07:40 +02:00
unleash.unleash/src/test/e2e/api/admin/metrics.e2e.test.js

112 lines
3.0 KiB
JavaScript
Raw Normal View History

2016-11-11 17:39:33 +01:00
'use strict';
const dbInit = require('../../helpers/database-init');
const { setupApp } = require('../../helpers/test-helper');
const getLogger = require('../../../fixtures/no-logger');
let app;
let db;
beforeAll(async () => {
db = await dbInit('metrics_serial', getLogger);
app = await setupApp(db.stores);
});
beforeEach(async () => {
await app.services.clientMetricsService.createApplication({
appName: 'demo-app-1',
strategies: ['default'],
announced: true,
});
await app.services.clientMetricsService.createApplication({
appName: 'demo-app-2',
strategies: ['default', 'extra'],
description: 'hello',
announced: true,
});
await app.services.clientMetricsService.createApplication({
appName: 'deletable-app',
strategies: ['default'],
description: 'Some desc',
announced: true,
});
await db.stores.clientInstanceStore.insert({
appName: 'demo-app-1',
instanceId: 'test-1',
strategies: ['default'],
started: 1516026938494,
interval: 10,
});
await db.stores.clientInstanceStore.insert({
appName: 'demo-seed-2',
instanceId: 'test-2',
strategies: ['default'],
started: 1516026938494,
interval: 10,
});
await db.stores.clientInstanceStore.insert({
appName: 'deletable-app',
instanceId: 'inst-1',
strategies: ['default'],
started: 1516026938494,
interval: 10,
});
});
afterAll(async () => {
if (db) {
await db.destroy();
}
});
afterEach(async () => {
await db.reset();
});
2016-11-11 17:39:33 +01:00
test('should get application details', async () => {
expect.assertions(2);
return app.request
.get('/api/admin/metrics/applications/demo-app-1')
2016-11-13 15:41:35 +01:00
.expect('Content-Type', /json/)
.expect(200)
.expect(res => {
expect(res.body.appName).toBe('demo-app-1');
expect(res.body.instances).toHaveLength(1);
});
});
test('should get list of applications', async () => {
expect.assertions(1);
return app.request
.get('/api/admin/metrics/applications')
.expect('Content-Type', /json/)
.expect(200)
.expect(res => {
expect(res.body.applications).toHaveLength(3);
2020-09-25 09:39:12 +02:00
});
});
test('should delete application', async () => {
expect.assertions(2);
await app.request
2020-09-25 09:39:12 +02:00
.delete('/api/admin/metrics/applications/deletable-app')
.expect(res => {
expect(res.status).toBe(200);
2020-09-25 09:39:12 +02:00
});
return app.request
2020-09-25 09:39:12 +02:00
.get('/api/admin/metrics/applications')
.expect('Content-Type', /json/)
.expect(res => {
expect(res.body.applications).toHaveLength(2);
});
2016-11-11 17:39:33 +01:00
});
2020-09-25 09:39:12 +02:00
test('deleting an application should be idempotent, so expect 200', async () => {
expect.assertions(1);
return app.request
.delete('/api/admin/metrics/applications/unknown')
.expect(res => {
expect(res.status).toBe(200);
});
});