test(e2e): add paid image insufficient credits flow
This commit is contained in:
@@ -11,6 +11,7 @@ import {
|
|||||||
emptyChatHistoryResponse,
|
emptyChatHistoryResponse,
|
||||||
emailLoginResponse,
|
emailLoginResponse,
|
||||||
guestLoginResponse,
|
guestLoginResponse,
|
||||||
|
insufficientCreditsUnlockImageResponse,
|
||||||
insufficientCreditsUnlockVoiceResponse,
|
insufficientCreditsUnlockVoiceResponse,
|
||||||
paidImageChatSendResponse,
|
paidImageChatSendResponse,
|
||||||
paidImageUnlockHistoryResponse,
|
paidImageUnlockHistoryResponse,
|
||||||
@@ -24,6 +25,7 @@ import {
|
|||||||
interface MockCoreApisOptions {
|
interface MockCoreApisOptions {
|
||||||
chatLimitTriggerAt?: number;
|
chatLimitTriggerAt?: number;
|
||||||
paidImageFlow?: boolean;
|
paidImageFlow?: boolean;
|
||||||
|
paidImageInsufficientCreditsFlow?: boolean;
|
||||||
paidVoiceInsufficientCreditsFlow?: boolean;
|
paidVoiceInsufficientCreditsFlow?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,6 +36,7 @@ export async function mockCoreApis(
|
|||||||
const {
|
const {
|
||||||
chatLimitTriggerAt,
|
chatLimitTriggerAt,
|
||||||
paidImageFlow = false,
|
paidImageFlow = false,
|
||||||
|
paidImageInsufficientCreditsFlow = false,
|
||||||
paidVoiceInsufficientCreditsFlow = false,
|
paidVoiceInsufficientCreditsFlow = false,
|
||||||
} = options;
|
} = options;
|
||||||
let sendCount = 0;
|
let sendCount = 0;
|
||||||
@@ -68,6 +71,8 @@ export async function mockCoreApis(
|
|||||||
const response =
|
const response =
|
||||||
paidVoiceInsufficientCreditsFlow
|
paidVoiceInsufficientCreditsFlow
|
||||||
? paidVoiceHistoryResponse
|
? paidVoiceHistoryResponse
|
||||||
|
: paidImageInsufficientCreditsFlow
|
||||||
|
? createPaidImageHistoryResponse(false)
|
||||||
: paidImageFlow && paidImageRequested
|
: paidImageFlow && paidImageRequested
|
||||||
? createPaidImageHistoryResponse(paidImageUnlocked)
|
? createPaidImageHistoryResponse(paidImageUnlocked)
|
||||||
: emptyChatHistoryResponse;
|
: emptyChatHistoryResponse;
|
||||||
@@ -128,8 +133,11 @@ export async function mockCoreApis(
|
|||||||
});
|
});
|
||||||
|
|
||||||
await page.route("**/api/chat/unlock-private", async (route) => {
|
await page.route("**/api/chat/unlock-private", async (route) => {
|
||||||
const response = paidVoiceInsufficientCreditsFlow
|
const response =
|
||||||
|
paidVoiceInsufficientCreditsFlow
|
||||||
? insufficientCreditsUnlockVoiceResponse
|
? insufficientCreditsUnlockVoiceResponse
|
||||||
|
: paidImageInsufficientCreditsFlow
|
||||||
|
? insufficientCreditsUnlockImageResponse
|
||||||
: {
|
: {
|
||||||
unlocked: true,
|
unlocked: true,
|
||||||
content: "Unlocked message",
|
content: "Unlocked message",
|
||||||
|
|||||||
@@ -261,6 +261,24 @@ export const insufficientCreditsUnlockVoiceResponse = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const insufficientCreditsUnlockImageResponse = {
|
||||||
|
unlocked: false,
|
||||||
|
content: "",
|
||||||
|
reason: "insufficient_balance",
|
||||||
|
creditBalance: 3,
|
||||||
|
creditsCharged: 0,
|
||||||
|
requiredCredits: 30,
|
||||||
|
shortfallCredits: 27,
|
||||||
|
lockDetail: {
|
||||||
|
locked: true,
|
||||||
|
showContent: true,
|
||||||
|
showUpgrade: true,
|
||||||
|
reason: "image",
|
||||||
|
hint: "Unlock this high-definition image with credits.",
|
||||||
|
detail: null,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
export const paymentPlansResponse = {
|
export const paymentPlansResponse = {
|
||||||
plans: [
|
plans: [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,93 @@
|
|||||||
|
import { expect, test } from "@playwright/test";
|
||||||
|
|
||||||
|
import { mockCoreApis } from "../../fixtures/api-mocks";
|
||||||
|
import { paidImageMessageId } from "../../fixtures/test-data";
|
||||||
|
|
||||||
|
test.beforeEach(async ({ baseURL, context, page }) => {
|
||||||
|
await context.clearCookies();
|
||||||
|
|
||||||
|
const client = await context.newCDPSession(page);
|
||||||
|
const origins = new Set([
|
||||||
|
new URL(baseURL ?? "http://127.0.0.1:3000").origin,
|
||||||
|
"http://127.0.0.1:3000",
|
||||||
|
"http://localhost:3000",
|
||||||
|
]);
|
||||||
|
for (const origin of origins) {
|
||||||
|
await client
|
||||||
|
.send("Storage.clearDataForOrigin", {
|
||||||
|
origin,
|
||||||
|
storageTypes: "all",
|
||||||
|
})
|
||||||
|
.catch(() => {});
|
||||||
|
}
|
||||||
|
|
||||||
|
await mockCoreApis(page, {
|
||||||
|
paidImageInsufficientCreditsFlow: true,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("user sees insufficient credits when unlocking a paid image from fullscreen and can navigate to subscription", async ({
|
||||||
|
page,
|
||||||
|
}) => {
|
||||||
|
await signInWithEmailAndOpenChat(page);
|
||||||
|
|
||||||
|
const paidImageButton = page.getByRole("button", {
|
||||||
|
name: "Open image in fullscreen",
|
||||||
|
});
|
||||||
|
await expect(paidImageButton).toBeVisible({ timeout: 10_000 });
|
||||||
|
|
||||||
|
await paidImageButton.click();
|
||||||
|
await expect(page).toHaveURL(new RegExp(`/chat/image/${paidImageMessageId}$`));
|
||||||
|
|
||||||
|
const lockedImageDialog = page.getByRole("dialog", {
|
||||||
|
name: "Locked fullscreen image",
|
||||||
|
});
|
||||||
|
await expect(lockedImageDialog).toBeVisible();
|
||||||
|
|
||||||
|
const unlockRequestPromise = page.waitForRequest(
|
||||||
|
"**/api/chat/unlock-private",
|
||||||
|
);
|
||||||
|
await lockedImageDialog
|
||||||
|
.getByRole("button", { name: "Unlock high-definition large image" })
|
||||||
|
.click();
|
||||||
|
|
||||||
|
const unlockRequest = await unlockRequestPromise;
|
||||||
|
expect(unlockRequest.method()).toBe("POST");
|
||||||
|
expect(unlockRequest.postDataJSON()).toMatchObject({
|
||||||
|
messageId: paidImageMessageId,
|
||||||
|
});
|
||||||
|
|
||||||
|
const insufficientCreditsDialog = page.getByRole("dialog", {
|
||||||
|
name: "Not enough credits",
|
||||||
|
});
|
||||||
|
await expect(insufficientCreditsDialog).toBeVisible();
|
||||||
|
await expect(insufficientCreditsDialog.getByText("Balance")).toBeVisible();
|
||||||
|
await expect(insufficientCreditsDialog.getByText("Required")).toBeVisible();
|
||||||
|
await expect(insufficientCreditsDialog.getByText("Still needed")).toBeVisible();
|
||||||
|
|
||||||
|
await insufficientCreditsDialog
|
||||||
|
.getByRole("button", { name: "Top up now" })
|
||||||
|
.click();
|
||||||
|
|
||||||
|
await expect(page).toHaveURL(/\/subscription\?type=vip&returnTo=chat$/);
|
||||||
|
});
|
||||||
|
|
||||||
|
async function signInWithEmailAndOpenChat(
|
||||||
|
page: import("@playwright/test").Page,
|
||||||
|
) {
|
||||||
|
await page.goto("/auth");
|
||||||
|
|
||||||
|
await page.getByRole("button", { name: /Other Sign In Options/i }).click();
|
||||||
|
await expect(
|
||||||
|
page.getByRole("dialog", { name: /Other sign-in options/i }),
|
||||||
|
).toBeVisible();
|
||||||
|
|
||||||
|
await page.getByRole("button", { name: "Email Sign In" }).click();
|
||||||
|
await expect(page.getByPlaceholder("Email")).toHaveValue(
|
||||||
|
"chanwillian0@gmail.com",
|
||||||
|
);
|
||||||
|
await expect(page.getByPlaceholder("Password")).toHaveValue("12345678");
|
||||||
|
|
||||||
|
await page.getByRole("button", { name: "Login" }).click();
|
||||||
|
await expect(page).toHaveURL(/\/chat$/);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user