test(e2e): add playwright smoke coverage

This commit is contained in:
2026-06-25 14:19:38 +08:00
parent 6081f2896a
commit 5879b7acf3
10 changed files with 402 additions and 8 deletions
+32
View File
@@ -0,0 +1,32 @@
import type { Page } from "@playwright/test";
import {
apiEnvelope,
chatSendResponse,
emptyChatHistoryResponse,
guestLoginResponse,
paymentPlansResponse,
vipStatusResponse,
} from "./test-data";
export async function mockCoreApis(page: Page): Promise<void> {
await page.route("**/api/auth/guest", async (route) => {
await route.fulfill({ json: apiEnvelope(guestLoginResponse) });
});
await page.route("**/api/chat/history**", async (route) => {
await route.fulfill({ json: apiEnvelope(emptyChatHistoryResponse) });
});
await page.route("**/api/chat/send", async (route) => {
await route.fulfill({ json: apiEnvelope(chatSendResponse) });
});
await page.route("**/api/payment/plans**", async (route) => {
await route.fulfill({ json: apiEnvelope(paymentPlansResponse) });
});
await page.route("**/api/payment/vip-status**", async (route) => {
await route.fulfill({ json: apiEnvelope(vipStatusResponse) });
});
}
+110
View File
@@ -0,0 +1,110 @@
export function apiEnvelope<T>(data: T) {
return {
code: 200,
message: "success",
success: true,
data,
};
}
export const e2eUser = {
id: "user_e2e",
username: "E2E User",
email: "e2e@example.com",
platform: "web",
intimacy: 42,
dolBalance: 0,
relationshipStage: "close_friend",
currentMood: "happy",
preferredLanguage: "en",
createdAt: "2026-06-25T00:00:00.000Z",
lastMessageAt: "",
avatarUrl: "",
loginProvider: "guest",
isGuest: true,
isVip: false,
voiceMinutesRemaining: 0,
};
export const guestLoginResponse = {
token: "e2e-guest-token",
deviceId: "e2e-device-id",
userId: e2eUser.id,
isDeviceUser: true,
expiresIn: 2_592_000,
user: e2eUser,
};
export const emptyChatHistoryResponse = {
messages: [],
total: 0,
limit: 50,
offset: 0,
isVip: false,
privateFreeLimit: 0,
privateUsedToday: 0,
privateCanViewFree: false,
};
export const chatSendResponse = {
reply: "Hello from the E2E boyfriend.",
audioUrl: "",
messageId: "msg_e2e_reply_001",
isGuest: true,
timestamp: 1_782_356_425_363,
image: {
type: null,
url: null,
},
lockDetail: {
locked: false,
showContent: true,
showUpgrade: false,
reason: null,
hint: null,
detail: null,
},
};
export const paymentPlansResponse = {
plans: [
{
plan_id: "vip_monthly",
plan_name: "Monthly",
order_type: "vip_monthly",
amount_cents: 999,
original_amount_cents: 1999,
daily_price_cents: 33,
currency: "USD",
vip_days: 30,
dol_amount: null,
},
{
plan_id: "vip_quarterly",
plan_name: "Quarterly",
order_type: "vip_quarterly",
amount_cents: 2499,
original_amount_cents: 5999,
daily_price_cents: 28,
currency: "USD",
vip_days: 90,
dol_amount: null,
},
{
plan_id: "dol_voice_30",
plan_name: "Voice Pack",
order_type: "dol_voice",
amount_cents: 499,
original_amount_cents: null,
daily_price_cents: null,
currency: "USD",
vip_days: null,
dol_amount: 30,
},
],
};
export const vipStatusResponse = {
isVip: false,
expiresAt: null,
};