32 lines
1.7 KiB
TypeScript
32 lines
1.7 KiB
TypeScript
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 });
|
|
});
|
|
});
|