first commit
هذا الالتزام موجود في:
42
src/modules/follows/follows.service.spec.ts
Normal file
42
src/modules/follows/follows.service.spec.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { FollowsService } from './follows.service';
|
||||
|
||||
describe('FollowsService', () => {
|
||||
it('keeps follow successful even if notification creation fails and resyncs counters', async () => {
|
||||
const currentUserId = '507f1f77bcf86cd799439011';
|
||||
const targetUserId = '507f191e810c19729de860ea';
|
||||
|
||||
const followsRepository = {
|
||||
findOne: jest.fn().mockResolvedValue(null),
|
||||
create: jest.fn().mockResolvedValue({ id: 'follow-1' }),
|
||||
count: jest
|
||||
.fn()
|
||||
.mockResolvedValueOnce(6)
|
||||
.mockResolvedValueOnce(14),
|
||||
};
|
||||
const usersRepository = {
|
||||
findById: jest.fn().mockResolvedValue({ id: targetUserId }),
|
||||
setFollowingCount: jest.fn().mockResolvedValue(undefined),
|
||||
setFollowersCount: jest.fn().mockResolvedValue(undefined),
|
||||
};
|
||||
const outboxService = {
|
||||
enqueueFollowNotification: jest.fn().mockRejectedValue(new Error('socket down')),
|
||||
};
|
||||
|
||||
const service = new FollowsService(
|
||||
followsRepository as any,
|
||||
usersRepository as any,
|
||||
outboxService as any,
|
||||
);
|
||||
|
||||
await expect(service.toggleFollow(currentUserId, { targetUserId })).resolves.toEqual({
|
||||
following: true,
|
||||
});
|
||||
expect(usersRepository.setFollowingCount).toHaveBeenCalledWith(currentUserId, 6);
|
||||
expect(usersRepository.setFollowersCount).toHaveBeenCalledWith(targetUserId, 14);
|
||||
expect(outboxService.enqueueFollowNotification).toHaveBeenCalledWith(
|
||||
currentUserId,
|
||||
targetUserId,
|
||||
'follow-1',
|
||||
);
|
||||
});
|
||||
});
|
||||
المرجع في مشكلة جديدة
حظر مستخدم