1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-18 20:09:08 +02:00
unleash.unleash/src/lib/routes/index.test.ts
2022-01-06 10:31:00 +01:00

88 lines
2.4 KiB
TypeScript

import supertest from 'supertest';
import { createTestConfig } from '../../test/config/test-config';
import createStores from '../../test/fixtures/store';
import getApp from '../app';
import { createServices } from '../services';
async function getSetup() {
const base = `/random${Math.round(Math.random() * 1000)}`;
const stores = createStores();
const config = createTestConfig({
server: { baseUriPath: base },
});
const services = createServices(stores, config);
const app = await getApp(config, stores, services);
return {
base,
request: supertest(app),
destroy: () => {
services.versionService.destroy();
services.clientInstanceService.destroy();
services.apiTokenService.destroy();
},
};
}
let base;
let request;
let destroy;
beforeEach(async () => {
const setup = await getSetup();
base = setup.base;
request = setup.request;
destroy = setup.destroy;
});
afterEach(() => {
destroy();
});
test('api definition', () => {
expect.assertions(5);
return request
.get(`${base}/api/`)
.expect('Content-Type', /json/)
.expect(200)
.expect((res) => {
expect(res.body).toBeTruthy();
const { admin, client } = res.body.links;
expect(admin.uri === '/api/admin').toBe(true);
expect(client.uri === '/api/client').toBe(true);
expect(
admin.links['feature-toggles'].uri === '/api/admin/features',
).toBe(true);
expect(client.links.metrics.uri === '/api/client/metrics').toBe(
true,
);
});
});
test('admin api defintion', () => {
expect.assertions(2);
return request
.get(`${base}/api/admin`)
.expect('Content-Type', /json/)
.expect(200)
.expect((res) => {
expect(res.body).toBeTruthy();
expect(
res.body.links['feature-toggles'].uri === '/api/admin/features',
).toBe(true);
});
});
test('client api defintion', () => {
expect.assertions(2);
return request
.get(`${base}/api/client`)
.expect('Content-Type', /json/)
.expect(200)
.expect((res) => {
expect(res.body).toBeTruthy();
expect(res.body.links.metrics.uri === '/api/client/metrics').toBe(
true,
);
});
});