feat: emit notification event on invite-link creation
This commit is contained in:
@@ -14,6 +14,7 @@ describe('AuthService inactive-user enforcement and safe logging', () => {
|
||||
let userRepository: any;
|
||||
let service: AuthService;
|
||||
let mailService: any;
|
||||
let eventEmitter: any;
|
||||
|
||||
beforeEach(() => {
|
||||
jwtService = {
|
||||
@@ -44,6 +45,7 @@ describe('AuthService inactive-user enforcement and safe logging', () => {
|
||||
dataSource = {
|
||||
transaction: jest.fn((work) => work(manager)),
|
||||
};
|
||||
eventEmitter = { emit: jest.fn() };
|
||||
service = new AuthService(
|
||||
jwtService,
|
||||
usersService,
|
||||
@@ -52,6 +54,7 @@ describe('AuthService inactive-user enforcement and safe logging', () => {
|
||||
logger,
|
||||
dataSource,
|
||||
{ assertAtLeast: jest.fn() } as any,
|
||||
eventEmitter as any,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -155,6 +158,19 @@ describe('AuthService inactive-user enforcement and safe logging', () => {
|
||||
expect(usersService.linkPlayerToUserId).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('emits an invite-link-created event after issuing the token', async () => {
|
||||
const token = await service.createTeamInvite(
|
||||
{ teamId: 10, teamName: 'Team A' } as any,
|
||||
5,
|
||||
);
|
||||
|
||||
expect(token.token).toBeDefined();
|
||||
expect(eventEmitter.emit).toHaveBeenCalledWith(
|
||||
'notifications.invite_link.created',
|
||||
expect.objectContaining({ teamId: 10, actorUserId: 5, teamName: 'Team A' }),
|
||||
);
|
||||
});
|
||||
|
||||
function user(statusId: StatusEnum) {
|
||||
return {
|
||||
id: 2,
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
UnauthorizedException,
|
||||
} from '@nestjs/common';
|
||||
import { JwtService } from '@nestjs/jwt';
|
||||
import { EventEmitter2 } from '@nestjs/event-emitter';
|
||||
import { User } from '../users/entities/user.entity';
|
||||
import * as bcrypt from 'bcryptjs';
|
||||
import { AuthEmailLoginDto } from './dto/auth-email-login.dto';
|
||||
@@ -27,6 +28,8 @@ import { LoggingService } from 'src/database/logging/logging.service';
|
||||
import { DataSource } from 'typeorm';
|
||||
import { TeamAccessService } from 'src/teams/team-access.service';
|
||||
import { TeamRolesEnum } from 'src/team-roles/team-roles.enum';
|
||||
import { NOTIFICATION_EVENT_NAME } from 'src/notifications/events/notification-event-names';
|
||||
import { InviteLinkCreatedEvent } from 'src/notifications/events/invite-link-created.event';
|
||||
|
||||
@Injectable()
|
||||
export class AuthService {
|
||||
@@ -38,6 +41,7 @@ export class AuthService {
|
||||
private logger: LoggingService,
|
||||
private dataSource: DataSource,
|
||||
private teamAccess: TeamAccessService,
|
||||
private eventEmitter: EventEmitter2,
|
||||
) {}
|
||||
|
||||
async validateLogin(
|
||||
@@ -323,6 +327,11 @@ export class AuthService {
|
||||
userId: 0,
|
||||
});
|
||||
|
||||
this.eventEmitter.emit(
|
||||
NOTIFICATION_EVENT_NAME.inviteLinkCreated,
|
||||
new InviteLinkCreatedEvent(object.teamId, actorUserId, object.teamName),
|
||||
);
|
||||
|
||||
return { token };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user