test(e2e): cover chat send token refresh retry
This commit is contained in:
@@ -6,6 +6,8 @@ import {
|
||||
completeVipPayment,
|
||||
dismissChatInterruptions,
|
||||
enterChatFromSplash,
|
||||
expectAuthRedirectToVipChatSubscription,
|
||||
expectVipChatSubscriptionUrl,
|
||||
submitEmailLogin,
|
||||
switchToEmailSignIn,
|
||||
} from "../../fixtures/test-helpers";
|
||||
@@ -88,13 +90,11 @@ test("guest hits the chat quantity limit and can continue to login and subscript
|
||||
|
||||
await topUpButton.click();
|
||||
await expect(page).toHaveURL(/\/auth\?redirect=/);
|
||||
expect(new URL(page.url()).searchParams.get("redirect")).toBe(
|
||||
"/subscription?type=vip&returnTo=chat",
|
||||
);
|
||||
expectAuthRedirectToVipChatSubscription(page);
|
||||
|
||||
await switchToEmailSignIn(page);
|
||||
await submitEmailLogin(page);
|
||||
await expect(page).toHaveURL(/\/subscription\?type=vip&returnTo=chat$/);
|
||||
await expectVipChatSubscriptionUrl(page);
|
||||
|
||||
await completeVipPayment(page);
|
||||
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
import { expect, test, type Request } from "@playwright/test";
|
||||
|
||||
import { mockCoreApis } from "../../fixtures/api-mocks";
|
||||
import {
|
||||
clearBrowserState,
|
||||
signInWithEmailAndOpenChat,
|
||||
} from "../../fixtures/test-helpers";
|
||||
|
||||
test.beforeEach(async ({ baseURL, context, page }) => {
|
||||
await clearBrowserState(context, page, baseURL);
|
||||
await mockCoreApis(page, {
|
||||
chatSendTokenRefreshFlow: true,
|
||||
});
|
||||
});
|
||||
|
||||
test("chat send refreshes an expired token, retries the request, and renders the reply", async ({
|
||||
page,
|
||||
}) => {
|
||||
const chatSendRequests: Request[] = [];
|
||||
page.on("request", (request) => {
|
||||
if (new URL(request.url()).pathname === "/api/chat/send") {
|
||||
chatSendRequests.push(request);
|
||||
}
|
||||
});
|
||||
|
||||
await signInWithEmailAndOpenChat(page);
|
||||
|
||||
const message = "token refresh retry test";
|
||||
const messageInput = page.getByRole("textbox", { name: "Message" });
|
||||
await expect(messageInput).toBeVisible({ timeout: 10_000 });
|
||||
await expect(messageInput).toBeEnabled();
|
||||
await messageInput.fill(message);
|
||||
|
||||
const refreshRequestPromise = page.waitForRequest("**/api/auth/refresh");
|
||||
const retriedSendResponsePromise = page.waitForResponse(
|
||||
(response) =>
|
||||
new URL(response.url()).pathname === "/api/chat/send" &&
|
||||
response.status() === 200,
|
||||
);
|
||||
|
||||
await messageInput.press("Enter");
|
||||
|
||||
const refreshRequest = await refreshRequestPromise;
|
||||
expect(refreshRequest.method()).toBe("POST");
|
||||
expect(refreshRequest.headers().authorization).toBeUndefined();
|
||||
expect(refreshRequest.postDataJSON()).toMatchObject({
|
||||
refreshToken: "e2e-email-refresh-token",
|
||||
});
|
||||
|
||||
await retriedSendResponsePromise;
|
||||
await expect.poll(() => chatSendRequests.length).toBe(2);
|
||||
|
||||
expect(chatSendRequests[0]?.postDataJSON()).toMatchObject({ message });
|
||||
expect(chatSendRequests[0]?.headers().authorization).toBe(
|
||||
"Bearer e2e-email-token",
|
||||
);
|
||||
expect(chatSendRequests[1]?.postDataJSON()).toMatchObject({ message });
|
||||
expect(chatSendRequests[1]?.headers().authorization).toBe(
|
||||
"Bearer e2e-refreshed-email-token",
|
||||
);
|
||||
|
||||
await expect(page.getByText(message)).toBeVisible();
|
||||
await expect(page.getByText("Hello from the E2E boyfriend.")).toBeVisible();
|
||||
});
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
clearBrowserState,
|
||||
dismissChatInterruptions,
|
||||
expectInsufficientCreditsDialog,
|
||||
expectVipChatSubscriptionUrl,
|
||||
signInWithEmailAndOpenChat,
|
||||
} from "../../fixtures/test-helpers";
|
||||
|
||||
@@ -53,5 +54,5 @@ test("user sees insufficient credits when unlocking a paid image from fullscreen
|
||||
.getByRole("button", { name: "Top up now" })
|
||||
.click();
|
||||
|
||||
await expect(page).toHaveURL(/\/subscription\?type=vip&returnTo=chat$/);
|
||||
await expectVipChatSubscriptionUrl(page);
|
||||
});
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
dismissChatInterruptions,
|
||||
enterChatFromSplash,
|
||||
expectInsufficientCreditsDialog,
|
||||
expectVipChatSubscriptionUrl,
|
||||
submitEmailLogin,
|
||||
switchToEmailSignIn,
|
||||
} from "../../fixtures/test-helpers";
|
||||
@@ -77,7 +78,7 @@ test("guest can unlock a paid image after email login and subscription payment",
|
||||
.getByRole("button", { name: "Top up now" })
|
||||
.click();
|
||||
|
||||
await expect(page).toHaveURL(/\/subscription\?type=vip&returnTo=chat$/);
|
||||
await expectVipChatSubscriptionUrl(page);
|
||||
await completeVipPayment(page);
|
||||
|
||||
await expect(page).toHaveURL(new RegExp(`/chat/image/${paidImageMessageId}$`));
|
||||
|
||||
@@ -5,6 +5,7 @@ import { paidVoiceMessageId } from "../../fixtures/test-data";
|
||||
import {
|
||||
clearBrowserState,
|
||||
expectInsufficientCreditsDialog,
|
||||
expectVipChatSubscriptionUrl,
|
||||
signInWithEmailAndOpenChat,
|
||||
} from "../../fixtures/test-helpers";
|
||||
|
||||
@@ -44,5 +45,5 @@ test("user sees insufficient credits when unlocking a paid voice message and can
|
||||
.getByRole("button", { name: "Top up now" })
|
||||
.click();
|
||||
|
||||
await expect(page).toHaveURL(/\/subscription\?type=vip&returnTo=chat$/);
|
||||
await expectVipChatSubscriptionUrl(page);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user