Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
anki247 committed Oct 11, 2023
1 parent 3f9ec6f commit 24a4ea3
Showing 1 changed file with 111 additions and 6 deletions.
117 changes: 111 additions & 6 deletions src/clockodo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,46 @@ describe("Clockodo (instance)", () => {
});
});

describe("getLumpSumService()", () => {
it("correctly builds getLumpSumService() request", async () => {
const nockScope = nock(CLOCKODO_API)
.get("/v2/lumpsumservices/777")
.reply(200, {});

await clockodo.getLumpSumService({ id: 777 });

nockScope.done();
});
});

describe("getLumpSumServicesPage()", () => {
it("correctly builds getLumpSumServicesPage() request", async () => {
const nockScope = nock(CLOCKODO_API)
.get("/v2/lumpsumservices")
.reply(200, {});

await clockodo.getLumpSumServicesPage();

nockScope.done();
});
});

describe("getLumpSumServices()", () => {
it("requests all lumpSumService pages", async () => {
const nockScope = setupPaginatedApiMock({
baseUrl: "/v2/lumpsumservices?",
countPages: 3,
createPageResponse: (page) => ({ lumpSumServices: [page] }),
});

const { lumpSumServices } = await clockodo.getLumpSumServices();

expect(lumpSumServices).toMatchObject([1, 2, 3]);

nockScope.done();
});
});

describe("getEntry()", () => {
it("correctly builds getEntry() request", async () => {
const nockScope = nock(CLOCKODO_API)
Expand Down Expand Up @@ -413,11 +453,27 @@ describe("Clockodo (instance)", () => {
});
});

describe("getServicesPage()", () => {
it("correctly builds getServicesPage() request", async () => {
const nockScope = nock(CLOCKODO_API).get("/v2/services").reply(200, {});

await clockodo.getServicesPage();

nockScope.done();
});
});

describe("getServices()", () => {
it("correctly builds getServices() request", async () => {
const nockScope = nock(CLOCKODO_API).get("/services").reply(200, {});
it("requests all getServices pages", async () => {
const nockScope = setupPaginatedApiMock({
baseUrl: "/v2/services?",
countPages: 3,
createPageResponse: (page) => ({ services: [page] }),
});

await clockodo.getServices();
const { services } = await clockodo.getServices();

expect(services).toMatchObject([1, 2, 3]);

nockScope.done();
});
Expand Down Expand Up @@ -649,6 +705,26 @@ describe("Clockodo (instance)", () => {
});
});

describe("addLumpsumService()", () => {
it("correctly builds addLumpsumService() request", async () => {
const expectedParameters = {
name: "Weyland-Yutani",
price: 1,
};

const nockScope = nock(CLOCKODO_API)
.post("/v2/lumpsumservices", expectedParameters)
.reply(200, {});

await clockodo.addLumpsumService({
name: "Weyland-Yutani",
price: 1,
});

nockScope.done();
});
});

describe("addProject()", () => {
it("correctly builds addProject() request", async () => {
const expectedParameters = {
Expand Down Expand Up @@ -679,7 +755,7 @@ describe("Clockodo (instance)", () => {
};

const nockScope = nock(CLOCKODO_API)
.post("/services", expectedParameters)
.post("/v2/services", expectedParameters)
.reply(200, {});

await clockodo.addService({ name: "Thinking", active: true });
Expand Down Expand Up @@ -923,6 +999,23 @@ describe("Clockodo (instance)", () => {
});
});

describe("editLumpsumService()", () => {
it("correctly builds editLumpsumService() request", async () => {
const lumpsumService = {
id: 15,
name: "Mystery Gang",
};

const nockScope = nock(CLOCKODO_API)
.put("/v2/lumpsumservices/15", mapRequestBody(lumpsumService))
.reply(200, {});

await clockodo.editLumpsumService(lumpsumService);

nockScope.done();
});
});

describe("editProject()", () => {
it("correctly builds editProject() request", async () => {
const project = {
Expand All @@ -949,7 +1042,7 @@ describe("Clockodo (instance)", () => {
};

const nockScope = nock(CLOCKODO_API)
.put("/services/23", mapRequestBody(service))
.put("/v2/services/23", mapRequestBody(service))
.reply(200, {});

await clockodo.editService(service);
Expand Down Expand Up @@ -1079,7 +1172,7 @@ describe("Clockodo (instance)", () => {
describe("deleteService()", () => {
it("correctly builds deleteService() request", async () => {
const nockScope = nock(CLOCKODO_API)
.delete("/services/94")
.delete("/v2/services/94")
.reply(200, {});

await clockodo.deleteService({ id: 94 });
Expand All @@ -1088,6 +1181,18 @@ describe("Clockodo (instance)", () => {
});
});

describe("deleteLumpsumService()", () => {
it("correctly builds deleteLumpsumService() request", async () => {
const nockScope = nock(CLOCKODO_API)
.delete("/v2/lumpsumservices/94")
.reply(200, {});

await clockodo.deleteLumpsumService({ id: 94 });

nockScope.done();
});
});

describe("deactivateUser()", () => {
it("correctly builds deactivateUser() request", async () => {
const nockScope = nock(CLOCKODO_API).delete("/users/7").reply(200, {});
Expand Down

0 comments on commit 24a4ea3

Please sign in to comment.