test: assert recipient-filter query clauses in NotificationsService.create
This commit is contained in:
@@ -32,9 +32,8 @@ describe('NotificationsService', () => {
|
||||
|
||||
describe('create', () => {
|
||||
it('does nothing when the team has no other active members with a login', async () => {
|
||||
playerRepository.createQueryBuilder.mockReturnValue(
|
||||
chain({ getRawMany: jest.fn().mockResolvedValue([]) }),
|
||||
);
|
||||
const playerQuery = chain({ getRawMany: jest.fn().mockResolvedValue([]) });
|
||||
playerRepository.createQueryBuilder.mockReturnValue(playerQuery);
|
||||
|
||||
await service.create({
|
||||
teamId: 10,
|
||||
@@ -43,14 +42,18 @@ describe('NotificationsService', () => {
|
||||
payload: { playerId: 1, playerName: 'Ada Lovelace' },
|
||||
});
|
||||
|
||||
expect(playerQuery.where).toHaveBeenCalledWith('player.teamId = :teamId', { teamId: 10 });
|
||||
expect(playerQuery.andWhere).toHaveBeenCalledWith('player.active = :active', { active: true });
|
||||
expect(playerQuery.andWhere).toHaveBeenCalledWith('player.userId IS NOT NULL');
|
||||
expect(playerQuery.andWhere).toHaveBeenCalledWith('player.userId != :actorUserId', { actorUserId: 5 });
|
||||
|
||||
expect(notificationRepository.save).not.toHaveBeenCalled();
|
||||
expect(recipientRepository.insert).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('creates one notification and fans it out to every recipient', async () => {
|
||||
playerRepository.createQueryBuilder.mockReturnValue(
|
||||
chain({ getRawMany: jest.fn().mockResolvedValue([{ userId: 7 }, { userId: 8 }]) }),
|
||||
);
|
||||
const playerQuery = chain({ getRawMany: jest.fn().mockResolvedValue([{ userId: 7 }, { userId: 8 }]) });
|
||||
playerRepository.createQueryBuilder.mockReturnValue(playerQuery);
|
||||
notificationRepository.save.mockResolvedValue({ id: 99 });
|
||||
|
||||
await service.create({
|
||||
@@ -60,6 +63,11 @@ describe('NotificationsService', () => {
|
||||
payload: { playerId: 1, playerName: 'Ada Lovelace' },
|
||||
});
|
||||
|
||||
expect(playerQuery.where).toHaveBeenCalledWith('player.teamId = :teamId', { teamId: 10 });
|
||||
expect(playerQuery.andWhere).toHaveBeenCalledWith('player.active = :active', { active: true });
|
||||
expect(playerQuery.andWhere).toHaveBeenCalledWith('player.userId IS NOT NULL');
|
||||
expect(playerQuery.andWhere).toHaveBeenCalledWith('player.userId != :actorUserId', { actorUserId: 5 });
|
||||
|
||||
expect(notificationRepository.save).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
team: { id: 10 },
|
||||
|
||||
Reference in New Issue
Block a user