Skip to content

Commit

Permalink
mock service
Browse files Browse the repository at this point in the history
  • Loading branch information
whiitex committed Jan 14, 2024
1 parent c2d69bd commit 2c77714
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions api/src/recruitment-session/recruitment-session.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { mockRecruitmentSession, testDate } from '@mocks/data';
import { mockedRepository } from '@mocks/repositories';
import { TestingModule, Test } from '@nestjs/testing';
import { getRepositoryToken } from '@nestjs/typeorm';
import { RecruitmentSession } from './recruitment-session.entity';
import { RecruitmentSessionService } from './recruitment-session.service';

describe('Recruitment Session Service', () => {
let recruitmentSessionService: RecruitmentSessionService;

beforeAll(() => {
jest
.spyOn(global, 'Date')
.mockImplementation(() => testDate as unknown as string);
});

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [
RecruitmentSessionService,
{
provide: getRepositoryToken(RecruitmentSession),
useValue: mockedRepository,
},
],
}).compile();

recruitmentSessionService = module.get<RecruitmentSessionService>(
RecruitmentSessionService,
);
});

afterEach(() => jest.clearAllMocks());

it('should be defined', () => {
expect(recruitmentSessionService).toBeDefined();
});

describe('deleteRecruitmentSession', () => {
it('should remove the specified recruitment session from the database', () => {
jest
.spyOn(mockedRepository, 'remove')
.mockResolvedValue(mockRecruitmentSession);
const result = recruitmentSessionService.deletRecruitmentSession(
mockRecruitmentSession,
);
expect(result).toEqual([mockRecruitmentSession]);
expect(mockedRepository.find).toHaveBeenCalledTimes(1);
});
});
});

0 comments on commit 2c77714

Please sign in to comment.