Skip to content

Commit dd6a37f

Browse files
committed
test: do not use admin user as test user
1 parent 5c1ece4 commit dd6a37f

File tree

7 files changed

+53
-9
lines changed

7 files changed

+53
-9
lines changed

e2e/README.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
# Notes about e2e tests
22

33
When writing new spec file, make sure to import the test function from the fixtures file, like this:
4+
```ts
5+
import { teacherTest as test } from './fixtures'
46
```
5-
import { test } from './fixtures'
7+
8+
So that the global foreach function runs for your tests. For different user roles (`studentTest`, `teacherTest`, `adminTest`), import the corresponding test function:
9+
```ts
10+
import { studentTest as test } from './fixtures'
611
```
7-
.
812

9-
So that the global foreach function runs for your tests.
13+
## Test setup and data
14+
15+
Test user headers are defined in `src/shared/testData.ts`. TEST_COURSES are also defined there.
16+
17+
Before each test, the test data of a test user is reset by calling the `/test/reset-test-data` endpoint. It is found at `src/server/routes/testUtils.ts`.
18+
19+
When running the tests, the headers `x-test-user-idx` and `x-test-user-role` are set, defining the test user's id and iam-based role. They are read at `src/server/middleware/user.ts`.
20+
21+
The tests are isolated so that each (should at least) modifies their own data discriminated by the user's id. This allows parallel execution.

e2e/chat.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect } from '@playwright/test'
22
import { acceptDisclaimer } from './utils/test-helpers'
3-
import { test } from './fixtures'
3+
import { teacherTest as test } from './fixtures'
44

55
test.describe('Chat v2 Conversation tests', () => {
66
test.beforeEach(async ({ page }) => {

e2e/chatFeatures.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect } from '@playwright/test'
22
import { acceptDisclaimer } from './utils/test-helpers'
3-
import { test } from './fixtures'
3+
import { teacherTest as test } from './fixtures'
44

55
test.describe('Chat v2 UI Features Tests', () => {
66
test.beforeEach(async ({ page }) => {

e2e/courseChatRag.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect } from '@playwright/test'
22
import { acceptDisclaimer } from './utils/test-helpers'
3-
import { test } from './fixtures'
3+
import { studentTest as test } from './fixtures'
44

55
test.describe('Course Chat v2', () => {
66
test.beforeEach(async ({ page }) => {

e2e/fixtures.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { test as base } from '@playwright/test'
22
import { setupLogging } from './utils/logging'
33

4-
export const test = base.extend<{ forEachTest: void }>({
4+
export const adminTest = base.extend<{ forEachTest: void }>({
55
forEachTest: [
66
async ({ page, request }, use) => {
77
// This code runs before every test.
@@ -32,6 +32,37 @@ export const test = base.extend<{ forEachTest: void }>({
3232
], // automatically starts for every test.
3333
})
3434

35+
export const teacherTest = base.extend<{ forEachTest: void }>({
36+
forEachTest: [
37+
async ({ page, request }, use) => {
38+
// This code runs before every test.
39+
40+
// setupLogging(page)
41+
42+
/*
43+
* Parallel worker isolation: each worker has its own test user identified by the worker index.
44+
*/
45+
46+
const testUserIdx = studentTest.info().workerIndex
47+
const testUserRole = 'teacher'
48+
49+
page.context().setExtraHTTPHeaders({
50+
'x-test-user-index': String(testUserIdx),
51+
'x-test-user-role': testUserRole,
52+
})
53+
54+
await request.post('/api/test/reset-test-data', { data: { testUserIdx, testUserRole } })
55+
56+
// Run the test
57+
await use()
58+
59+
// This code runs after every test.
60+
// console.log('Last URL:', page.url());
61+
},
62+
{ auto: true },
63+
], // automatically starts for every test.
64+
})
65+
3566
export const studentTest = base.extend<{ forEachTest: void }>({
3667
forEachTest: [
3768
async ({ page, request }, use) => {

e2e/healthcheck.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { test, expect } from '@playwright/test'
1+
import { expect } from '@playwright/test'
2+
import { studentTest as test } from './fixtures'
23

34
test.describe('Health Check Tests', () => {
45
test.beforeEach(async ({ page }) => {})

e2e/prompts.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { test } from './fixtures'
21
import { expect } from '@playwright/test'
2+
import { teacherTest as test } from './fixtures'
33
import { acceptDisclaimer } from './utils/test-helpers'
44

55
test.describe('Prompts', () => {

0 commit comments

Comments
 (0)