Added tests for SkillsService

This commit is contained in:
Thom Werring 2023-10-21 14:04:55 +02:00
parent 92c3d833f9
commit d5132520cb

View file

@ -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', () => {
describe("AppController", () => {
let appController: AppController;
let appService: AppService;
let skillsService: SkillsService;
beforeEach(async () => {
const app: TestingModule = await Test.createTestingModule({
controllers: [AppController],
providers: [AppService],
providers: [AppService, SkillsService],
}).compile();
appController = app.get<AppController>(AppController);
appService = app.get<AppService>(AppService);
skillsService = app.get<SkillsService>(SkillsService);
});
describe('root', () => {
it('should return "Hello World!"', () => {
expect(appController.sayHello()).toBe('Hello World!');
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();
});
});
});
});