import { describe, it, expect, beforeAll } from '@jest/globals';
import { EmailService, SMSService, PushService } from '@shieldai/shared-notifications';
describe('Notification Integration Tests', () => {
let emailService: EmailService;
let smsService: SMSService;
let pushService: PushService;
beforeAll(() => {
emailService = EmailService.getInstance();
smsService = SMSService.getInstance();
pushService = PushService.getInstance();
});
describe('Email Service', () => {
it('should validate email notification structure', () => {
const notification = {
channel: 'email' as const,
to: 'test@example.com',
subject: 'Test Subject',
htmlBody: '
Test
',
textBody: 'Test',
};
expect(notification.channel).toBe('email');
expect(notification.to).toMatch(/^[^\s@]+@[^\s@]+\.[^\s@]+$/);
expect(notification.subject).toBeTruthy();
expect(notification.htmlBody).toBeTruthy();
});
it('should handle rate limiting', async () => {
const rateLimit = emailService.getRateLimitStatus();
expect(rateLimit.limit).toBeGreaterThan(0);
expect(rateLimit.remaining).toBeLessThanOrEqual(rateLimit.limit);
});
});
describe('SMS Service', () => {
it('should validate SMS notification structure', () => {
const notification = {
channel: 'sms' as const,
to: '+1234567890',
body: 'Test message',
};
expect(notification.channel).toBe('sms');
expect(notification.to).toMatch(/^\+?\d{10,15}$/);
expect(notification.body).toBeTruthy();
});
it('should handle rate limiting', async () => {
const rateLimit = smsService.getRateLimitStatus();
expect(rateLimit.limit).toBeGreaterThan(0);
expect(rateLimit.remaining).toBeLessThanOrEqual(rateLimit.limit);
});
});
describe('Push Service', () => {
it('should validate push notification structure', () => {
const notification = {
channel: 'push' as const,
userId: 'user_123',
title: 'Test Title',
body: 'Test Body',
data: { key: 'value' },
};
expect(notification.channel).toBe('push');
expect(notification.userId).toBeTruthy();
expect(notification.title).toBeTruthy();
expect(notification.body).toBeTruthy();
});
it('should handle rate limiting', async () => {
const rateLimit = pushService.getRateLimitStatus();
expect(rateLimit.limit).toBeGreaterThan(0);
expect(rateLimit.remaining).toBeLessThanOrEqual(rateLimit.limit);
});
});
describe('Multi-Channel Notifications', () => {
it('should support different channels for same user', async () => {
const emailResult = await emailService.send({
channel: 'email' as const,
to: 'test@example.com',
subject: 'Alert',
htmlBody: 'Alert message
',
});
expect(emailResult.channel).toBe('email');
expect(emailResult.notificationId).toBeTruthy();
});
});
});