-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
145 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { JobService } from "../services/job.service"; | ||
import { Repository } from "typeorm"; | ||
import { Job } from "../models/job"; | ||
import AppDataSource from "../data-source"; | ||
import { BadRequest } from "../middleware"; | ||
|
||
jest.mock("../data-source"); | ||
|
||
describe("JobService", () => { | ||
let jobService: JobService; | ||
let jobRepository: jest.Mocked<Repository<Job>>; | ||
|
||
beforeEach(() => { | ||
jobRepository = { | ||
findOne: jest.fn(), | ||
} as any; | ||
|
||
AppDataSource.getRepository = jest.fn().mockImplementation((model) => { | ||
if (model === Job) { | ||
return jobRepository; | ||
} | ||
throw new Error("Unknown model"); | ||
}); | ||
|
||
jobService = new JobService(); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
describe("getJobById", () => { | ||
it("should return job details for a valid ID", async () => { | ||
const jobId = "1"; | ||
const jobDetails = { | ||
id: jobId, | ||
title: "Software Engineer", | ||
description: "Job description here...", | ||
user_id: "21", | ||
location: "Remote", | ||
salary: "60000", | ||
job_type: "Developer", | ||
company_name: "Company Name", | ||
} as Job; | ||
|
||
jobRepository.findOne.mockResolvedValue(jobDetails); | ||
|
||
const result = await jobService.getById(jobId); | ||
|
||
expect(jobRepository.findOne).toHaveBeenCalledWith({ | ||
where: { id: jobId }, | ||
}); | ||
expect(result).toEqual(jobDetails); | ||
}); | ||
}); | ||
}); |