first commit
هذا الالتزام موجود في:
44
src/modules/notifications/notifications.service.spec.ts
Normal file
44
src/modules/notifications/notifications.service.spec.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { NotFoundException } from '@nestjs/common';
|
||||
import { NotificationsService } from './notifications.service';
|
||||
|
||||
describe('NotificationsService', () => {
|
||||
it('recalculates unread count after markAllRead', async () => {
|
||||
const notificationsRepository = {
|
||||
markAllRead: jest.fn().mockResolvedValue(4),
|
||||
countUnread: jest.fn().mockResolvedValue(2),
|
||||
};
|
||||
const notificationsGateway = {
|
||||
emitUnreadCount: jest.fn(),
|
||||
};
|
||||
|
||||
const service = new NotificationsService(
|
||||
notificationsRepository as any,
|
||||
notificationsGateway as any,
|
||||
);
|
||||
|
||||
await expect(service.markAllRead('user-1')).resolves.toEqual({
|
||||
message: 'All notifications marked as read',
|
||||
updatedCount: 4,
|
||||
unreadCount: 2,
|
||||
});
|
||||
expect(notificationsGateway.emitUnreadCount).toHaveBeenCalledWith('user-1', 2);
|
||||
});
|
||||
|
||||
it('throws not found for invalid notification id in markRead', async () => {
|
||||
const notificationsRepository = {
|
||||
markRead: jest.fn(),
|
||||
countUnread: jest.fn(),
|
||||
};
|
||||
const notificationsGateway = {
|
||||
emitUnreadCount: jest.fn(),
|
||||
};
|
||||
|
||||
const service = new NotificationsService(
|
||||
notificationsRepository as any,
|
||||
notificationsGateway as any,
|
||||
);
|
||||
|
||||
await expect(service.markRead('user-1', 'invalid-id')).rejects.toBeInstanceOf(NotFoundException);
|
||||
expect(notificationsRepository.markRead).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
المرجع في مشكلة جديدة
حظر مستخدم