test(e2e): add paid voice insufficient credits flow

This commit is contained in:
2026-07-01 14:41:59 +08:00
parent 760e4fe343
commit 969a3b3f9f
3 changed files with 172 additions and 2 deletions
+35 -2
View File
@@ -11,8 +11,10 @@ import {
emptyChatHistoryResponse,
emailLoginResponse,
guestLoginResponse,
insufficientCreditsUnlockVoiceResponse,
paidImageChatSendResponse,
paidImageUnlockHistoryResponse,
paidVoiceHistoryResponse,
paidPaymentOrderStatusResponse,
paymentPlansResponse,
userEntitlementsResponse,
@@ -22,13 +24,18 @@ import {
interface MockCoreApisOptions {
chatLimitTriggerAt?: number;
paidImageFlow?: boolean;
paidVoiceInsufficientCreditsFlow?: boolean;
}
export async function mockCoreApis(
page: Page,
options: MockCoreApisOptions = {},
): Promise<void> {
const { chatLimitTriggerAt, paidImageFlow = false } = options;
const {
chatLimitTriggerAt,
paidImageFlow = false,
paidVoiceInsufficientCreditsFlow = false,
} = options;
let sendCount = 0;
let paidImageRequested = false;
let paidImageUnlocked = false;
@@ -59,7 +66,9 @@ export async function mockCoreApis(
await page.route("**/api/chat/history**", async (route) => {
const response =
paidImageFlow && paidImageRequested
paidVoiceInsufficientCreditsFlow
? paidVoiceHistoryResponse
: paidImageFlow && paidImageRequested
? createPaidImageHistoryResponse(paidImageUnlocked)
: emptyChatHistoryResponse;
@@ -118,6 +127,30 @@ export async function mockCoreApis(
await route.fulfill({ json: apiEnvelope(response) });
});
await page.route("**/api/chat/unlock-private", async (route) => {
const response = paidVoiceInsufficientCreditsFlow
? insufficientCreditsUnlockVoiceResponse
: {
unlocked: true,
content: "Unlocked message",
reason: "ok",
creditBalance: 100,
creditsCharged: 0,
requiredCredits: 0,
shortfallCredits: 0,
lockDetail: {
locked: false,
showContent: true,
showUpgrade: false,
reason: null,
hint: null,
detail: null,
},
};
await route.fulfill({ json: apiEnvelope(response) });
});
await page.route("**/api/payment/plans**", async (route) => {
await route.fulfill({ json: apiEnvelope(paymentPlansResponse) });
});
+54
View File
@@ -207,6 +207,60 @@ export const paidImageUnlockHistoryResponse = {
messageIds: [paidImageMessageId],
};
export const paidVoiceMessageId = "msg_voice_paywall_001";
export const paidVoiceAudioUrl =
"data:audio/mpeg;base64,//uQZAAAAAAAAAAAAAAAAAAAAAAAWGluZwAAAA8AAAACAAACcQCA";
export const paidVoiceHistoryResponse = {
messages: [
{
role: "assistant",
type: "voice",
content: "",
id: paidVoiceMessageId,
created_at: "2026-07-01T00:00:00.000Z",
audioUrl: paidVoiceAudioUrl,
image: {
type: null,
url: null,
},
lockDetail: {
locked: true,
showContent: true,
showUpgrade: true,
reason: "voice_message",
hint: "Unlock this voice message with credits.",
detail: null,
},
},
],
total: 1,
limit: 50,
offset: 0,
isVip: false,
privateFreeLimit: 0,
privateUsedToday: 0,
privateCanViewFree: false,
};
export const insufficientCreditsUnlockVoiceResponse = {
unlocked: false,
content: "",
reason: "insufficient_balance",
creditBalance: 3,
creditsCharged: 0,
requiredCredits: 20,
shortfallCredits: 17,
lockDetail: {
locked: true,
showContent: true,
showUpgrade: true,
reason: "voice_message",
hint: "Unlock this voice message with credits.",
detail: null,
},
};
export const paymentPlansResponse = {
plans: [
{