Skip to content

Commit 068fedd

Browse files
committed
Merge branch 'alerting_v2_event_bus' into alerting-v2-workflow-trigger-assign-episode
2 parents 28a9188 + 0f8e5c0 commit 068fedd

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

  • x-pack/platform/plugins/shared/alerting_v2/server/lib/events/event_bus

x-pack/platform/plugins/shared/alerting_v2/server/lib/events/event_bus/event_bus.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ describe('AsyncDomainEventBus', () => {
5151
});
5252

5353
describe('publish / subscribe', () => {
54+
const reservedTypes = ['error', 'newListener', 'removeListener'] as const;
55+
5456
it('invokes the subscribed handler when a matching event is published', async () => {
5557
const handler = jest.fn();
5658
bus.subscribe<FooEvent>('foo', handler);
@@ -140,6 +142,21 @@ describe('AsyncDomainEventBus', () => {
140142
expect(barHandler).toHaveBeenCalledTimes(1);
141143
expect(barHandler).toHaveBeenCalledWith(bar);
142144
});
145+
146+
it.each(reservedTypes)(
147+
'refuses to publish events typed "%s", logs a single warn, and does not dispatch to handlers',
148+
async (reservedType) => {
149+
const handler = jest.fn();
150+
bus.subscribe(reservedType, handler);
151+
// @ts-expect-error: we're testing the reserved type
152+
bus.publish({ type: reservedType });
153+
154+
await flushAsync();
155+
156+
expect(handler).not.toHaveBeenCalled();
157+
expect(mockLogger.warn).toHaveBeenCalledTimes(1);
158+
}
159+
);
143160
});
144161

145162
describe('error isolation', () => {

0 commit comments

Comments
 (0)