mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2026-10-03 18:23:47 +10:00
test: remove redundant cases and repeated setup
This commit is contained in:
@@ -2,7 +2,9 @@ import { readFile, writeFile } from "node:fs/promises";
|
||||
import { createSampleResumeFromDashboard, openDownloadDialog, openSidebarSection } from "../fixtures/resume";
|
||||
import { expect, test } from "../fixtures/test";
|
||||
|
||||
test("exports and imports a resume JSON backup", async ({ authPage: page }, testInfo) => {
|
||||
test("round-trips a JSON backup and splits a legacy embedded letter on import", async ({
|
||||
authPage: page,
|
||||
}, testInfo) => {
|
||||
await createSampleResumeFromDashboard(page, testInfo);
|
||||
|
||||
const sheet = await openDownloadDialog(page);
|
||||
@@ -14,7 +16,11 @@ test("exports and imports a resume JSON backup", async ({ authPage: page }, test
|
||||
|
||||
const downloadPath = testInfo.outputPath(download.suggestedFilename());
|
||||
await download.saveAs(downloadPath);
|
||||
const exportedData = JSON.parse(await readFile(downloadPath, "utf-8")) as { basics: { name: string } };
|
||||
const exportedData = JSON.parse(await readFile(downloadPath, "utf-8")) as {
|
||||
basics: { name: string };
|
||||
customSections: unknown[];
|
||||
metadata: { layout: { pages: { fullWidth: boolean; main: string[]; sidebar: string[] }[] } };
|
||||
};
|
||||
// A name only this file carries, so a builder that opens anything but the imported resume fails.
|
||||
exportedData.basics.name = `Imported ${Date.now()}`;
|
||||
await writeFile(downloadPath, JSON.stringify(exportedData));
|
||||
@@ -29,24 +35,9 @@ test("exports and imports a resume JSON backup", async ({ authPage: page }, test
|
||||
await page.waitForURL(/\/builder\/.+/);
|
||||
await openSidebarSection(page, "Basics");
|
||||
await expect(page.getByRole("textbox", { name: "Full name", exact: true })).toHaveValue(exportedData.basics.name);
|
||||
});
|
||||
|
||||
test("imports a resume file that carries a cover letter as a resume and a letter of its own", async ({
|
||||
authPage: page,
|
||||
}, testInfo) => {
|
||||
await createSampleResumeFromDashboard(page, testInfo);
|
||||
const sheet = await openDownloadDialog(page);
|
||||
await sheet.getByRole("radio", { name: /^JSON/ }).click();
|
||||
const downloadPromise = page.waitForEvent("download");
|
||||
await sheet.getByRole("button", { name: "Download JSON" }).click();
|
||||
const exported = await downloadPromise;
|
||||
const data = JSON.parse(await readFile((await exported.path()) as string, "utf-8")) as {
|
||||
customSections: unknown[];
|
||||
metadata: { layout: { pages: { fullWidth: boolean; main: string[]; sidebar: string[] }[] } };
|
||||
};
|
||||
|
||||
// A file from an older version, with the letter inside the resume.
|
||||
data.customSections.push({
|
||||
exportedData.customSections.push({
|
||||
id: "old-letter",
|
||||
type: "cover-letter",
|
||||
title: "Letter to Globex",
|
||||
@@ -57,9 +48,9 @@ test("imports a resume file that carries a cover letter as a resume and a letter
|
||||
startOnNewPage: false,
|
||||
items: [{ id: "old-letter-item", hidden: false, recipient: "<p>Globex</p>", content: "<p>Dear Globex team,</p>" }],
|
||||
});
|
||||
data.metadata.layout.pages.push({ fullWidth: true, main: ["old-letter"], sidebar: [] });
|
||||
exportedData.metadata.layout.pages.push({ fullWidth: true, main: ["old-letter"], sidebar: [] });
|
||||
const path = testInfo.outputPath("with-letter.json");
|
||||
await writeFile(path, JSON.stringify(data));
|
||||
await writeFile(path, JSON.stringify(exportedData));
|
||||
|
||||
await page.goto("/dashboard");
|
||||
await page.getByRole("button", { name: "New", exact: true }).click();
|
||||
|
||||
@@ -1,37 +1,34 @@
|
||||
import { createHash, randomBytes } from "node:crypto";
|
||||
import { expect, test } from "../fixtures/test";
|
||||
|
||||
for (const accept of [false, true]) {
|
||||
test(`requires explicit OAuth consent before ${accept ? "allowing" : "denying"} access`, async ({
|
||||
authPage: page,
|
||||
baseURL,
|
||||
}) => {
|
||||
const origin = new URL(baseURL ?? "http://localhost:3000").origin;
|
||||
const metadata = await page.request.get("/.well-known/oauth-protected-resource");
|
||||
expect(metadata.status()).toBe(200);
|
||||
const advertisedResource = (await metadata.json()).resource;
|
||||
expect(advertisedResource).toBe(origin);
|
||||
const resource = `${origin}/mcp`;
|
||||
const callback = "http://127.0.0.1:33921/callback";
|
||||
const registration = await page.request.post("/api/auth/oauth2/register", {
|
||||
headers: { origin },
|
||||
data: { client_name: "Consent test client", redirect_uris: [callback] },
|
||||
});
|
||||
expect(registration.status(), await registration.text()).toBe(201);
|
||||
const client = await registration.json();
|
||||
const verifier = randomBytes(32).toString("base64url");
|
||||
const query = new URLSearchParams({
|
||||
client_id: client.client_id,
|
||||
redirect_uri: callback,
|
||||
response_type: "code",
|
||||
scope: "openid profile offline_access",
|
||||
code_challenge: createHash("sha256").update(verifier).digest("base64url"),
|
||||
code_challenge_method: "S256",
|
||||
resource,
|
||||
state: "browser-consent-state",
|
||||
});
|
||||
query.append("resource", origin);
|
||||
await page.route(`${callback}**`, (route) => route.fulfill({ body: "Client callback" }));
|
||||
test("requires explicit OAuth consent before denying or allowing access", async ({ authPage: page, baseURL }) => {
|
||||
const origin = new URL(baseURL ?? "http://localhost:3000").origin;
|
||||
const metadata = await page.request.get("/.well-known/oauth-protected-resource");
|
||||
expect(metadata.status()).toBe(200);
|
||||
const advertisedResource = (await metadata.json()).resource;
|
||||
expect(advertisedResource).toBe(origin);
|
||||
const resource = `${origin}/mcp`;
|
||||
const callback = "http://127.0.0.1:33921/callback";
|
||||
const registration = await page.request.post("/api/auth/oauth2/register", {
|
||||
headers: { origin },
|
||||
data: { client_name: "Consent test client", redirect_uris: [callback] },
|
||||
});
|
||||
expect(registration.status(), await registration.text()).toBe(201);
|
||||
const client = await registration.json();
|
||||
const verifier = randomBytes(32).toString("base64url");
|
||||
const query = new URLSearchParams({
|
||||
client_id: client.client_id,
|
||||
redirect_uri: callback,
|
||||
response_type: "code",
|
||||
scope: "openid profile offline_access",
|
||||
code_challenge: createHash("sha256").update(verifier).digest("base64url"),
|
||||
code_challenge_method: "S256",
|
||||
resource,
|
||||
state: "browser-consent-state",
|
||||
});
|
||||
query.append("resource", origin);
|
||||
await page.route(`${callback}**`, (route) => route.fulfill({ body: "Client callback" }));
|
||||
for (const accept of [false, true]) {
|
||||
await page.goto(`/api/auth/oauth2/authorize?${query}`);
|
||||
await expect(page.getByRole("heading", { name: "Connect an application" })).toBeVisible();
|
||||
await expect(page.getByText("Consent test client", { exact: true })).toBeVisible();
|
||||
@@ -49,7 +46,7 @@ for (const accept of [false, true]) {
|
||||
expect(target.searchParams.has("code")).toBe(false);
|
||||
const after = await page.request.get(`${origin}/api/auth/oauth2/get-consents`);
|
||||
expect(await after.json()).toEqual([]);
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
expect(target.searchParams.get("code")).toBeTruthy();
|
||||
const token = await page.request.post(`${origin}/api/auth/oauth2/token`, {
|
||||
@@ -89,5 +86,5 @@ for (const accept of [false, true]) {
|
||||
data: initializePayload,
|
||||
});
|
||||
expect(wrongAudience.status()).toBe(401);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user