unleash-server
Version:
Unleash is an enterprise ready feature flag service. It provides different strategies for handling feature flags.
91 lines • 2.59 kB
JavaScript
import { createTestConfig } from '../test/config/test-config.js';
import { create, start, } from './server-impl.js';
import { vi } from 'vitest';
const mockFactories = () => ({
createDb: vi.fn().mockReturnValue({
destroy: vi.fn(),
}),
createStores: vi
.fn()
.mockReturnValue({
settingStore: {
get: vi.fn(),
postgresVersion: vi.fn(),
},
eventStore: {
on: vi.fn(),
},
}),
createServices: vi
.fn()
.mockReturnValue({
userService: {
initAdminUser: vi.fn(),
},
schedulerService: {
schedule: vi.fn(),
stop: vi.fn(),
},
addonService: {
destroy: vi.fn(),
},
openApiService: {
// returns a middleware
validPath: vi.fn().mockReturnValue(() => { }),
},
}),
createSessionDb: vi.fn(),
createMetricsMonitor: vi.fn().mockReturnValue({
startMonitoring: vi.fn(),
}),
});
const configWithoutMigrations = (opts) => {
const config = createTestConfig({
server: { port: 0 },
...opts,
});
config.db = {
...config.db,
disableMigration: true,
};
config.enableOAS = false;
return config;
};
test('should call preHook', async () => {
let called = 0;
const config = configWithoutMigrations({
preHook: () => {
called++;
},
});
const { stop } = await start(config, mockFactories());
expect(called).toBe(1);
await stop();
});
test('should call preRouterHook', async () => {
let called = 0;
const { stop } = await start(configWithoutMigrations({
preRouterHook: () => {
called++;
},
}), mockFactories());
expect(called === 1).toBe(true);
await stop();
});
test('should auto-create server on start()', async () => {
const { server, stop } = await start(configWithoutMigrations(), mockFactories());
expect(typeof server === 'undefined').toBe(false);
await stop();
});
test('should not create a server using create()', async () => {
const config = configWithoutMigrations();
const { server, stop } = await create(config, mockFactories());
expect(server).toBeUndefined();
await stop();
});
test('should shutdown the server when calling stop()', async () => {
const { server, stop } = await start(configWithoutMigrations(), mockFactories());
await stop();
expect(server?.address()).toBe(null);
});
//# sourceMappingURL=server-impl.test.js.map