mirror of
https://github.com/Unleash/unleash.git
synced 2024-11-01 19:07:38 +01:00
ca01a79f71
## About the changes
Ref:
https://docs.getunleash.io/reference/deploy/configuring-unleash#further-customization
> **eventHook** (`function(event, data)`) - (_deprecated in Unleash 4.3_
in favor of the [Webhook addon](../addons/webhook.md)) If provided, this
function will be invoked whenever a feature is mutated. The possible
values for `event` are `'feature-created'`, `'feature-archived'` and
`'feature-revived'`. The `data` argument contains information about the
mutation. Its fields are `type` (string) - the event type (same as
`event`); `createdBy` (string) - the user who performed the mutation;
`data` - the contents of the change. The contents in `data` differs
based on the event type; For `'feature-archived'` and
`'feature-revived'`, the only field will be `name` - the name of the
feature. For `'feature-created'` the data follows a schema defined in
the code
[here](7b7f0b84e8/src/lib/schema/feature-schema.ts (L77)
).
See an [api here](/reference/api/legacy/unleash/admin/events).
Related to: https://github.com/Unleash/unleash/issues/1265
118 lines
2.7 KiB
TypeScript
118 lines
2.7 KiB
TypeScript
import express from 'express';
|
|
import { createTestConfig } from '../test/config/test-config';
|
|
import { start, create } from './server-impl';
|
|
import FakeEventStore from '../test/fixtures/fake-event-store';
|
|
|
|
jest.mock(
|
|
'./routes',
|
|
() =>
|
|
class Index {
|
|
router() {
|
|
return express.Router();
|
|
}
|
|
},
|
|
);
|
|
|
|
const noop = () => {};
|
|
|
|
const eventStore = new FakeEventStore();
|
|
const settingStore = {
|
|
get: () => {
|
|
Promise.resolve('secret');
|
|
},
|
|
};
|
|
|
|
jest.mock('./metrics', () => ({
|
|
createMetricsMonitor() {
|
|
return {
|
|
startMonitoring: noop,
|
|
stopMonitoring: noop,
|
|
};
|
|
},
|
|
}));
|
|
|
|
jest.mock('./db', () => ({
|
|
createStores() {
|
|
return {
|
|
db: {
|
|
destroy: () => undefined,
|
|
},
|
|
clientInstanceStore: {
|
|
destroy: noop,
|
|
removeInstancesOlderThanTwoDays: noop,
|
|
},
|
|
clientMetricsStore: { destroy: noop, on: noop },
|
|
eventStore,
|
|
publicSignupTokenStore: { destroy: noop, on: noop },
|
|
settingStore,
|
|
projectStore: { getAll: () => Promise.resolve([]) },
|
|
};
|
|
},
|
|
}));
|
|
|
|
jest.mock('../migrator', () => ({
|
|
migrateDb: () => Promise.resolve(),
|
|
}));
|
|
|
|
jest.mock('./util/db-lock', () => ({
|
|
withDbLock: () => (fn) => fn,
|
|
}));
|
|
|
|
jest.mock(
|
|
'./util/version',
|
|
() =>
|
|
function () {
|
|
return 'unleash-test-version';
|
|
},
|
|
);
|
|
|
|
test('should call preHook', async () => {
|
|
let called = 0;
|
|
const config = createTestConfig({
|
|
server: { port: 0 },
|
|
preHook: () => {
|
|
called++;
|
|
},
|
|
});
|
|
const { stop } = await start(config);
|
|
expect(called).toBe(1);
|
|
await stop();
|
|
});
|
|
|
|
test('should call preRouterHook', async () => {
|
|
let called = 0;
|
|
const { stop } = await start(
|
|
createTestConfig({
|
|
server: { port: 0 },
|
|
preRouterHook: () => {
|
|
called++;
|
|
},
|
|
}),
|
|
);
|
|
expect(called === 1).toBe(true);
|
|
await stop();
|
|
});
|
|
|
|
test('should auto-create server on start()', async () => {
|
|
const { server, stop } = await start(
|
|
createTestConfig({ server: { port: 0 } }),
|
|
);
|
|
expect(typeof server === 'undefined').toBe(false);
|
|
await stop();
|
|
});
|
|
|
|
test('should not create a server using create()', async () => {
|
|
const config = createTestConfig({ server: { port: 0 } });
|
|
const { server, stop } = await create(config);
|
|
expect(server).toBeUndefined();
|
|
await stop();
|
|
});
|
|
|
|
test('should shutdown the server when calling stop()', async () => {
|
|
const { server, stop } = await start(
|
|
createTestConfig({ server: { port: 0 } }),
|
|
);
|
|
await stop();
|
|
expect(server!.address()).toBe(null);
|
|
});
|