Skip to content

Commit 91d7efa

Browse files
committed
test(e2e): verify uploaded timesheet integrity with sha256
1 parent 2ae7198 commit 91d7efa

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

test/e2e/timesheet-upload.spec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
import { test, expect } from "@playwright/test";
22
import { loginAs, openTimesheetUpload, readE2EState, uploadTimesheet } from "./helpers/agiladmin.js";
3+
import { createHash } from "node:crypto";
34
import fs from "node:fs/promises";
45
import os from "node:os";
56
import path from "node:path";
67

8+
async function sha256File(filePath) {
9+
const data = await fs.readFile(filePath);
10+
return createHash("sha256").update(data).digest("hex");
11+
}
12+
713
test("admin can login and upload a real timesheet", async ({ page }) => {
814
const state = await readE2EState();
915
await loginAs(page, "admin");
1016
await openTimesheetUpload(page);
1117
await uploadTimesheet(page, state.fixtures.admin);
1218

1319
await expect(page.getByText("Uploaded: 2016_timesheet_Luca-Pacioli.xlsx")).toBeVisible();
20+
const uploadedTempPath = await page.locator('input[name="tempfile"]').inputValue();
21+
await expect(uploadedTempPath).toBeTruthy();
22+
await expect(sha256File(uploadedTempPath)).resolves.toBe(await sha256File(state.fixtures.admin));
1423
await page.getByRole("button", { name: "Contents" }).click();
1524
await expect(page.getByText("Contents of the new timesheet")).toBeVisible();
1625
await expect(page.getByText("Error parsing timesheet")).toHaveCount(0);
@@ -23,6 +32,9 @@ test("manager can login and upload their own timesheet", async ({ page }) => {
2332
await uploadTimesheet(page, state.fixtures.manager);
2433

2534
await expect(page.getByText("Uploaded: 2016_timesheet_Manager.xlsx")).toBeVisible();
35+
const uploadedTempPath = await page.locator('input[name="tempfile"]').inputValue();
36+
await expect(uploadedTempPath).toBeTruthy();
37+
await expect(sha256File(uploadedTempPath)).resolves.toBe(await sha256File(state.fixtures.manager));
2638
await page.getByRole("button", { name: "Contents" }).click();
2739
await expect(page.getByText("Contents of the new timesheet")).toBeVisible();
2840
await expect(page.getByText("Error parsing timesheet")).toHaveCount(0);

0 commit comments

Comments
 (0)