2016-11-11 17:39:33 +01:00
|
|
|
'use strict';
|
|
|
|
|
2018-12-17 09:24:49 +01:00
|
|
|
const test = require('ava');
|
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');
|
|
|
|
|
|
|
|
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();
|
|
|
|
});
|
2016-11-11 17:39:33 +01:00
|
|
|
|
2016-11-28 17:11:11 +01:00
|
|
|
test.serial('should get application details', async t => {
|
2017-06-28 10:20:22 +02:00
|
|
|
t.plan(3);
|
2019-10-03 15:01:33 +02:00
|
|
|
const request = await setupApp(stores);
|
2016-11-13 15:41:35 +01:00
|
|
|
return 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 => {
|
2016-11-13 15:41:35 +01:00
|
|
|
t.true(res.status === 200);
|
2016-12-09 17:30:12 +01:00
|
|
|
t.true(res.body.appName === 'demo-app-1');
|
2016-11-28 17:11:11 +01:00
|
|
|
t.true(res.body.instances.length === 1);
|
2019-10-03 15:01:33 +02:00
|
|
|
});
|
2016-11-28 17:11:11 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test.serial('should get list of applications', async t => {
|
2017-06-28 10:20:22 +02:00
|
|
|
t.plan(2);
|
2019-10-03 15:01:33 +02:00
|
|
|
const request = await setupApp(stores);
|
2016-11-28 17:11:11 +01:00
|
|
|
return 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 => {
|
2016-11-28 17:11:11 +01:00
|
|
|
t.true(res.status === 200);
|
2020-09-25 09:39:12 +02:00
|
|
|
t.is(res.body.applications.length, 3);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test.serial('should delete application', async t => {
|
|
|
|
t.plan(2);
|
|
|
|
const request = await setupApp(stores);
|
|
|
|
await request
|
|
|
|
.delete('/api/admin/metrics/applications/deletable-app')
|
|
|
|
.expect(res => {
|
|
|
|
t.is(res.status, 200);
|
|
|
|
});
|
|
|
|
return request
|
|
|
|
.get('/api/admin/metrics/applications')
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect(res => {
|
2019-10-03 15:01:33 +02:00
|
|
|
t.is(res.body.applications.length, 2);
|
|
|
|
});
|
2016-11-11 17:39:33 +01:00
|
|
|
});
|
2020-09-25 09:39:12 +02:00
|
|
|
|
2021-01-18 12:32:19 +01:00
|
|
|
test.serial(
|
|
|
|
'deleting an application should be idempotent, so expect 200',
|
|
|
|
async t => {
|
|
|
|
t.plan(1);
|
|
|
|
const request = await setupApp(stores);
|
|
|
|
return request
|
|
|
|
.delete('/api/admin/metrics/applications/unknown')
|
|
|
|
.expect(res => {
|
|
|
|
t.is(res.status, 200);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
);
|