1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-23 20:07:40 +02:00
unleash.unleash/test/e2e/api/admin/metrics.e2e.test.js
Christopher Kolstad c17a1980a2
Add service layer
This simplifies stores to just be storage interaction, they no longer react to events.

Controllers now call services and awaits the result from the call.

When the service calls are returned the database is updated.
This simplifies testing dramatically, cause you know that your state is
updated when returned from a call, rather than hoping the store has
picked up the event (which really was a command) and reacted to it.

Events are still emitted from eventStore, so other parts of the app can
react to events as they're being sent out.

As part of the move to services, we now also emit an application-created
event when we see a new client application.

Fixes: #685
Fixes: #595
2021-01-21 10:59:19 +01:00

78 lines
2.0 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 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, 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 => {
t.is(res.body.applications.length, 2);
});
});
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);
});
},
);