2021-09-14 19:34:35 +02:00
|
|
|
import { EventEmitter } from 'events';
|
|
|
|
import { addEventHook } from './event-hook';
|
|
|
|
import {
|
2019-06-18 19:22:18 +02:00
|
|
|
FEATURE_CREATED,
|
|
|
|
FEATURE_UPDATED,
|
|
|
|
FEATURE_ARCHIVED,
|
|
|
|
FEATURE_REVIVED,
|
2021-09-14 19:34:35 +02:00
|
|
|
} from './types/events';
|
2019-06-18 19:22:18 +02:00
|
|
|
|
2021-09-14 19:34:35 +02:00
|
|
|
const eventStore = new EventEmitter();
|
2019-06-18 19:22:18 +02:00
|
|
|
const o = {};
|
|
|
|
|
|
|
|
function testHook(feature, data) {
|
|
|
|
o[feature] = data;
|
|
|
|
}
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
beforeAll(() => {
|
2019-06-18 19:22:18 +02:00
|
|
|
addEventHook(testHook, eventStore);
|
|
|
|
});
|
|
|
|
|
|
|
|
[FEATURE_CREATED, FEATURE_UPDATED, FEATURE_ARCHIVED, FEATURE_REVIVED].forEach(
|
2021-08-12 15:04:37 +02:00
|
|
|
(feature) => {
|
2021-05-28 11:10:24 +02:00
|
|
|
test(`should invoke hook on ${feature}`, () => {
|
2019-06-18 19:22:18 +02:00
|
|
|
const data = { dataKey: feature };
|
|
|
|
eventStore.emit(feature, data);
|
2021-05-28 11:10:24 +02:00
|
|
|
expect(o[feature] === data).toBe(true);
|
2019-06-18 19:22:18 +02:00
|
|
|
});
|
2020-04-14 22:29:11 +02:00
|
|
|
},
|
2019-06-18 19:22:18 +02:00
|
|
|
);
|