Skip to content

Commit

Permalink
test(invite): add EntityManager mock
Browse files Browse the repository at this point in the history
  • Loading branch information
ztmbuilds committed Mar 1, 2025
1 parent 5874dc3 commit 8778574
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/modules/invite/tests/invite.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { HttpStatus, BadRequestException, NotFoundException, InternalServerErrorException } from '@nestjs/common';
import { Test, TestingModule } from '@nestjs/testing';
import { getRepositoryToken } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { Repository, EntityManager } from 'typeorm';
import { Organisation } from '../../organisations/entities/organisations.entity';
import { User } from '../../user/entities/user.entity';
import { Invite } from '../entities/invite.entity';
Expand Down Expand Up @@ -34,8 +34,14 @@ describe('InviteService', () => {
let organisationService: OrganisationsService;
let configService: ConfigService;
let frontendUrl: string;
let entityManager: jest.Mocked<EntityManager>;

beforeEach(async () => {
entityManager = {
transaction: jest.fn().mockImplementation(async cb => cb(entityManager)),
save: jest.fn(),
} as unknown as jest.Mocked<EntityManager>;

const module: TestingModule = await Test.createTestingModule({
imports: [ConfigModule.forRoot()],
providers: [
Expand Down Expand Up @@ -137,6 +143,10 @@ describe('InviteService', () => {
sendMail: jest.fn(),
},
},
{
provide: EntityManager,
useValue: entityManager,
},
],
}).compile();

Expand Down

0 comments on commit 8778574

Please sign in to comment.