test(e2e): add mock chat quantity limit coverage
This commit is contained in:
@@ -3,6 +3,8 @@ import type { Page } from "@playwright/test";
|
||||
import {
|
||||
apiEnvelope,
|
||||
chatSendResponse,
|
||||
createChatSendResponse,
|
||||
createWeeklyLimitChatSendResponse,
|
||||
e2eEmailUser,
|
||||
emptyChatHistoryResponse,
|
||||
emailLoginResponse,
|
||||
@@ -12,7 +14,17 @@ import {
|
||||
vipStatusResponse,
|
||||
} from "./test-data";
|
||||
|
||||
export async function mockCoreApis(page: Page): Promise<void> {
|
||||
interface MockCoreApisOptions {
|
||||
chatLimitTriggerAt?: number;
|
||||
}
|
||||
|
||||
export async function mockCoreApis(
|
||||
page: Page,
|
||||
options: MockCoreApisOptions = {},
|
||||
): Promise<void> {
|
||||
const { chatLimitTriggerAt } = options;
|
||||
let sendCount = 0;
|
||||
|
||||
await page.route("**/api/auth/guest", async (route) => {
|
||||
await route.fulfill({ json: apiEnvelope(guestLoginResponse) });
|
||||
});
|
||||
@@ -38,7 +50,16 @@ export async function mockCoreApis(page: Page): Promise<void> {
|
||||
});
|
||||
|
||||
await page.route("**/api/chat/send", async (route) => {
|
||||
await route.fulfill({ json: apiEnvelope(chatSendResponse) });
|
||||
sendCount += 1;
|
||||
|
||||
const response =
|
||||
chatLimitTriggerAt != null && sendCount >= chatLimitTriggerAt
|
||||
? createWeeklyLimitChatSendResponse(sendCount, chatLimitTriggerAt)
|
||||
: chatLimitTriggerAt != null
|
||||
? createChatSendResponse(sendCount)
|
||||
: chatSendResponse;
|
||||
|
||||
await route.fulfill({ json: apiEnvelope(response) });
|
||||
});
|
||||
|
||||
await page.route("**/api/payment/plans**", async (route) => {
|
||||
|
||||
Reference in New Issue
Block a user