/** * 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); }); }); });