Added extra tests
This commit is contained in:
parent
7aca1b737d
commit
6816187fee
4 changed files with 156 additions and 9 deletions
|
|
@ -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>(AppController);
|
||||
appService = app.get<AppService>(AppService);
|
||||
skillsService = app.get<SkillsService>(SkillsService);
|
||||
experiencesService = app.get<ExperiencesService>(ExperiencesService);
|
||||
educationService = app.get<EducationService>(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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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>(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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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>(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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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>(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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue