From c6157f13088f2d89e89213e25ef3963e593b0f4d Mon Sep 17 00:00:00 2001 From: Dominik Sumer Date: Tue, 17 Oct 2023 13:47:47 +0200 Subject: [PATCH] added mock creation method and tests --- src/clockodo.test.ts | 73 +++++++++++++++++++++++++++++++++++ src/mocks.ts | 1 + src/models/surcharge.mocks.ts | 17 ++++++++ src/models/surcharge.ts | 3 +- 4 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 src/models/surcharge.mocks.ts diff --git a/src/clockodo.test.ts b/src/clockodo.test.ts index 6ea23587..ad37e5b3 100644 --- a/src/clockodo.test.ts +++ b/src/clockodo.test.ts @@ -592,6 +592,30 @@ describe("Clockodo (instance)", () => { nockScope.done(); }); }); + + describe("getSurcharge()", () => { + it("correctly builds getSurcharge() request", async () => { + const nockScope = nock(CLOCKODO_API) + .get("/v2/surcharges/7") + .reply(200, {}); + + await clockodo.getSurcharge({ id: 7 }); + + nockScope.done(); + }); + }); + + describe("getSurcharges()", () => { + it("correctly builds getSurcharges() request", async () => { + const nockScope = nock(CLOCKODO_API) + .get("/v2/surcharges") + .reply(200, {}); + + await clockodo.getSurcharges(); + + nockScope.done(); + }); + }); }); describe("POST", () => { @@ -871,6 +895,26 @@ describe("Clockodo (instance)", () => { nockScope.done(); }); }); + + describe("addSurcharge()", () => { + it("correctly builds addSurcharge() request", async () => { + const expectedParameters = { + name: "Weyland-Yutani", + accumulation: true, + }; + + const nockScope = nock(CLOCKODO_API) + .post("/v2/surcharges", expectedParameters) + .reply(200, {}); + + await clockodo.addSurcharge({ + name: "Weyland-Yutani", + accumulation: true, + }); + + nockScope.done(); + }); + }); }); describe("PUT", () => { @@ -1027,6 +1071,23 @@ describe("Clockodo (instance)", () => { nockScope.done(); }); }); + + describe("editSurcharge()", () => { + it("correctly builds editSurcharge() request", async () => { + const entry = { + id: 365, + name: "ABC", + }; + + const nockScope = nock(CLOCKODO_API) + .put("/v2/surcharges/365", mapRequestBody(entry)) + .reply(200, {}); + + await clockodo.editSurcharge(entry); + + nockScope.done(); + }); + }); }); describe("DELETE", () => { @@ -1153,6 +1214,18 @@ describe("Clockodo (instance)", () => { nockScope.done(); }); }); + + describe("deleteSurcharge()", () => { + it("correctly builds deleteSurcharge() request", async () => { + const nockScope = nock(CLOCKODO_API) + .delete("/v2/surcharges/31") + .reply(200, {}); + + await clockodo.deleteSurcharge({ id: 31 }); + + nockScope.done(); + }); + }); }); }); diff --git a/src/mocks.ts b/src/mocks.ts index c9b9646e..1496395a 100644 --- a/src/mocks.ts +++ b/src/mocks.ts @@ -10,6 +10,7 @@ export * from "./models/lumpsumService.mocks.js"; export * from "./models/nonbusinessDay.mocks.js"; export * from "./models/project.mocks.js"; // export * from "./models/service.mocks.js"; +export * from "./models/surcharge.mocks.js"; export * from "./models/targethours.mocks.js"; export * from "./models/user.mocks.js"; // export * from "./models/userReport.mocks.js"; diff --git a/src/models/surcharge.mocks.ts b/src/models/surcharge.mocks.ts new file mode 100644 index 00000000..25faa7be --- /dev/null +++ b/src/models/surcharge.mocks.ts @@ -0,0 +1,17 @@ +import { faker } from "@faker-js/faker"; +import { Surcharge } from "./surcharge.js"; + +export const createSurchargeMocks = ({ count = 1 }: { count?: number } = {}) => + Array.from({ length: count }, (_, index): Surcharge => { + return { + id: index, + name: faker.commerce.productName(), + accumulation: faker.datatype.boolean(), + night: null, + nightIncreased: null, + nonbusiness: null, + nonbusinessSpecial: null, + sunday: null, + saturday: null, + }; + }); diff --git a/src/models/surcharge.ts b/src/models/surcharge.ts index 959a7c2a..35e102ba 100644 --- a/src/models/surcharge.ts +++ b/src/models/surcharge.ts @@ -15,7 +15,7 @@ export type Surcharge = { /** Increased night surcharge configuration */ nightIncreased: NightSurchargeConfiguration | null; /** Nonbusiness surcharge configuration */ - nonbusiness: NightSurchargeConfiguration | null; + nonbusiness: SurchargeConfiguration | null; /** Nonbusiness surcharge configuration for special nonbusiness days */ nonbusinessSpecial: SurchargeConfiguration | null; /** Sunday surcharge configuration */ @@ -42,7 +42,6 @@ type NightSurchargeConfiguration = { export type SurchargeConfiguration = NightSurchargeConfiguration & { /** * Does the surcharge period start on the previous day? - * * Not for `night` and `nightIncreased`, as these surcharges apply every day */ timeSinceIsPreviousDay: boolean;