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