新增案例库浏览器登录态

This commit is contained in:
czj
2026-07-08 17:02:37 +08:00
parent fd1b792f2c
commit b4472fe348
12 changed files with 646 additions and 75 deletions
+82
View File
@@ -1,6 +1,7 @@
import { expect, test } from "@playwright/test";
test("案例库列表和人味文案详情可查看", async ({ page }) => {
await mockAuthenticatedSession(page, true);
await page.route("**/api/cases", async (route) => {
await route.fulfill({
status: 200,
@@ -134,3 +135,84 @@ test("案例库列表和人味文案详情可查看", async ({ page }) => {
await expect(page.getByText("AI 味检查")).toBeVisible();
await expect(page.getByText("发布表现")).toBeVisible();
});
test("案例库可以通过访问密钥建立浏览器登录态", async ({ page }) => {
let authenticated = false;
await page.route("**/api/auth/session", async (route) => {
const request = route.request();
if (request.method() === "GET") {
await route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify({ authenticated }),
});
return;
}
if (request.method() === "POST") {
const payload = request.postDataJSON() as { api_access_key?: string };
authenticated = payload.api_access_key === "local-dev-key";
await route.fulfill({
status: authenticated ? 200 : 401,
contentType: "application/json",
body: JSON.stringify(
authenticated
? { authenticated: true }
: { error: "Unauthorized" },
),
});
return;
}
await route.fulfill({ status: 405 });
});
await page.route("**/api/cases", async (route) => {
await route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify({
cases: [
{
id: "case_article_1",
case_type: "article",
title: "伟思德鲁官网文章优化案例",
summary: "优化后摘要",
status: "optimized",
customer_name: "",
brand_name: "",
project_tags: [],
notes: "",
publish_target: "official_site",
source_excerpt: "原文摘要",
result_excerpt: "优化后摘要",
latest_result_version_id: "ver_article_1",
latest_version_number: 1,
last_error_stage: null,
last_error_summary: null,
archived_at: null,
created_at: "2026-07-08T10:00:00.000Z",
updated_at: "2026-07-08T10:05:00.000Z",
},
],
}),
});
});
await page.goto("/cases");
await expect(page.getByText("请先登录后查看案例库。")).toBeVisible();
await page.getByLabel("访问密钥").fill("local-dev-key");
await page.getByRole("button", { name: "确认登录" }).click();
await expect(page.getByText("已登录")).toBeVisible();
await expect(page.getByText("伟思德鲁官网文章优化案例")).toBeVisible();
});
async function mockAuthenticatedSession(
page: Parameters<Parameters<typeof test>[1]>[0]["page"],
authenticated: boolean,
) {
await page.route("**/api/auth/session", async (route) => {
await route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify({ authenticated }),
});
});
}