Skip to content

Commit 4d329a3

Browse files
committed
add get project auth
1 parent 640550a commit 4d329a3

2 files changed

Lines changed: 21 additions & 4 deletions

File tree

testing/e2e/src/1.1-auth.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ test.describe('login page', () => {
2424
const response = await loginResponsePromise;
2525
const body = await response.json();
2626
expect(typeof body.accessToken).toBe('string');
27-
setProjectAuth({ accessToken: body.accessToken as string } satisfies ProjectAuth);
27+
28+
await setProjectAuth({ accessToken: body.accessToken as string } satisfies ProjectAuth);
2829
});
2930
});

testing/e2e/src/helpers/fixtures.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ type TestArgs = {
2121
};
2222

2323
type WorkerArgs = {
24+
getProjectAuth: () => Promise<ProjectAuth>;
2425
getProjectMetadata: <TKey extends Extract<keyof ProjectMetadata, string>>(key: TKey) => ProjectMetadata[TKey];
25-
setProjectAuth: (auth: ProjectAuth) => void;
26+
setProjectAuth: (auth: ProjectAuth) => Promise<void>;
2627
};
2728

2829
const pageModels = {
@@ -42,6 +43,18 @@ export const test = base.extend<TestArgs, WorkerArgs>({
4243
}
4344
);
4445
},
46+
getProjectAuth: [
47+
async ({ getProjectMetadata }, use) => {
48+
return use(async () => {
49+
const authStorageFile = getProjectMetadata('authStorageFile');
50+
if (!fs.existsSync(authStorageFile)) {
51+
throw new Error(`Cannot get project auth: storage file does not exist: ${authStorageFile}`);
52+
}
53+
return JSON.parse(await fs.promises.readFile(authStorageFile, 'utf8')) as ProjectAuth;
54+
});
55+
},
56+
{ scope: 'worker' }
57+
],
4558
getProjectMetadata: [
4659
async ({}, use, workerInfo) => {
4760
return use((key) => {
@@ -52,9 +65,12 @@ export const test = base.extend<TestArgs, WorkerArgs>({
5265
],
5366
setProjectAuth: [
5467
async ({ getProjectMetadata }, use) => {
55-
return use((auth) => {
68+
return use(async (auth) => {
5669
const authStorageFile = getProjectMetadata('authStorageFile');
57-
fs.writeFileSync(authStorageFile, JSON.stringify(auth, null, 2), 'utf-8');
70+
if (fs.existsSync(authStorageFile)) {
71+
throw new Error(`Cannot set project auth: storage file already exists: ${authStorageFile}`);
72+
}
73+
await fs.promises.writeFile(authStorageFile, JSON.stringify(auth, null, 2), 'utf-8');
5874
});
5975
},
6076
{ scope: 'worker' }

0 commit comments

Comments
 (0)