2021-08-12 15:04:37 +02:00
|
|
|
import supertest from 'supertest';
|
|
|
|
import createStores from '../../../test/fixtures/store';
|
|
|
|
import permissions from '../../../test/fixtures/permissions';
|
|
|
|
import getApp from '../../app';
|
|
|
|
import { createTestConfig } from '../../../test/config/test-config';
|
|
|
|
import { createServices } from '../../services';
|
2017-06-28 10:20:22 +02:00
|
|
|
|
2022-01-06 10:31:00 +01:00
|
|
|
async function getSetup() {
|
2021-08-12 15:04:37 +02:00
|
|
|
const stores = createStores();
|
2018-12-19 10:36:56 +01:00
|
|
|
const perms = permissions();
|
2021-04-22 10:07:10 +02:00
|
|
|
const config = createTestConfig({
|
2018-12-19 10:36:56 +01:00
|
|
|
preRouterHook: perms.hook,
|
2021-04-22 10:07:10 +02:00
|
|
|
});
|
2020-12-17 19:22:30 +01:00
|
|
|
const services = createServices(stores, config);
|
2022-01-06 10:31:00 +01:00
|
|
|
const app = await getApp(config, stores, services);
|
2017-06-28 10:20:22 +02:00
|
|
|
|
|
|
|
return {
|
|
|
|
request: supertest(app),
|
|
|
|
stores,
|
2018-12-19 10:36:56 +01:00
|
|
|
perms,
|
2021-05-28 11:10:24 +02:00
|
|
|
destroy: () => {
|
|
|
|
services.versionService.destroy();
|
2021-12-09 21:25:06 +01:00
|
|
|
services.clientInstanceService.destroy();
|
2021-05-28 11:10:24 +02:00
|
|
|
services.apiTokenService.destroy();
|
|
|
|
},
|
2017-06-28 10:20:22 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
let stores;
|
|
|
|
let request;
|
|
|
|
let destroy;
|
|
|
|
|
2022-01-06 10:31:00 +01:00
|
|
|
beforeEach(async () => {
|
|
|
|
const setup = await getSetup();
|
2021-05-28 11:10:24 +02:00
|
|
|
stores = setup.stores;
|
|
|
|
request = setup.request;
|
|
|
|
destroy = setup.destroy;
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
destroy();
|
|
|
|
});
|
|
|
|
|
2021-12-09 21:02:58 +01:00
|
|
|
test('/api/admin/metrics/seen-toggles is deprecated', () => {
|
|
|
|
return request.get('/api/admin/metrics/seen-toggles').expect(410);
|
2017-06-28 10:20:22 +02:00
|
|
|
});
|
|
|
|
|
2021-12-09 21:02:58 +01:00
|
|
|
test('/api/admin/metrics/feature-toggles is deprecated', () => {
|
|
|
|
return request.get('/api/admin/metrics/feature-toggles').expect(410);
|
2017-06-28 10:20:22 +02:00
|
|
|
});
|
2018-01-17 15:31:53 +01:00
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('should return empty list of client applications', () => {
|
2018-11-29 21:45:26 +01:00
|
|
|
return request
|
|
|
|
.get('/api/admin/metrics/applications')
|
|
|
|
.expect(200)
|
2021-08-12 15:04:37 +02:00
|
|
|
.expect((res) => {
|
2021-05-28 11:10:24 +02:00
|
|
|
expect(res.body.applications.length === 0).toBe(true);
|
2018-11-29 21:45:26 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('should return applications', () => {
|
|
|
|
expect.assertions(2);
|
2018-01-17 15:31:53 +01:00
|
|
|
const appName = '123!23';
|
|
|
|
|
|
|
|
stores.clientApplicationsStore.upsert({ appName });
|
|
|
|
|
|
|
|
return request
|
2021-02-23 06:20:10 +01:00
|
|
|
.get('/api/admin/metrics/applications/')
|
2018-01-17 15:31:53 +01:00
|
|
|
.expect(200)
|
2021-08-12 15:04:37 +02:00
|
|
|
.expect((res) => {
|
2018-01-17 15:31:53 +01:00
|
|
|
const metrics = res.body;
|
2021-05-28 11:10:24 +02:00
|
|
|
expect(metrics.applications.length === 1).toBe(true);
|
|
|
|
expect(metrics.applications[0].appName === appName).toBe(true);
|
2018-01-17 15:31:53 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('should store application', () => {
|
|
|
|
expect.assertions(0);
|
2018-01-17 15:31:53 +01:00
|
|
|
const appName = '123!23';
|
|
|
|
|
|
|
|
return request
|
|
|
|
.post(`/api/admin/metrics/applications/${appName}`)
|
2018-12-19 10:36:56 +01:00
|
|
|
.send({ appName, strategies: ['default'] })
|
2018-01-17 15:31:53 +01:00
|
|
|
.expect(202);
|
|
|
|
});
|
2019-05-10 13:47:56 +02:00
|
|
|
|
2022-06-21 09:12:40 +02:00
|
|
|
test('should store application details without strategies', () => {
|
2021-05-28 11:10:24 +02:00
|
|
|
expect.assertions(0);
|
2019-05-10 13:47:56 +02:00
|
|
|
const appName = '123!23';
|
|
|
|
|
|
|
|
return request
|
|
|
|
.post(`/api/admin/metrics/applications/${appName}`)
|
|
|
|
.send({ appName, url: 'htto://asd.com' })
|
|
|
|
.expect(202);
|
|
|
|
});
|
2020-09-25 09:39:12 +02:00
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('should accept a delete call to unknown application', () => {
|
|
|
|
expect.assertions(0);
|
2020-09-25 09:39:12 +02:00
|
|
|
const appName = 'unknown';
|
|
|
|
|
|
|
|
return request
|
|
|
|
.delete(`/api/admin/metrics/applications/${appName}`)
|
2021-01-18 12:32:19 +01:00
|
|
|
.expect(200);
|
2020-09-25 09:39:12 +02:00
|
|
|
});
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('should delete application', () => {
|
|
|
|
expect.assertions(0);
|
2020-09-25 09:39:12 +02:00
|
|
|
const appName = 'deletable-test';
|
|
|
|
|
|
|
|
stores.clientApplicationsStore.upsert({ appName });
|
|
|
|
|
|
|
|
return request
|
|
|
|
.delete(`/api/admin/metrics/applications/${appName}`)
|
|
|
|
.expect(200);
|
|
|
|
});
|