feat: stabilize social backend contracts
هذا الالتزام موجود في:
@@ -21,12 +21,16 @@ describe('FollowsService', () => {
|
||||
const outboxService = {
|
||||
enqueueFollowNotification: jest.fn().mockRejectedValue(new Error('socket down')),
|
||||
};
|
||||
const blocksRepository = {
|
||||
findAnyBetween: jest.fn().mockResolvedValue(null),
|
||||
};
|
||||
|
||||
const service = new FollowsService(
|
||||
followsRepository as any,
|
||||
usersRepository as any,
|
||||
outboxService as any,
|
||||
{ bumpGlobalVersion: jest.fn().mockResolvedValue(1) } as any,
|
||||
blocksRepository as any,
|
||||
);
|
||||
|
||||
await expect(service.toggleFollow(currentUserId, { targetUserId })).resolves.toEqual({
|
||||
@@ -40,4 +44,51 @@ describe('FollowsService', () => {
|
||||
'follow-1',
|
||||
);
|
||||
});
|
||||
|
||||
it('prevents users from following themselves', async () => {
|
||||
const userId = '507f1f77bcf86cd799439011';
|
||||
const service = new FollowsService(
|
||||
{} as any,
|
||||
{} as any,
|
||||
{} as any,
|
||||
{ bumpGlobalVersion: jest.fn() } as any,
|
||||
{ findAnyBetween: jest.fn() } as any,
|
||||
);
|
||||
|
||||
await expect(service.followUser(userId, userId)).rejects.toThrow('You cannot follow yourself');
|
||||
});
|
||||
|
||||
it('returns already-following response without creating duplicate notification', async () => {
|
||||
const currentUserId = '507f1f77bcf86cd799439011';
|
||||
const targetUserId = '507f191e810c19729de860ea';
|
||||
const followsRepository = {
|
||||
findOne: jest.fn().mockResolvedValue({ id: 'existing-follow' }),
|
||||
count: jest.fn().mockResolvedValueOnce(1).mockResolvedValueOnce(2),
|
||||
create: jest.fn(),
|
||||
};
|
||||
const usersRepository = {
|
||||
findById: jest.fn().mockResolvedValue({ id: targetUserId, isDisabled: false, isPrivate: false }),
|
||||
setFollowingCount: jest.fn(),
|
||||
setFollowersCount: jest.fn(),
|
||||
};
|
||||
const outboxService = {
|
||||
enqueueFollowNotification: jest.fn(),
|
||||
};
|
||||
const service = new FollowsService(
|
||||
followsRepository as any,
|
||||
usersRepository as any,
|
||||
outboxService as any,
|
||||
{ bumpGlobalVersion: jest.fn() } as any,
|
||||
{ findAnyBetween: jest.fn().mockResolvedValue(null) } as any,
|
||||
);
|
||||
|
||||
await expect(service.followUser(currentUserId, targetUserId)).resolves.toMatchObject({
|
||||
message: 'Already following user',
|
||||
isFollowing: true,
|
||||
followersCount: 2,
|
||||
followingCount: 1,
|
||||
});
|
||||
expect(followsRepository.create).not.toHaveBeenCalled();
|
||||
expect(outboxService.enqueueFollowNotification).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
المرجع في مشكلة جديدة
حظر مستخدم