Files
cozsweet-frontend-nextjs/e2e/fixtures/api-mocks.ts
T

52 lines
1.5 KiB
TypeScript

import type { Page } from "@playwright/test";
import {
apiEnvelope,
chatSendResponse,
e2eEmailUser,
emptyChatHistoryResponse,
emailLoginResponse,
guestLoginResponse,
paymentPlansResponse,
userEntitlementsResponse,
vipStatusResponse,
} from "./test-data";
export async function mockCoreApis(page: Page): Promise<void> {
await page.route("**/api/auth/guest", async (route) => {
await route.fulfill({ json: apiEnvelope(guestLoginResponse) });
});
await page.route("**/api/auth/login", async (route) => {
await route.fulfill({ json: apiEnvelope(emailLoginResponse) });
});
await page.route("**/api/auth/logout", async (route) => {
await route.fulfill({ json: apiEnvelope(null) });
});
await page.route("**/api/user/profile", async (route) => {
await route.fulfill({ json: apiEnvelope(e2eEmailUser) });
});
await page.route("**/api/user/entitlements", async (route) => {
await route.fulfill({ json: apiEnvelope(userEntitlementsResponse) });
});
await page.route("**/api/chat/history**", async (route) => {
await route.fulfill({ json: apiEnvelope(emptyChatHistoryResponse) });
});
await page.route("**/api/chat/send", async (route) => {
await route.fulfill({ json: apiEnvelope(chatSendResponse) });
});
await page.route("**/api/payment/plans**", async (route) => {
await route.fulfill({ json: apiEnvelope(paymentPlansResponse) });
});
await page.route("**/api/payment/vip-status**", async (route) => {
await route.fulfill({ json: apiEnvelope(vipStatusResponse) });
});
}