diff --git a/src/app.controller.spec.ts b/src/app.controller.spec.ts index cf1e530..2df6877 100644 --- a/src/app.controller.spec.ts +++ b/src/app.controller.spec.ts @@ -5,23 +5,27 @@ 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], + providers: [AppService, SkillsService, ExperiencesService, EducationService], }).compile(); appController = app.get(AppController); appService = app.get(AppService); skillsService = app.get(SkillsService); experiencesService = app.get(ExperiencesService); + educationService = app.get(EducationService); }); describe("root", () => { @@ -71,4 +75,25 @@ describe("AppController", () => { 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(); + }); + }); }); diff --git a/src/education/education.service.spec.ts b/src/education/education.service.spec.ts index 1d06d4f..499545c 100644 --- a/src/education/education.service.spec.ts +++ b/src/education/education.service.spec.ts @@ -1,5 +1,6 @@ import { Test, TestingModule } from "@nestjs/testing"; -import { EducationService } from "src/education/education.service"; +import { EducationService } from "@/education/education.service"; +import { education } from "@/education/education"; describe("SkillsService", () => { let service: EducationService; @@ -9,6 +10,30 @@ describe("SkillsService", () => { providers: [EducationService], }).compile(); + education.splice(0); + + education.push({ + institute: "Oxford University", + city: "Oxford", + url: "https://www.ox.ac.uk/", + course: "English", + level: "Masters", + startDate: new Date(2023, 0), + endDate: new Date(2023, 1), + description: "Got my english degree", + }); + + education.push({ + 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", + }); + service = module.get(EducationService); }); @@ -21,12 +46,20 @@ describe("SkillsService", () => { expect(service.getMany).toBeDefined(); }); - it("should return an array", () => { - expect(Array.isArray(service.getMany())).toBe(true); + it("should return an array with 2 entries", () => { + const education = service.getMany(); + + expect(Array.isArray(education)).toBe(true); + expect(education.length).toBe(2); }); - it("should return an array", () => { - expect(Array.isArray(service.getMany())).toBe(true); + it("should return an array with 1 entry", () => { + const education = service.getMany({ + level: "PHD", + }); + + expect(Array.isArray(education)).toBe(true); + expect(education.length).toBe(1); }); }); }); diff --git a/src/experiences/experiences.service.spec.ts b/src/experiences/experiences.service.spec.ts index dfa9b76..5b82972 100644 --- a/src/experiences/experiences.service.spec.ts +++ b/src/experiences/experiences.service.spec.ts @@ -1,6 +1,8 @@ import { Test, TestingModule } from "@nestjs/testing"; import { ExperiencesService } from "./experiences.service"; import { SkillsService } from "@/skills/skills.service"; +import { experiences } from "@/experiences/experiences"; +import { skills } from "@/skills/skills"; describe("ExperiencesService", () => { let service: ExperiencesService; @@ -10,10 +12,77 @@ describe("ExperiencesService", () => { providers: [ExperiencesService, SkillsService], }).compile(); + experiences.splice(0); + + experiences.push({ + name: "Employer A", + city: "City A", + url: "https://example.com/", + jobTitle: "Tester", + startDate: new Date(2023, 0), + endDate: new Date(2023, 1), + description: `Description of work`, + skills: [ + { + category: "Testing", + }, + ], + }); + experiences.push({ + name: "Employer B", + city: "City B", + url: "https://example.com/", + jobTitle: "Developer", + startDate: new Date(2023, 1), + endDate: new Date(2023, 2), + description: `Description of work`, + skills: [ + { + category: "Programming", + }, + ], + }); + + skills.splice(0); + skills.push({ + name: "Writing tests", + description: "Writing tests", + category: "Testing", + }); + skills.push({ + name: "TDD", + description: "Test Driven Development", + category: "Testing", + }); + skills.push({ + name: "OOP", + description: "Object Orientated Programming", + category: "Programming style", + }); + service = module.get(ExperiencesService); }); it("should be defined", () => { expect(service).toBeDefined(); }); + + describe("getMany method", () => { + it("should be defined", () => { + expect(service.getMany).toBeDefined(); + }); + it("should return an array", () => { + expect(Array.isArray(service.getMany())).toBe(true); + }); + + it("should return 2 entries", () => { + expect(service.getMany().length).toBe(2); + }); + + it("should return 1 entries with 2 skills", () => { + const experiences = service.getMany({ jobTitle: "Tester" }); + expect(experiences.length).toBe(1); + expect(experiences[0].skills.length).toBe(2); + }); + }); }); diff --git a/src/skills/skills.service.spec.ts b/src/skills/skills.service.spec.ts index 84d0adf..4649df3 100644 --- a/src/skills/skills.service.spec.ts +++ b/src/skills/skills.service.spec.ts @@ -1,5 +1,6 @@ import { Test, TestingModule } from "@nestjs/testing"; import { SkillsService } from "./skills.service"; +import { skills } from "@/skills/skills"; describe("SkillsService", () => { let service: SkillsService; @@ -9,6 +10,22 @@ describe("SkillsService", () => { providers: [SkillsService], }).compile(); + skills.splice(0); + skills.push({ + name: "Writing tests", + description: "Writing tests", + category: "Testing", + }); + skills.push({ + name: "TDD", + description: "Test Driven Development", + category: "Testing", + }); + skills.push({ + name: "OOP", + description: "Object Orientated Programming", + category: "Programming style", + }); service = module.get(SkillsService); }); @@ -20,13 +37,16 @@ describe("SkillsService", () => { it("should be defined", () => { expect(service.getMany).toBeDefined(); }); - it("should return an array", () => { expect(Array.isArray(service.getMany())).toBe(true); }); - it("should return an array", () => { - expect(Array.isArray(service.getMany())).toBe(true); + it("should return 3 entries", () => { + expect(service.getMany().length).toBe(3); + }); + + it("should return 2 entries", () => { + expect(service.getMany({ category: "Testing" }).length).toBe(2); }); }); });