test(e2e): add paid image insufficient credits flow

This commit is contained in:
2026-07-01 16:01:06 +08:00
parent a52e7f15ff
commit 854a7498b7
3 changed files with 138 additions and 19 deletions
+27 -19
View File
@@ -11,6 +11,7 @@ import {
emptyChatHistoryResponse,
emailLoginResponse,
guestLoginResponse,
insufficientCreditsUnlockImageResponse,
insufficientCreditsUnlockVoiceResponse,
paidImageChatSendResponse,
paidImageUnlockHistoryResponse,
@@ -24,6 +25,7 @@ import {
interface MockCoreApisOptions {
chatLimitTriggerAt?: number;
paidImageFlow?: boolean;
paidImageInsufficientCreditsFlow?: boolean;
paidVoiceInsufficientCreditsFlow?: boolean;
}
@@ -34,6 +36,7 @@ export async function mockCoreApis(
const {
chatLimitTriggerAt,
paidImageFlow = false,
paidImageInsufficientCreditsFlow = false,
paidVoiceInsufficientCreditsFlow = false,
} = options;
let sendCount = 0;
@@ -68,6 +71,8 @@ export async function mockCoreApis(
const response =
paidVoiceInsufficientCreditsFlow
? paidVoiceHistoryResponse
: paidImageInsufficientCreditsFlow
? createPaidImageHistoryResponse(false)
: paidImageFlow && paidImageRequested
? createPaidImageHistoryResponse(paidImageUnlocked)
: emptyChatHistoryResponse;
@@ -128,25 +133,28 @@ export async function mockCoreApis(
});
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,
},
};
const response =
paidVoiceInsufficientCreditsFlow
? insufficientCreditsUnlockVoiceResponse
: paidImageInsufficientCreditsFlow
? insufficientCreditsUnlockImageResponse
: {
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) });
});