UNPKG

@ideal-photography/shared

Version:

Shared MongoDB and utility logic for Ideal Photography PWAs: users, products, services, bookings, orders/cart, galleries, reviews, notifications, campaigns, settings, audit logs, minimart items/orders, and push notification subscriptions.

36 lines (27 loc) 1.43 kB
import { jest } from '@jest/globals'; // Mock services before importing handlers const mockNotificationService = { createAndSend: jest.fn().mockResolvedValue({ _id: 'n1' }) }; const mockEmailService = { send: jest.fn().mockResolvedValue({ success: true }) }; jest.unstable_mockModule('../../services/NotificationService.js', () => ({ default: mockNotificationService })); jest.unstable_mockModule('../../services/EmailNotificationService.js', () => ({ default: mockEmailService })); // Register handlers (side-effect: subscribes to AlertBus) await import('../../alerts/handlers/index.js'); // Import SUT const { emitAlert } = await import('../../alerts/index.js'); describe('ErrorBoundary alert flow', () => { beforeEach(() => { jest.clearAllMocks(); }); it('persists notification and sends email on error trigger', async () => { emitAlert('error.boundary.triggered', { errorId: 'ERR_test', error: { message: 'Test error', stack: 'stack' }, componentStack: 'stack', context: { pwaType: 'client', url: 'https://example.com' } }); await new Promise((r) => setTimeout(r, 20)); expect(mockNotificationService.createAndSend).toHaveBeenCalledTimes(1); const meta = mockNotificationService.createAndSend.mock.calls[0][0]; expect(meta.channels?.email).toBe(true); }); });