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 userRepository: any;
|
||||||
let service: AuthService;
|
let service: AuthService;
|
||||||
let mailService: any;
|
let mailService: any;
|
||||||
|
let eventEmitter: any;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jwtService = {
|
jwtService = {
|
||||||
@@ -44,6 +45,7 @@ describe('AuthService inactive-user enforcement and safe logging', () => {
|
|||||||
dataSource = {
|
dataSource = {
|
||||||
transaction: jest.fn((work) => work(manager)),
|
transaction: jest.fn((work) => work(manager)),
|
||||||
};
|
};
|
||||||
|
eventEmitter = { emit: jest.fn() };
|
||||||
service = new AuthService(
|
service = new AuthService(
|
||||||
jwtService,
|
jwtService,
|
||||||
usersService,
|
usersService,
|
||||||
@@ -52,6 +54,7 @@ describe('AuthService inactive-user enforcement and safe logging', () => {
|
|||||||
logger,
|
logger,
|
||||||
dataSource,
|
dataSource,
|
||||||
{ assertAtLeast: jest.fn() } as any,
|
{ 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();
|
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) {
|
function user(statusId: StatusEnum) {
|
||||||
return {
|
return {
|
||||||
id: 2,
|
id: 2,
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
UnauthorizedException,
|
UnauthorizedException,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { JwtService } from '@nestjs/jwt';
|
import { JwtService } from '@nestjs/jwt';
|
||||||
|
import { EventEmitter2 } from '@nestjs/event-emitter';
|
||||||
import { User } from '../users/entities/user.entity';
|
import { User } from '../users/entities/user.entity';
|
||||||
import * as bcrypt from 'bcryptjs';
|
import * as bcrypt from 'bcryptjs';
|
||||||
import { AuthEmailLoginDto } from './dto/auth-email-login.dto';
|
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 { DataSource } from 'typeorm';
|
||||||
import { TeamAccessService } from 'src/teams/team-access.service';
|
import { TeamAccessService } from 'src/teams/team-access.service';
|
||||||
import { TeamRolesEnum } from 'src/team-roles/team-roles.enum';
|
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()
|
@Injectable()
|
||||||
export class AuthService {
|
export class AuthService {
|
||||||
@@ -38,6 +41,7 @@ export class AuthService {
|
|||||||
private logger: LoggingService,
|
private logger: LoggingService,
|
||||||
private dataSource: DataSource,
|
private dataSource: DataSource,
|
||||||
private teamAccess: TeamAccessService,
|
private teamAccess: TeamAccessService,
|
||||||
|
private eventEmitter: EventEmitter2,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async validateLogin(
|
async validateLogin(
|
||||||
@@ -323,6 +327,11 @@ export class AuthService {
|
|||||||
userId: 0,
|
userId: 0,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.eventEmitter.emit(
|
||||||
|
NOTIFICATION_EVENT_NAME.inviteLinkCreated,
|
||||||
|
new InviteLinkCreatedEvent(object.teamId, actorUserId, object.teamName),
|
||||||
|
);
|
||||||
|
|
||||||
return { token };
|
return { token };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user