2016-11-11 17:39:33 +01:00
|
|
|
'use strict';
|
|
|
|
|
2019-10-03 15:01:33 +02:00
|
|
|
const dbInit = require('../../helpers/database-init');
|
|
|
|
const { setupApp } = require('../../helpers/test-helper');
|
|
|
|
const getLogger = require('../../../fixtures/no-logger');
|
|
|
|
|
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-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 () => {
|
|
|
|
expect.assertions(3);
|
|
|
|
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/)
|
2017-06-28 10:20:22 +02:00
|
|
|
.expect(res => {
|
2021-05-28 11:10:24 +02:00
|
|
|
expect(res.status === 200).toBe(true);
|
|
|
|
expect(res.body.appName === 'demo-app-1').toBe(true);
|
|
|
|
expect(res.body.instances.length === 1).toBe(true);
|
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 () => {
|
|
|
|
expect.assertions(2);
|
|
|
|
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/)
|
2017-06-28 10:20:22 +02:00
|
|
|
.expect(res => {
|
2021-05-28 11:10:24 +02:00
|
|
|
expect(res.status === 200).toBe(true);
|
|
|
|
expect(res.body.applications.length).toBe(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')
|
|
|
|
.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/)
|
|
|
|
.expect(res => {
|
2021-05-28 11:10:24 +02:00
|
|
|
expect(res.body.applications.length).toBe(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')
|
|
|
|
.expect(res => {
|
|
|
|
expect(res.status).toBe(200);
|
|
|
|
});
|
|
|
|
});
|