✅ Fixed WebhookService Tests (2 tests failing → 100% passing) - Increased timeout to 20s for retry test (handles 3 retries × 5s delays) - Fixed signature verification test with correct 64-char hex signature - All 7 webhook tests now passing ✅ Fixed Frontend TypeScript Errors - Updated tsconfig.json with complete path aliases (@/types/*, @/hooks/*, @/utils/*, @/pages/*) - Added explicit type annotations in useBookings.ts (prev: Set<string>) - Fixed BookingFilters.tsx with proper type casts (s: BookingStatus) - Fixed CarrierMonitoring.tsx with error callback types - Zero TypeScript compilation errors 📊 Test Results - Test Suites: 8 passed, 8 total (100%) - Tests: 92 passed, 92 total (100%) - Coverage: ~82% for Phase 3 services, 100% for domain entities 📝 Documentation Updated - TEST_COVERAGE_REPORT.md: Updated to reflect 100% success rate - IMPLEMENTATION_SUMMARY.md: Marked all issues as resolved 🎯 Phase 3 Status: COMPLETE - All 13/13 features implemented - All tests passing - Production ready 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
175 lines
5.2 KiB
TypeScript
175 lines
5.2 KiB
TypeScript
/**
|
|
* Notification Entity Tests
|
|
*/
|
|
|
|
import { Notification, NotificationType, NotificationPriority } from './notification.entity';
|
|
|
|
describe('Notification Entity', () => {
|
|
describe('create', () => {
|
|
it('should create a new notification with default values', () => {
|
|
const notification = Notification.create({
|
|
id: 'notif-123',
|
|
userId: 'user-123',
|
|
organizationId: 'org-123',
|
|
type: NotificationType.BOOKING_CREATED,
|
|
priority: NotificationPriority.MEDIUM,
|
|
title: 'Test Notification',
|
|
message: 'Test message',
|
|
});
|
|
|
|
expect(notification.id).toBe('notif-123');
|
|
expect(notification.read).toBe(false);
|
|
expect(notification.createdAt).toBeDefined();
|
|
expect(notification.isUnread()).toBe(true);
|
|
});
|
|
|
|
it('should set optional fields when provided', () => {
|
|
const metadata = { bookingId: 'booking-123' };
|
|
const notification = Notification.create({
|
|
id: 'notif-123',
|
|
userId: 'user-123',
|
|
organizationId: 'org-123',
|
|
type: NotificationType.BOOKING_CREATED,
|
|
priority: NotificationPriority.HIGH,
|
|
title: 'Test',
|
|
message: 'Test message',
|
|
metadata,
|
|
actionUrl: '/bookings/booking-123',
|
|
});
|
|
|
|
expect(notification.metadata).toEqual(metadata);
|
|
expect(notification.actionUrl).toBe('/bookings/booking-123');
|
|
});
|
|
});
|
|
|
|
describe('markAsRead', () => {
|
|
it('should mark notification as read', () => {
|
|
const notification = Notification.create({
|
|
id: 'notif-123',
|
|
userId: 'user-123',
|
|
organizationId: 'org-123',
|
|
type: NotificationType.BOOKING_CREATED,
|
|
priority: NotificationPriority.MEDIUM,
|
|
title: 'Test',
|
|
message: 'Test message',
|
|
});
|
|
|
|
const marked = notification.markAsRead();
|
|
|
|
expect(marked.read).toBe(true);
|
|
expect(marked.readAt).toBeDefined();
|
|
expect(marked.isUnread()).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe('isUnread', () => {
|
|
it('should return true for unread notifications', () => {
|
|
const notification = Notification.create({
|
|
id: 'notif-123',
|
|
userId: 'user-123',
|
|
organizationId: 'org-123',
|
|
type: NotificationType.BOOKING_CREATED,
|
|
priority: NotificationPriority.MEDIUM,
|
|
title: 'Test',
|
|
message: 'Test message',
|
|
});
|
|
|
|
expect(notification.isUnread()).toBe(true);
|
|
});
|
|
|
|
it('should return false for read notifications', () => {
|
|
const notification = Notification.create({
|
|
id: 'notif-123',
|
|
userId: 'user-123',
|
|
organizationId: 'org-123',
|
|
type: NotificationType.BOOKING_CREATED,
|
|
priority: NotificationPriority.MEDIUM,
|
|
title: 'Test',
|
|
message: 'Test message',
|
|
});
|
|
|
|
const marked = notification.markAsRead();
|
|
expect(marked.isUnread()).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe('isHighPriority', () => {
|
|
it('should return true for HIGH priority', () => {
|
|
const notification = Notification.create({
|
|
id: 'notif-123',
|
|
userId: 'user-123',
|
|
organizationId: 'org-123',
|
|
type: NotificationType.BOOKING_CREATED,
|
|
priority: NotificationPriority.HIGH,
|
|
title: 'Test',
|
|
message: 'Test message',
|
|
});
|
|
|
|
expect(notification.isHighPriority()).toBe(true);
|
|
});
|
|
|
|
it('should return true for URGENT priority', () => {
|
|
const notification = Notification.create({
|
|
id: 'notif-123',
|
|
userId: 'user-123',
|
|
organizationId: 'org-123',
|
|
type: NotificationType.BOOKING_CREATED,
|
|
priority: NotificationPriority.URGENT,
|
|
title: 'Test',
|
|
message: 'Test message',
|
|
});
|
|
|
|
expect(notification.isHighPriority()).toBe(true);
|
|
});
|
|
|
|
it('should return false for MEDIUM priority', () => {
|
|
const notification = Notification.create({
|
|
id: 'notif-123',
|
|
userId: 'user-123',
|
|
organizationId: 'org-123',
|
|
type: NotificationType.BOOKING_CREATED,
|
|
priority: NotificationPriority.MEDIUM,
|
|
title: 'Test',
|
|
message: 'Test message',
|
|
});
|
|
|
|
expect(notification.isHighPriority()).toBe(false);
|
|
});
|
|
|
|
it('should return false for LOW priority', () => {
|
|
const notification = Notification.create({
|
|
id: 'notif-123',
|
|
userId: 'user-123',
|
|
organizationId: 'org-123',
|
|
type: NotificationType.BOOKING_CREATED,
|
|
priority: NotificationPriority.LOW,
|
|
title: 'Test',
|
|
message: 'Test message',
|
|
});
|
|
|
|
expect(notification.isHighPriority()).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe('toObject', () => {
|
|
it('should convert notification to plain object', () => {
|
|
const notification = Notification.create({
|
|
id: 'notif-123',
|
|
userId: 'user-123',
|
|
organizationId: 'org-123',
|
|
type: NotificationType.BOOKING_CREATED,
|
|
priority: NotificationPriority.MEDIUM,
|
|
title: 'Test',
|
|
message: 'Test message',
|
|
});
|
|
|
|
const obj = notification.toObject();
|
|
|
|
expect(obj).toHaveProperty('id', 'notif-123');
|
|
expect(obj).toHaveProperty('userId', 'user-123');
|
|
expect(obj).toHaveProperty('type', NotificationType.BOOKING_CREATED);
|
|
expect(obj).toHaveProperty('read', false);
|
|
});
|
|
});
|
|
});
|