49 lines
1.5 KiB
TypeScript
49 lines
1.5 KiB
TypeScript
import { expect, test } from "@playwright/test";
|
|
|
|
import { mockCoreApis } from "../../fixtures/api-mocks";
|
|
import { paidVoiceMessageId } from "../../fixtures/test-data";
|
|
import {
|
|
clearBrowserState,
|
|
expectInsufficientCreditsDialog,
|
|
signInWithEmailAndOpenChat,
|
|
} from "../../fixtures/test-helpers";
|
|
|
|
test.beforeEach(async ({ baseURL, context, page }) => {
|
|
await clearBrowserState(context, page, baseURL);
|
|
await mockCoreApis(page, {
|
|
paidVoiceInsufficientCreditsFlow: true,
|
|
});
|
|
});
|
|
|
|
test("user sees insufficient credits when unlocking a paid voice message and can navigate to subscription", async ({
|
|
page,
|
|
}) => {
|
|
await signInWithEmailAndOpenChat(page);
|
|
await expect(
|
|
page.getByText("Unlock this voice message with credits."),
|
|
).toBeVisible({ timeout: 10_000 });
|
|
|
|
const unlockButton = page.getByRole("button", {
|
|
name: "Unlock voice message",
|
|
}).last();
|
|
await expect(unlockButton).toBeVisible({ timeout: 10_000 });
|
|
|
|
const unlockRequestPromise = page.waitForRequest(
|
|
"**/api/chat/unlock-private",
|
|
);
|
|
await unlockButton.click();
|
|
|
|
const unlockRequest = await unlockRequestPromise;
|
|
expect(unlockRequest.method()).toBe("POST");
|
|
expect(unlockRequest.postDataJSON()).toMatchObject({
|
|
messageId: paidVoiceMessageId,
|
|
});
|
|
|
|
const insufficientCreditsDialog = await expectInsufficientCreditsDialog(page);
|
|
await insufficientCreditsDialog
|
|
.getByRole("button", { name: "Top up now" })
|
|
.click();
|
|
|
|
await expect(page).toHaveURL(/\/subscription\?type=vip&returnTo=chat$/);
|
|
});
|