diff --git a/cv/src/app.controller.spec.ts b/cv/src/app.controller.spec.ts index bc30a7a..d0dd8fd 100644 --- a/cv/src/app.controller.spec.ts +++ b/cv/src/app.controller.spec.ts @@ -1,22 +1,50 @@ import { Test, TestingModule } from "@nestjs/testing"; import { AppController } from "@/app.controller"; import { AppService } from "@/app.service"; +import { SkillsService } from "@/skills/skills.service"; +import { SkillDto } from "@/skills/skills.types"; -describe('AppController', () => { - let appController: AppController; +describe("AppController", () => { + let appController: AppController; + let appService: AppService; + let skillsService: SkillsService; - beforeEach(async () => { - const app: TestingModule = await Test.createTestingModule({ - controllers: [AppController], - providers: [AppService], - }).compile(); - appController = app.get(AppController); - }); + beforeEach(async () => { + const app: TestingModule = await Test.createTestingModule({ + controllers: [AppController], + providers: [AppService, SkillsService], + }).compile(); - describe('root', () => { - it('should return "Hello World!"', () => { - expect(appController.sayHello()).toBe('Hello World!'); + appController = app.get(AppController); + appService = app.get(AppService); + skillsService = app.get(SkillsService); + }); + + 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(); + }); + }); }); - }); });