feat: stabilize social backend contracts
هذا الالتزام موجود في:
@@ -47,6 +47,7 @@ describe('NotificationsService', () => {
|
||||
|
||||
await expect(service.markAllRead('user-1')).resolves.toEqual({
|
||||
message: 'All notifications marked as read',
|
||||
modifiedCount: 4,
|
||||
updatedCount: 4,
|
||||
unreadCount: 2,
|
||||
});
|
||||
@@ -70,4 +71,68 @@ describe('NotificationsService', () => {
|
||||
await expect(service.markRead('user-1', 'invalid-id')).rejects.toBeInstanceOf(NotFoundException);
|
||||
expect(notificationsRepository.markRead).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('returns total unread count for the current user in the notifications list', async () => {
|
||||
const notificationsRepository = {
|
||||
findMine: jest.fn().mockResolvedValue([{ id: 'notification-1' }]),
|
||||
countMine: jest.fn().mockResolvedValue(30),
|
||||
countUnread: jest.fn().mockResolvedValue(7),
|
||||
};
|
||||
const notificationsGateway = {
|
||||
emitUnreadCount: jest.fn(),
|
||||
};
|
||||
|
||||
const service = new NotificationsService(
|
||||
notificationsRepository as any,
|
||||
notificationsGateway as any,
|
||||
);
|
||||
|
||||
await expect(
|
||||
service.getMine('507f1f77bcf86cd799439011', {
|
||||
page: 1,
|
||||
limit: 20,
|
||||
sortOrder: 'desc' as any,
|
||||
}),
|
||||
).resolves.toMatchObject({
|
||||
count: 1,
|
||||
page: 1,
|
||||
limit: 20,
|
||||
total: 30,
|
||||
unreadCount: 7,
|
||||
pagination: {
|
||||
mode: 'offset',
|
||||
hasNextPage: true,
|
||||
},
|
||||
});
|
||||
expect(notificationsRepository.countUnread).toHaveBeenCalledWith('507f1f77bcf86cd799439011');
|
||||
});
|
||||
|
||||
it('creates system notifications with system resource mapping when requested', async () => {
|
||||
const notificationsRepository = {
|
||||
create: jest.fn().mockResolvedValue({ toJSON: () => ({ _id: 'notification-1' }) }),
|
||||
countUnread: jest.fn().mockResolvedValue(1),
|
||||
};
|
||||
const notificationsGateway = {
|
||||
emitCreated: jest.fn(),
|
||||
};
|
||||
|
||||
const service = new NotificationsService(
|
||||
notificationsRepository as any,
|
||||
notificationsGateway as any,
|
||||
);
|
||||
|
||||
await service.create({
|
||||
actorId: '507f1f77bcf86cd799439011',
|
||||
recipientId: '507f191e810c19729de860ea',
|
||||
type: 'system',
|
||||
});
|
||||
|
||||
expect(notificationsRepository.create).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
type: 'system',
|
||||
resourceType: 'system',
|
||||
deepLink: '',
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
المرجع في مشكلة جديدة
حظر مستخدم