unleash-server
Version:
Unleash is an enterprise ready feature flag service. It provides different strategies for handling feature flags.
63 lines • 2.18 kB
JavaScript
import supertest from 'supertest';
import { createTestConfig } from '../../../test/config/test-config.js';
import createStores from '../../../test/fixtures/store.js';
import getApp from '../../app.js';
import { createServices } from '../../services/index.js';
import { DEFAULT_SEGMENT_VALUES_LIMIT, DEFAULT_STRATEGY_SEGMENTS_LIMIT, } from '../../util/segments.js';
const uiConfig = {
headerBackground: 'red',
slogan: 'hello',
};
async function getSetup() {
const base = `/random${Math.round(Math.random() * 1000)}`;
const config = createTestConfig({
server: { baseUriPath: base },
ui: uiConfig,
});
const stores = createStores();
const services = createServices(stores, config);
const app = await getApp(config, stores, services);
return {
base,
stores,
request: supertest(app),
};
}
let request;
let base;
let stores;
beforeEach(async () => {
const setup = await getSetup();
request = setup.request;
base = setup.base;
stores = setup.stores;
});
test('should get ui config', async () => {
const { body } = await request
.get(`${base}/api/admin/ui-config`)
.expect('Content-Type', /json/)
.expect(200);
expect(body.slogan).toEqual('hello');
expect(body.headerBackground).toEqual('red');
expect(body.resourceLimits.segmentValues).toEqual(DEFAULT_SEGMENT_VALUES_LIMIT);
expect(body.resourceLimits.strategySegments).toEqual(DEFAULT_STRATEGY_SEGMENTS_LIMIT);
});
test('should update CORS settings', async () => {
const { body } = await request
.get(`${base}/api/admin/ui-config`)
.expect('Content-Type', /json/)
.expect(200);
expect(body.frontendApiOrigins).toEqual(['*']);
await request
.post(`${base}/api/admin/ui-config/cors`)
.send({
frontendApiOrigins: ['https://example.com'],
})
.expect(204);
const { body: updatedBody } = await request
.get(`${base}/api/admin/ui-config`)
.expect('Content-Type', /json/)
.expect(200);
expect(updatedBody.frontendApiOrigins).toEqual(['https://example.com']);
});
//# sourceMappingURL=config.test.js.map