Skip to content

Commit 02ac49f

Browse files
chore: moving out user auth out into a util for E2E tests (#1181)
* chore: moving out from user auth out into a util * chore: missed some updates in the README * chore: adding logging to better understand why user setup is failing when pushed
1 parent 5a60d53 commit 02ac49f

File tree

14 files changed

+52
-98
lines changed

14 files changed

+52
-98
lines changed

.github/workflows/e2e-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
NEXTAUTH_SECRET: ${{ secrets.NEXTAUTH_SECRET }}
4747
E2E_USER_EMAIL: [email protected]
4848
E2E_USER_ID: 8e3179ce-f32b-4d0a-ba3b-234d66b836ad
49-
E2E_USER_SESSION_ID: df8a11f2-f20a-43d6-80a0-a213f1efedc1
49+
E2E_USER_ONE_SESSION_ID: df8a11f2-f20a-43d6-80a0-a213f1efedc1
5050

5151
steps:
5252
- name: Checkout repository

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ You shouldn't need to change the default value here. This is a variable used by
141141
NEXTAUTH_URL=http://localhost:3000/api/auth
142142
```
143143

144-
### E2E_USER_SESSION_ID
144+
### E2E_USER_ONE_SESSION_ID
145145

146-
This is the sessionToken uuid that .
146+
This is the sessionToken uuid that is used to identify a users current active session.
147147
This is currently hardcoded and there is no reason to change this until we require multiple E2E test users within the same test suite
148148

149149
### E2E_USER_ID
@@ -173,7 +173,7 @@ Please ensure you have the following variables set in your `.env` file:
173173

174174
- `E2E_USER_ID`: The id of the E2E user for testing.
175175
- `E2E_USER_EMAIL`: The email of the E2E user for testing.
176-
- `E2E_USER_SESSION_ID`: The session id that the user will use to authenticate.
176+
- `E2E_USER_ONE_SESSION_ID`: The session id that the user will use to authenticate.
177177

178178

179179
Note the sample .env [here](./sample.env) is fine to use.

drizzle/seed.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import postgres from "postgres";
1111
const DATABASE_URL = process.env.DATABASE_URL || "";
1212
// These can be removed in a follow on PR. Until this hits main we cant add E2E_USER_* stuff to the env.
1313
const E2E_SESSION_ID =
14-
process.env.E2E_USER_SESSION_ID || "df8a11f2-f20a-43d6-80a0-a213f1efedc1";
14+
process.env.E2E_USER_ONE_SESSION_ID || "df8a11f2-f20a-43d6-80a0-a213f1efedc1";
1515
const E2E_USER_ID =
1616
process.env.E2E_USER_ID || "8e3179ce-f32b-4d0a-ba3b-234d66b836ad";
1717
const E2E_USER_EMAIL = process.env.E2E_USER_EMAIL || "[email protected]";

e2e/articles.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import { test, expect } from "playwright/test";
22
import { randomUUID } from "crypto";
3+
import { loggedInAsUserOne } from "./utils";
34

45
test.describe("Unauthenticated Articles Page", () => {
5-
test.beforeEach(async ({ page }) => {
6-
await page.context().clearCookies();
7-
});
8-
96
test("Should show popular tags", async ({ page, isMobile }) => {
107
await page.goto("http://localhost:3000/articles");
118
await expect(
@@ -133,6 +130,9 @@ test.describe("Unauthenticated Articles Page", () => {
133130
});
134131

135132
test.describe("Authenticated Articles Page", () => {
133+
test.beforeEach(async ({ page }) => {
134+
await loggedInAsUserOne(page);
135+
});
136136
test("Should show recent bookmarks", async ({ page, isMobile }) => {
137137
await page.goto("http://localhost:3000/articles");
138138
await expect(

e2e/auth.setup.ts

Lines changed: 0 additions & 54 deletions
This file was deleted.

e2e/home.spec.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { test, expect } from "@playwright/test";
2+
import { loggedInAsUserOne } from "./utils";
23

34
test.describe("Authenticated homepage", () => {
5+
test.beforeEach(async ({ page }) => {
6+
await loggedInAsUserOne(page);
7+
});
48
test("Homepage view", async ({ page, isMobile }) => {
59
await page.goto("http://localhost:3000/");
610

@@ -24,9 +28,6 @@ test.describe("Authenticated homepage", () => {
2428
});
2529

2630
test.describe("Unauthenticated homepage", () => {
27-
test.beforeEach(async ({ page }) => {
28-
await page.context().clearCookies();
29-
});
3031
test("Homepage view", async ({ page }) => {
3132
await page.goto("http://localhost:3000/");
3233

e2e/login.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { test, expect } from "playwright/test";
22
import "dotenv/config";
3+
import { loggedInAsUserOne } from "./utils";
34

45
test.describe("Unauthenticated Login Page", () => {
56
test.beforeEach(async ({ page }) => {
@@ -31,6 +32,9 @@ test.describe("Unauthenticated Login Page", () => {
3132
});
3233

3334
test.describe("Authenticated Login Page", () => {
35+
test.beforeEach(async ({ page }) => {
36+
await loggedInAsUserOne(page);
37+
});
3438
test("Sign up page contains sign up links", async ({ page, isMobile }) => {
3539
// authenticated users are kicked back to the homepage if they try to go to /get-started
3640
await page.goto("http://localhost:3000/get-started");

e2e/my-posts.spec.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import test from "@playwright/test";
2+
import { loggedInAsUserOne } from "./utils";
23

34
test.describe("Unauthenticated my-posts Page", () => {
4-
test.beforeEach(async ({ page }) => {
5-
await page.context().clearCookies();
6-
});
75
//
86
// Replace with tests for unauthenticated users
97
});
108

119
test.describe("Authenticated my-posts Page", () => {
10+
test.beforeEach(async ({ page }) => {
11+
await loggedInAsUserOne(page);
12+
});
1213
//
1314
// Replace with tests for authenticated users
1415
});

e2e/settings.spec.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import test from "@playwright/test";
2+
import { loggedInAsUserOne } from "./utils";
23

34
test.describe("Unauthenticated setttings Page", () => {
4-
test.beforeEach(async ({ page }) => {
5-
await page.context().clearCookies();
6-
});
75
//
86
// Replace with tests for unauthenticated users
97
});
108

119
test.describe("Authenticated settings Page", () => {
10+
test.beforeEach(async ({ page }) => {
11+
await loggedInAsUserOne(page);
12+
});
1213
//
1314
// Replace with tests for authenticated users
1415
});

e2e/utils/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./utils";

0 commit comments

Comments
 (0)