2021-08-12 15:04:37 +02:00
|
|
|
import dbInit from '../../helpers/database-init';
|
|
|
|
import { setupApp } from '../../helpers/test-helper';
|
|
|
|
import getLogger from '../../../fixtures/no-logger';
|
2021-11-02 15:13:46 +01:00
|
|
|
import { parseISO } from 'date-fns';
|
2019-10-03 15:01:33 +02:00
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
let app;
|
2021-03-19 22:25:21 +01:00
|
|
|
let db;
|
2019-10-03 15:01:33 +02:00
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
beforeAll(async () => {
|
2021-03-19 22:25:21 +01:00
|
|
|
db = await dbInit('metrics_serial', getLogger);
|
2021-05-28 11:10:24 +02:00
|
|
|
app = await setupApp(db.stores);
|
2019-10-03 15:01:33 +02:00
|
|
|
});
|
|
|
|
|
2021-07-07 10:46:50 +02:00
|
|
|
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,
|
|
|
|
});
|
2021-11-02 15:13:46 +01:00
|
|
|
|
|
|
|
const clientStartedDate = parseISO('2018-01-15T14:35:38.494Z');
|
2021-07-07 10:46:50 +02:00
|
|
|
await db.stores.clientInstanceStore.insert({
|
|
|
|
appName: 'demo-app-1',
|
|
|
|
instanceId: 'test-1',
|
|
|
|
strategies: ['default'],
|
2021-11-02 15:13:46 +01:00
|
|
|
started: clientStartedDate,
|
2021-07-07 10:46:50 +02:00
|
|
|
interval: 10,
|
|
|
|
});
|
|
|
|
await db.stores.clientInstanceStore.insert({
|
|
|
|
appName: 'demo-seed-2',
|
|
|
|
instanceId: 'test-2',
|
|
|
|
strategies: ['default'],
|
2021-11-02 15:13:46 +01:00
|
|
|
started: clientStartedDate,
|
2021-07-07 10:46:50 +02:00
|
|
|
interval: 10,
|
|
|
|
});
|
|
|
|
await db.stores.clientInstanceStore.insert({
|
|
|
|
appName: 'deletable-app',
|
|
|
|
instanceId: 'inst-1',
|
|
|
|
strategies: ['default'],
|
2021-11-02 15:13:46 +01:00
|
|
|
started: clientStartedDate,
|
2021-07-07 10:46:50 +02:00
|
|
|
interval: 10,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
afterAll(async () => {
|
|
|
|
if (db) {
|
|
|
|
await db.destroy();
|
|
|
|
}
|
2019-10-03 15:01:33 +02:00
|
|
|
});
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
afterEach(async () => {
|
|
|
|
await db.reset();
|
2019-10-03 15:01:33 +02:00
|
|
|
});
|
2016-11-11 17:39:33 +01:00
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('should get application details', async () => {
|
|
|
|
return app.request
|
2017-06-28 10:20:22 +02:00
|
|
|
.get('/api/admin/metrics/applications/demo-app-1')
|
2016-11-13 15:41:35 +01:00
|
|
|
.expect('Content-Type', /json/)
|
2021-07-07 10:46:50 +02:00
|
|
|
.expect(200)
|
2021-08-12 15:04:37 +02:00
|
|
|
.expect((res) => {
|
2021-07-07 10:46:50 +02:00
|
|
|
expect(res.body.appName).toBe('demo-app-1');
|
|
|
|
expect(res.body.instances).toHaveLength(1);
|
2019-10-03 15:01:33 +02:00
|
|
|
});
|
2016-11-28 17:11:11 +01:00
|
|
|
});
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('should get list of applications', async () => {
|
2021-07-07 10:46:50 +02:00
|
|
|
expect.assertions(1);
|
2021-05-28 11:10:24 +02:00
|
|
|
return app.request
|
2017-06-28 10:20:22 +02:00
|
|
|
.get('/api/admin/metrics/applications')
|
2016-11-28 17:11:11 +01:00
|
|
|
.expect('Content-Type', /json/)
|
2021-07-07 10:46:50 +02:00
|
|
|
.expect(200)
|
2021-08-12 15:04:37 +02:00
|
|
|
.expect((res) => {
|
2021-07-07 10:46:50 +02:00
|
|
|
expect(res.body.applications).toHaveLength(3);
|
2020-09-25 09:39:12 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-05-28 11:10:24 +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')
|
2021-08-12 15:04:37 +02:00
|
|
|
.expect((res) => {
|
2021-05-28 11:10:24 +02:00
|
|
|
expect(res.status).toBe(200);
|
2020-09-25 09:39:12 +02:00
|
|
|
});
|
2021-05-28 11:10:24 +02:00
|
|
|
return app.request
|
2020-09-25 09:39:12 +02:00
|
|
|
.get('/api/admin/metrics/applications')
|
|
|
|
.expect('Content-Type', /json/)
|
2021-08-12 15:04:37 +02:00
|
|
|
.expect((res) => {
|
2021-07-07 10:46:50 +02:00
|
|
|
expect(res.body.applications).toHaveLength(2);
|
2019-10-03 15:01:33 +02:00
|
|
|
});
|
2016-11-11 17:39:33 +01:00
|
|
|
});
|
2020-09-25 09:39:12 +02:00
|
|
|
|
2021-05-28 11:10:24 +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')
|
2021-08-12 15:04:37 +02:00
|
|
|
.expect((res) => {
|
2021-05-28 11:10:24 +02:00
|
|
|
expect(res.status).toBe(200);
|
|
|
|
});
|
|
|
|
});
|