Skip to content

Commit 6779f1c

Browse files
committed
debug lines in loginHelpers
1 parent 07b6796 commit 6779f1c

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

tests/helpers/loginHelpers.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,25 @@ export const logInWithUsernameAndPassword = async (
4747
await passwordField.press("Enter");
4848

4949
await expect(async () => {
50-
expect(page.url()).toBe(
50+
expect(page.url()).toContain(
5151
`${process.env.BASE_URL}/insights/content/repositories`
5252
);
5353
}).toPass();
5454
};
5555

5656
export const switchToUser = async (page: Page, userName: string) => {
57+
const storagePath = path.join(__dirname, `../../.auth/${userName}.json`);
5758
const { cookies } = await page.context().storageState({
58-
path: path.join(__dirname, `../../.auth/${userName}.json`),
59+
path: storagePath,
5960
});
60-
process.env.TOKEN = `Bearer ${
61-
cookies.find((cookie) => cookie.name === "cs_jwt")?.value
62-
}`;
61+
62+
const jwtCookie = cookies.find((cookie) => cookie.name === "cs_jwt");
63+
64+
if (!jwtCookie || !jwtCookie.value) {
65+
throw new Error(`No valid cs_jwt cookie found in storage state for user ${userName} at ${storagePath}`);
66+
}
67+
68+
process.env.TOKEN = `Bearer ${jwtCookie.value}`;
6369
await page.waitForTimeout(100);
6470
};
6571

0 commit comments

Comments
 (0)