Skip to content

Commit

Permalink
added mock creation method and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dsumer committed Oct 17, 2023
1 parent bb625ca commit c6157f1
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 2 deletions.
73 changes: 73 additions & 0 deletions src/clockodo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down Expand Up @@ -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", () => {
Expand Down Expand Up @@ -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", () => {
Expand Down Expand Up @@ -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();
});
});
});
});

Expand Down
1 change: 1 addition & 0 deletions src/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
17 changes: 17 additions & 0 deletions src/models/surcharge.mocks.ts
Original file line number Diff line number Diff line change
@@ -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,
};
});
3 changes: 1 addition & 2 deletions src/models/surcharge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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;
Expand Down

0 comments on commit c6157f1

Please sign in to comment.