test(e2e): cover chat send token refresh retry
This commit is contained in:
@@ -18,12 +18,15 @@ import {
|
||||
paidVoiceHistoryResponse,
|
||||
paidPaymentOrderStatusResponse,
|
||||
paymentPlansResponse,
|
||||
refreshedEmailLoginResponse,
|
||||
refreshedGuestLoginResponse,
|
||||
userEntitlementsResponse,
|
||||
vipStatusResponse,
|
||||
} from "./test-data";
|
||||
|
||||
interface MockCoreApisOptions {
|
||||
chatLimitTriggerAt?: number;
|
||||
chatSendTokenRefreshFlow?: boolean;
|
||||
paidImageFlow?: boolean;
|
||||
paidImageInsufficientCreditsFlow?: boolean;
|
||||
paidVoiceInsufficientCreditsFlow?: boolean;
|
||||
@@ -35,16 +38,22 @@ export async function mockCoreApis(
|
||||
): Promise<void> {
|
||||
const {
|
||||
chatLimitTriggerAt,
|
||||
chatSendTokenRefreshFlow = false,
|
||||
paidImageFlow = false,
|
||||
paidImageInsufficientCreditsFlow = false,
|
||||
paidVoiceInsufficientCreditsFlow = false,
|
||||
} = options;
|
||||
let sendCount = 0;
|
||||
let hasExpiredChatSend = false;
|
||||
let paidImageRequested = false;
|
||||
let paidImageUnlocked = false;
|
||||
|
||||
await page.route("**/api/auth/guest", async (route) => {
|
||||
await route.fulfill({ json: apiEnvelope(guestLoginResponse) });
|
||||
const response =
|
||||
chatSendTokenRefreshFlow && hasExpiredChatSend
|
||||
? refreshedGuestLoginResponse
|
||||
: guestLoginResponse;
|
||||
await route.fulfill({ json: apiEnvelope(response) });
|
||||
});
|
||||
|
||||
await page.route("**/api/auth/login", async (route) => {
|
||||
@@ -55,6 +64,10 @@ export async function mockCoreApis(
|
||||
await route.fulfill({ json: apiEnvelope(emailLoginResponse) });
|
||||
});
|
||||
|
||||
await page.route("**/api/auth/refresh", async (route) => {
|
||||
await route.fulfill({ json: apiEnvelope(refreshedEmailLoginResponse) });
|
||||
});
|
||||
|
||||
await page.route("**/api/auth/logout", async (route) => {
|
||||
await route.fulfill({ json: apiEnvelope(null) });
|
||||
});
|
||||
@@ -88,6 +101,17 @@ export async function mockCoreApis(
|
||||
const message =
|
||||
typeof requestBody?.message === "string" ? requestBody.message : "";
|
||||
|
||||
if (chatSendTokenRefreshFlow && !hasExpiredChatSend) {
|
||||
hasExpiredChatSend = true;
|
||||
await route.fulfill({
|
||||
status: 401,
|
||||
json: {
|
||||
message: "expired",
|
||||
},
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const response =
|
||||
paidImageFlow && message.includes("给我发图片")
|
||||
? paidImageChatSendResponse
|
||||
|
||||
Reference in New Issue
Block a user