feat(web): wire domain events into realtime stream
This commit is contained in:
1 parent
8c8ff11fd7
commit
d5f0175dc2
6 files changed
+155
-1
No files matched your search
@@ -0,0 +1,31 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import {
|
||||
reportDeliveryResult,
|
||||
reportInvitationCooldown,
|
||||
reportReply,
|
||||
} from '../../src/web/event-reporting.js';
|
||||
|
||||
describe('dashboard event reporting', () => {
|
||||
it('reports authoritative delivery success and failure', () => {
|
||||
const events = { messageSent: vi.fn(), messageFailed: vi.fn() };
|
||||
|
||||
reportDeliveryResult(events, { success: true, messageId: 'post-1', username: 'alice', conversationId: 'room-1' });
|
||||
reportDeliveryResult(events, { success: false, messageId: 'post-2', username: 'bob', error: 'Matrix rejected the message' });
|
||||
|
||||
expect(events.messageSent).toHaveBeenCalledWith({ id: 'post-1', username: 'alice', conversationId: 'room-1' });
|
||||
expect(events.messageFailed).toHaveBeenCalledWith({ messageId: 'post-2', username: 'bob', error: 'Matrix rejected the message' });
|
||||
});
|
||||
|
||||
it('reports replies and invitation cooldown state', () => {
|
||||
const events = { conversation: vi.fn(), reply: vi.fn(), rateLimit: vi.fn() };
|
||||
|
||||
reportReply(events, { conversationId: 'room-1', replyId: 'reply-1', username: 'alice', body: 'Hello there' });
|
||||
reportInvitationCooldown(events, { until: 10_000, reason: 'Reddit asked us to slow down' });
|
||||
reportInvitationCooldown(events, null);
|
||||
|
||||
expect(events.conversation).toHaveBeenCalledWith({ id: 'room-1', state: 'replied', unread: 1 });
|
||||
expect(events.reply).toHaveBeenCalledWith({ conversationId: 'room-1', id: 'reply-1', username: 'alice', body: 'Hello there' });
|
||||
expect(events.rateLimit).toHaveBeenNthCalledWith(1, { blocked: true, resetAt: 10_000, reason: 'Reddit asked us to slow down' });
|
||||
expect(events.rateLimit).toHaveBeenNthCalledWith(2, { blocked: false });
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user