CV/src/app.controller.spec.ts
2023-10-22 15:51:50 +02:00

99 lines
3.8 KiB
TypeScript

import { Test, TestingModule } from "@nestjs/testing";
import { AppController } from "@/app.controller";
import { AppService } from "@/app.service";
import { SkillsService } from "@/skills/skills.service";
import { ExperiencesService } from "@/experiences/experiences.service";
import { SkillDto } from "@/skills/skills.types";
import { ExperienceDto } from "@/experiences/experiences.types";
import { EducationService } from "@/education/education.service";
import { EducationDto } from "@/education/education.types";
describe("AppController", () => {
let appController: AppController;
let appService: AppService;
let skillsService: SkillsService;
let experiencesService: ExperiencesService;
let educationService: EducationService;
beforeEach(async () => {
const app: TestingModule = await Test.createTestingModule({
controllers: [AppController],
providers: [AppService, SkillsService, ExperiencesService, EducationService],
}).compile();
appController = app.get<AppController>(AppController);
appService = app.get<AppService>(AppService);
skillsService = app.get<SkillsService>(SkillsService);
experiencesService = app.get<ExperiencesService>(ExperiencesService);
educationService = app.get<EducationService>(EducationService);
});
describe("root", () => {
it("Should call AppService", () => {
jest.spyOn(appService, "sayHello").mockImplementation(() => "Hello World!");
appController.sayHello();
expect(appService.sayHello).toBeCalled();
});
it('should return "Hello World!"', () => {
expect(appController.sayHello()).toBe("Hello World!");
});
});
describe("getSkills", () => {
it("Should return an Array of SkillDtos", () => {
const result: SkillDto[] = SkillDto.asDto([
{
name: "skillName",
category: "skillCategory",
description: "skillDescription",
},
]);
jest.spyOn(skillsService, "getMany").mockImplementation(() => result);
expect(appController.getSkills()).toBe(result);
expect(skillsService.getMany).toBeCalled();
});
});
describe("getExperience", () => {
it("Should return an Array of ExperienceDtos", () => {
const result: ExperienceDto[] = ExperienceDto.asDto([
{
name: "experienceName",
city: "experienceCity",
jobTitle: "experienceJobTitle",
startDate: new Date(),
endDate: new Date(),
description: "experienceDescription",
skills: [],
},
]);
jest.spyOn(experiencesService, "getMany").mockImplementation(() => result);
expect(appController.getExperiences()).toBe(result);
expect(experiencesService.getMany).toBeCalled();
});
});
describe("getEducation", () => {
it("Should return an Array of EducationDtos", () => {
const result: EducationDto[] = EducationDto.asDto([
{
institute: "Massachusetts Institute of Technology",
city: "Cambridge",
url: "https://www.mit.edu/",
course: "Neuroscience",
level: "PHD",
startDate: new Date(2023, 2),
endDate: new Date(2023, 3),
description: "Got my PHD in neuroscience",
},
]);
jest.spyOn(educationService, "getMany").mockImplementation(() => result);
expect(appController.getEducation()).toBe(result);
expect(educationService.getMany).toBeCalled();
});
});
});