test(chat): cover promoted image top-up flow

This commit is contained in:
2026-07-16 12:56:23 +08:00
parent 0409d55d7f
commit 1c8a6afce1
@@ -0,0 +1,62 @@
import { expect, test } from "@playwright/test";
import { mockCoreApis } from "@e2e/fixtures/api-mocks";
import {
clearBrowserState,
completeVipPayment,
expectInsufficientCreditsDialog,
expectVipChatSubscriptionUrl,
setEmailSessionStorage,
submitEmailLogin,
switchToEmailSignIn,
} from "@e2e/fixtures/test-helpers";
test.beforeEach(async ({ baseURL, context, page }) => {
await clearBrowserState(context, page, baseURL);
await mockCoreApis(page, {
paidImageInsufficientCreditsFlow: true,
});
});
test("guest unlocks a promoted image through email login and top-up", async ({
page,
}) => {
await page.goto(
"/external-entry?target=chat&mode=promotion&promotion_type=image",
);
await expect(page).toHaveURL(/\/chat$/);
const unlockButton = page.getByRole("button", {
name: "Unlock private image",
});
await expect(unlockButton).toBeVisible({ timeout: 10_000 });
await unlockButton.click();
await expect(page).toHaveURL(/\/auth\?redirect=/);
await switchToEmailSignIn(page);
await submitEmailLogin(page, { expectedUrl: /\/chat$/ });
await setEmailSessionStorage(page);
const unlockRequestPromise = page.waitForRequest(
"**/api/chat/unlock-private",
);
await page.reload();
const unlockRequest = await unlockRequestPromise;
expect(unlockRequest.method()).toBe("POST");
expect(unlockRequest.postDataJSON()).toMatchObject({
lockType: "image_paywall",
});
const insufficientCreditsDialog = await expectInsufficientCreditsDialog(page);
await insufficientCreditsDialog
.getByRole("button", { name: "Top up now" })
.click();
await expectVipChatSubscriptionUrl(page);
await completeVipPayment(page);
await expect(page).toHaveURL(/\/chat$/);
await expect(page.getByRole("textbox", { name: "Message" })).toBeVisible();
});