diff --git a/api/src/recruitment-session/recruitment-session.service.spec.ts b/api/src/recruitment-session/recruitment-session.service.spec.ts new file mode 100644 index 0000000..f6657f3 --- /dev/null +++ b/api/src/recruitment-session/recruitment-session.service.spec.ts @@ -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, + ); + }); + + 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); + }); + }); +});