Skip to content

Commit

Permalink
Test booking is disabled on holidays
Browse files Browse the repository at this point in the history
  • Loading branch information
HendrikSchmidt committed Aug 28, 2024
1 parent b6347f2 commit b54af1b
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/apis/mocks/stubs/troi/billings_hours.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"CalculationPosition": {
"id": 7
},
"Date": "2024-08-03",
"Date": "will be replaced by one week ago",
"Quantity": 5,
"Remark": "Invoiced",
"IsBillable": true,
Expand Down
7 changes: 7 additions & 0 deletions app/apis/mocks/stubs/troi/calendarEvents.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,12 @@
"Subject": "Bezahlter Urlaub",
"Type": "P",
"id": "P5"
},
{
"Start": "will be replaced by two weeks ago",
"End": "will be replaced by two weeks ago",
"Subject": "Holiday",
"Type": "H",
"id": "11"
}
]
23 changes: 19 additions & 4 deletions app/apis/mocks/troiHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,23 @@ import md5 from "crypto-js/md5.js";
import { HttpResponse, delay, http } from "msw";
import type { ProjectTime } from "../troi/Troi.types";

const calendarEvents = require("./stubs/troi/calendarEvents.json");
// Replace holiday with two weeks ago
const holiday = calendarEvents.find(
(event: any) => event.Subject === "Holiday",
);
const holidayDate = new Date(Date.now() - 14 * 86400000)
.toISOString()
.split("T")[0];
holiday.Start = `${holidayDate} 00:00:00`;
holiday.End = `${holidayDate} 23:59:59`;

const projectTimes = require("./stubs/troi/billings_hours.json");
// Replace invoiced project time date with yesterday
const yesterday = new Date(Date.now() - 7 * 86400000)
// Replace invoiced project time date with one week ago
const oneWeekAgo = new Date(Date.now() - 7 * 86400000)
.toISOString()
.split("T")[0];
projectTimes.find((pt: any) => pt.Remark === "Invoiced").Date = yesterday;
projectTimes.find((pt: any) => pt.Remark === "Invoiced").Date = oneWeekAgo;

export const handlers = [
http.get(
Expand All @@ -31,7 +42,11 @@ export const handlers = [
),
http.get(
"https://digitalservice.troi.software/api/v2/rest/calendarEvents",
() => HttpResponse.json(require("./stubs/troi/calendarEvents.json")),
() => {
// Replace holiday with two weeks ago

return HttpResponse.json(calendarEvents);
},
),
http.get(
"https://digitalservice.troi.software/api/v2/rest/billings/hours",
Expand Down
13 changes: 13 additions & 0 deletions tests/e2e/projectHours.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,16 @@ test.describe("invoiced projects", () => {
await expect(projectLocator.getByRole("button")).not.toBeVisible();
});
});

test.describe("holidays", () => {
test("can't book on holidays", async ({ page }) => {
await new LoginPage(page).logIn("max.mustermann", "aSafePassword");
// date of holiday is replaced by two weeks ago in mock so we need to go back
await page.getByTestId("btn-previous-week").click();
await page.getByTestId("btn-previous-week").click();
await expect(page.getByTestId("week-view")).toContainText("holiday");
await expect(
page.locator("form").filter({ hasText: "2nd" }),
).not.toBeVisible();
});
});

0 comments on commit b54af1b

Please sign in to comment.