test(chat): cover promoted image top-up flow
This commit is contained in:
@@ -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();
|
||||
});
|
||||
Reference in New Issue
Block a user