fix(e2e): stabilize authenticated unlock flows

This commit is contained in:
Codex
2026-07-22 16:53:09 +08:00
parent 8bd67b83c5
commit e813333607
16 changed files with 116 additions and 28 deletions
+10 -11
View File
@@ -1,7 +1,10 @@
import { expect, test } from "@playwright/test";
import { mockCoreApis } from "@e2e/fixtures/api-mocks";
import { paidImageMessageId } from "@e2e/fixtures/test-data";
import {
paidImageDisplayMessageId,
paidImageMessageId,
} from "@e2e/fixtures/test-data";
import {
clearBrowserState,
completeVipPayment,
@@ -10,13 +13,12 @@ import {
enterChatFromSplash,
expectInsufficientCreditsDialog,
expectVipChatSubscriptionUrl,
setEmailSessionStorage,
submitEmailLogin,
switchToEmailSignIn,
} from "@e2e/fixtures/test-helpers";
const paidImageOverlayUrl = new RegExp(
`${defaultCharacterChatPath}\\?image=${paidImageMessageId}$`,
`${defaultCharacterChatPath}\\?image=${encodeURIComponent(paidImageDisplayMessageId)}$`,
);
test.beforeEach(async ({ baseURL, context, page }) => {
@@ -63,19 +65,16 @@ test("guest can unlock a paid image after email login and subscription payment",
await expect(page).toHaveURL(/\/auth\?redirect=/);
expect(new URL(page.url()).searchParams.get("redirect")).toBe(
`${defaultCharacterChatPath}?image=${paidImageMessageId}`,
`${defaultCharacterChatPath}?image=${encodeURIComponent(paidImageDisplayMessageId)}`,
);
await switchToEmailSignIn(page);
await submitEmailLogin(page, {
expectedUrl: paidImageOverlayUrl,
});
await setEmailSessionStorage(page);
const unlockRequestPromise = page.waitForRequest(
"**/api/chat/unlock-private",
);
await page.goto(`${defaultCharacterChatPath}?image=${paidImageMessageId}`);
await submitEmailLogin(page, {
expectedUrl: paidImageOverlayUrl,
});
const unlockRequest = await unlockRequestPromise;
expect(unlockRequest.postDataJSON()).toMatchObject({
@@ -92,7 +91,7 @@ test("guest can unlock a paid image after email login and subscription payment",
await expect(page).toHaveURL(
new RegExp(
`${defaultCharacterChatPath}(?:\\?image=msg_photo_paywall_001)?$`,
`${defaultCharacterChatPath}(?:\\?image=${encodeURIComponent(paidImageDisplayMessageId)})?$`,
),
);
expect(new URL(page.url()).pathname).toBe(defaultCharacterChatPath);