CV/src/app.controller.spec.ts
2023-10-26 22:07:17 +02:00

104 lines
4 KiB
TypeScript

import { Test, TestingModule } from "@nestjs/testing";
import { AppController } from "@/app.controller";
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";
import { IntroService } from "@/intro/intro.service";
import { IntroDto } from "@/intro/intro.types";
describe("AppController", () => {
let appController: AppController;
let skillsService: SkillsService;
let experiencesService: ExperiencesService;
let educationService: EducationService;
let introService: IntroService;
beforeEach(async () => {
const app: TestingModule = await Test.createTestingModule({
controllers: [AppController],
providers: [SkillsService, ExperiencesService, EducationService, IntroService],
}).compile();
appController = app.get<AppController>(AppController);
skillsService = app.get<SkillsService>(SkillsService);
experiencesService = app.get<ExperiencesService>(ExperiencesService);
educationService = app.get<EducationService>(EducationService);
introService = app.get<IntroService>(IntroService);
});
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();
});
});
describe("getIntros", () => {
it("Should return an Array of IntroDtos", () => {
const result: IntroDto[] = IntroDto.asDto([
{
name: "name",
value: "Bob Ross",
category: "Personal details",
},
]);
jest.spyOn(introService, "getMany").mockImplementation(() => result);
expect(appController.getIntros()).toBe(result);
expect(introService.getMany).toBeCalled();
});
});
});