هذا الالتزام موجود في:
2026-04-20 15:12:16 +03:00
التزام 28f7241bcd
172 ملفات معدلة مع 21907 إضافات و0 حذوفات

عرض الملف

@@ -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();
});
});