CV/src/app.controller.spec.ts
2023-10-21 14:07:03 +02:00

71 lines
2.7 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, ExperienceType } from "@/experiences/experiences.types";
describe("AppController", () => {
let appController: AppController;
let appService: AppService;
let skillsService: SkillsService;
let experiencesService: ExperiencesService;
beforeEach(async () => {
const app: TestingModule = await Test.createTestingModule({
controllers: [AppController],
providers: [AppService, SkillsService, ExperiencesService],
}).compile();
appController = app.get<AppController>(AppController);
appService = app.get<AppService>(AppService);
skillsService = app.get<SkillsService>(SkillsService);
experiencesService = app.get<ExperiencesService>(ExperiencesService);
});
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();
});
});
});