Skip to content

Commit 5e35f32

Browse files
committed
feat(seed): add function to seed assignment chain for Playwright test users
1 parent 3587a76 commit 5e35f32

2 files changed

Lines changed: 56 additions & 1 deletion

File tree

packages/frontend/e2e/helpers/global-setup.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
import axios from 'axios';
2222
import { apiLogin } from './auth.helper';
23-
import { seedPlaywrightUsers } from './seed.helper';
23+
import { seedPlaywrightUsers, seedPlaywrightAssignments } from './seed.helper';
2424

2525
const BACKEND_URL = process.env.BACKEND_URL ?? 'http://localhost:3000';
2626
const FRONTEND_URL = process.env.FRONTEND_URL ?? 'http://localhost:3001';
@@ -63,5 +63,8 @@ export default async function globalSetup(): Promise<void> {
6363
// 4. Seed all Playwright-specific test users (idempotent — skips 409s)
6464
await seedPlaywrightUsers(accessToken);
6565

66+
// 5. Seed assignment chain: uploader → validator → approver (idempotent)
67+
await seedPlaywrightAssignments(accessToken);
68+
6669
console.log('[global-setup] Done — Playwright users are ready');
6770
}

packages/frontend/e2e/helpers/seed.helper.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,55 @@ export async function seedPlaywrightUsers(
6868
}
6969
}
7070
}
71+
72+
/**
73+
* Seed the full assignment chain for Playwright test users:
74+
* pw-uploader → pw-validator → pw-approver
75+
*
76+
* Idempotent: 409 Conflict means assignment already exists, skip.
77+
*/
78+
export async function seedPlaywrightAssignments(
79+
adminToken: string,
80+
): Promise<void> {
81+
const headers = { Authorization: `Bearer ${adminToken}` };
82+
83+
// Fetch user IDs by role
84+
const usersRes = await axios.get<{
85+
data: Array<{ id: string; email: string; role: string }>;
86+
}>(`${BACKEND_URL}/admin/users`, { headers });
87+
const users = usersRes.data.data;
88+
89+
const uploader = users.find((u) => u.email === PLAYWRIGHT_USERS.uploader.email);
90+
const validator = users.find((u) => u.email === PLAYWRIGHT_USERS.validator.email);
91+
const approver = users.find((u) => u.email === PLAYWRIGHT_USERS.approver.email);
92+
93+
if (!uploader || !validator || !approver) {
94+
throw new Error('[seed] Could not find all Playwright users to create assignments');
95+
}
96+
97+
// uploader → validator
98+
try {
99+
await axios.post(
100+
`${BACKEND_URL}/admin/assignments/uploaders`,
101+
{ uploaderId: uploader.id, validatorId: validator.id },
102+
{ headers },
103+
);
104+
} catch (err) {
105+
if (axios.isAxiosError(err) && err.response?.status === 409) {
106+
// already assigned
107+
} else throw err;
108+
}
109+
110+
// validator → approver
111+
try {
112+
await axios.post(
113+
`${BACKEND_URL}/admin/assignments/validators`,
114+
{ validatorId: validator.id, approverId: approver.id },
115+
{ headers },
116+
);
117+
} catch (err) {
118+
if (axios.isAxiosError(err) && err.response?.status === 409) {
119+
// already assigned
120+
} else throw err;
121+
}
122+
}

0 commit comments

Comments
 (0)