feat(gateway): enhance gateway readiness handling and batch sync configuration (#851)
Co-authored-by: paisley <8197966+su8su@users.noreply.github.com>
This commit is contained in:
51
tests/unit/gateway-event-dispatch.test.ts
Normal file
51
tests/unit/gateway-event-dispatch.test.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { dispatchProtocolEvent } from '@electron/gateway/event-dispatch';
|
||||
|
||||
function createMockEmitter() {
|
||||
const emitted: Array<{ event: string; payload: unknown }> = [];
|
||||
return {
|
||||
emit: vi.fn((event: string, payload: unknown) => {
|
||||
emitted.push({ event, payload });
|
||||
return true;
|
||||
}),
|
||||
emitted,
|
||||
};
|
||||
}
|
||||
|
||||
describe('dispatchProtocolEvent', () => {
|
||||
it('dispatches gateway.ready event to gateway:ready', () => {
|
||||
const emitter = createMockEmitter();
|
||||
dispatchProtocolEvent(emitter, 'gateway.ready', { version: '4.11' });
|
||||
expect(emitter.emit).toHaveBeenCalledWith('gateway:ready', { version: '4.11' });
|
||||
});
|
||||
|
||||
it('dispatches ready event to gateway:ready', () => {
|
||||
const emitter = createMockEmitter();
|
||||
dispatchProtocolEvent(emitter, 'ready', { skills: 31 });
|
||||
expect(emitter.emit).toHaveBeenCalledWith('gateway:ready', { skills: 31 });
|
||||
});
|
||||
|
||||
it('dispatches channel.status to channel:status', () => {
|
||||
const emitter = createMockEmitter();
|
||||
dispatchProtocolEvent(emitter, 'channel.status', { channelId: 'telegram', status: 'connected' });
|
||||
expect(emitter.emit).toHaveBeenCalledWith('channel:status', { channelId: 'telegram', status: 'connected' });
|
||||
});
|
||||
|
||||
it('dispatches chat to chat:message', () => {
|
||||
const emitter = createMockEmitter();
|
||||
dispatchProtocolEvent(emitter, 'chat', { text: 'hello' });
|
||||
expect(emitter.emit).toHaveBeenCalledWith('chat:message', { message: { text: 'hello' } });
|
||||
});
|
||||
|
||||
it('suppresses tick events', () => {
|
||||
const emitter = createMockEmitter();
|
||||
dispatchProtocolEvent(emitter, 'tick', {});
|
||||
expect(emitter.emit).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('dispatches unknown events as notifications', () => {
|
||||
const emitter = createMockEmitter();
|
||||
dispatchProtocolEvent(emitter, 'some.custom.event', { data: 1 });
|
||||
expect(emitter.emit).toHaveBeenCalledWith('notification', { method: 'some.custom.event', params: { data: 1 } });
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user