Skip to content

Commit 2e9aa01

Browse files
authored
fix: e2e test - wait for session to load next step (calcom#23489)
* wait for session to load before navigating * use event-types testId to ensure session loaded * use profile page instead of eventTypes
1 parent 40d70cd commit 2e9aa01

2 files changed

Lines changed: 26 additions & 6 deletions

File tree

apps/web/playwright/booking-pages.e2e.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,10 +548,11 @@ test.describe("Booking round robin event", () => {
548548
users,
549549
}) => {
550550
const [testUser] = users.get();
551-
await testUser.apiLogin();
552551

553552
const team = await testUser.getFirstTeamMembership();
554553

554+
await testUser.apiLogin(`/team/${team.team.slug}`);
555+
555556
// Click first event type (round robin)
556557
await page.click('[data-testid="event-type-link"]');
557558

apps/web/playwright/fixtures/users.ts

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -657,8 +657,8 @@ const createUserFixture = (user: UserWithIncludes, page: Page) => {
657657
eventTypes: user.eventTypes,
658658
routingForms: user.routingForms,
659659
self,
660-
apiLogin: async (password?: string) =>
661-
apiLogin({ ...(await self()), password: password || user.username }, store.page),
660+
apiLogin: async (navigateToUrl?: string, password?: string) =>
661+
apiLogin({ ...(await self()), password: password || user.username }, store.page, navigateToUrl),
662662
/** Don't forget to close context at the end */
663663
apiLoginOnNewBrowser: async (browser: Browser, password?: string) => {
664664
const newContext = await browser.newContext();
@@ -969,25 +969,44 @@ export async function login(
969969

970970
export async function apiLogin(
971971
user: Pick<Prisma.User, "username"> & Partial<Pick<Prisma.User, "email">> & { password: string | null },
972-
page: Page
972+
page: Page,
973+
navigateToUrl?: string
973974
) {
975+
// Get CSRF token
974976
const csrfToken = await page
975977
.context()
976978
.request.get("/api/auth/csrf")
977979
.then((response) => response.json())
978980
.then((json) => json.csrfToken);
979-
const data = {
981+
982+
// Make the login request
983+
const loginData = {
980984
email: user.email ?? `${user.username}@example.com`,
981985
password: user.password ?? user.username,
982986
callbackURL: WEBAPP_URL,
983987
redirect: "false",
984988
json: "true",
985989
csrfToken,
986990
};
991+
987992
const response = await page.context().request.post("/api/auth/callback/credentials", {
988-
data,
993+
data: loginData,
989994
});
995+
990996
expect(response.status()).toBe(200);
997+
998+
/**
999+
* Critical: Navigate to a protected page to trigger NextAuth session loading
1000+
* This forces NextAuth to run the jwt and session callbacks that populate
1001+
* the session with profile, org, and other important data
1002+
* We picked /settings/my-account/profile due to it being one of
1003+
* our lighest protected pages and doesnt do anything other than load the user profile
1004+
*/
1005+
await page.goto(navigateToUrl || "/settings/my-account/profile");
1006+
1007+
// Wait for the session to be fully established
1008+
await page.waitForLoadState();
1009+
9911010
return response;
9921011
}
9931012

0 commit comments

Comments
 (0)