e2e tests (#16533)
In this PR, - current basic E2E tests are fixed, and some were added, covering some basic scenarios - some tests avec been commented out, until we decide whether they are worth fixing The next steps are - evaluate the flakiness of the tests. Once they've proved not to be flaky, we should add more tests + re-write the current ones not using aria-label (cf @lucasbordeau indication). - We will add them back to the development flow
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import { type Page } from '@playwright/test';
|
||||
|
||||
const decodeToken = (cookie: any) =>
|
||||
JSON.parse(decodeURIComponent(cookie.value)).accessOrWorkspaceAgnosticToken
|
||||
?.token;
|
||||
|
||||
const decodePayload = (jwt: string) =>
|
||||
JSON.parse(Buffer.from(jwt.split('.')[1], 'base64url').toString());
|
||||
|
||||
|
||||
export const getAccessAuthToken = async (page: Page) => {
|
||||
const storageState = await page.context().storageState();
|
||||
const tokenCookies = storageState.cookies.filter(
|
||||
(cookie) => cookie.name === 'tokenPair',
|
||||
);
|
||||
if (!tokenCookies) {
|
||||
throw new Error('No auth cookie found');
|
||||
}
|
||||
const accessTokenCookie = tokenCookies.find(
|
||||
(cookie) => {
|
||||
const payload = decodePayload(decodeToken(cookie) ?? '');
|
||||
return payload.type === 'ACCESS';
|
||||
}
|
||||
);
|
||||
|
||||
const token = JSON.parse(decodeURIComponent(accessTokenCookie?.value ?? '')).accessOrWorkspaceAgnosticToken
|
||||
.token;
|
||||
|
||||
return { authToken: token };
|
||||
};
|
||||
Reference in New Issue
Block a user