Skip to content

Commit 48cc3d4

Browse files
committed
chore: removed all e2e env variables and migrated them to constants file
1 parent 60267e5 commit 48cc3d4

File tree

9 files changed

+36
-72
lines changed

9 files changed

+36
-72
lines changed

.github/workflows/e2e-tests.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,6 @@ jobs:
4444
GITHUB_ID: ${{ secrets.E2E_GITHUB_ID }}
4545
GITHUB_SECRET: ${{ secrets.E2E_GITHUB_SECRET }}
4646
NEXTAUTH_SECRET: ${{ secrets.NEXTAUTH_SECRET }}
47-
E2E_USER_ONE_EMAIL: e2e-user-one@codu.co
48-
E2E_USER_ONE_ID: 8e3179ce-f32b-4d0a-ba3b-234d66b836ad
49-
E2E_USER_ONE_SESSION_ID: df8a11f2-f20a-43d6-80a0-a213f1efedc1
50-
E2E_USER_TWO_EMAIL: e2e-user-two@codu.co
51-
E2E_USER_TWO_ID: a15a104a-0e34-4101-8800-ed25c9231345
52-
E2E_USER_TWO_SESSION_ID: 10134766-bc6c-4b52-83d7-46ec0a4cb95d
5347

5448
steps:
5549
- name: Checkout repository

E2E Overview.md

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,7 @@
22

33
To run the end-to-end tests using Playwright, you need to configure your environment and follow these steps:
44

5-
### Environment Variables
65

7-
Ensure you have the following variables set in your `.env` file:
8-
9-
- `E2E_USER_ID`: The ID of the E2E user for testing.
10-
- `E2E_USER_EMAIL`: The email of the E2E user for testing.
11-
- `E2E_USER_ONE_SESSION_ID`: The session ID that the user will use to authenticate.
12-
13-
Note: The sample `.env` file is fine to use.
146

157
### Session and User Setup
168

@@ -38,11 +30,9 @@ For UI mode:
3830
npx playwright test --ui
3931
```
4032

41-
### Additional E2E Environment Variables
33+
### Additional E2E constants
4234

4335
- **E2E_USER_ONE_SESSION_ID**: This is the session token UUID for one E2E user.
4436
- **E2E_USER_TWO_SESSION_ID**: This is the session token UUID for another E2E user.
4537
- **E2E_USER_ONE_ID**: The user ID of one of the E2E users.
4638
- **E2E_USER_TWO_ID**: The user ID of another E2E user.
47-
48-
These values are currently hardcoded and should be unique for each user.

drizzle/seed.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,16 @@ import "dotenv/config";
77

88
import { drizzle, type PostgresJsDatabase } from "drizzle-orm/postgres-js";
99
import postgres from "postgres";
10+
import {
11+
E2E_USER_ONE_EMAIL,
12+
E2E_USER_ONE_ID,
13+
E2E_USER_TWO_EMAIL,
14+
E2E_USER_TWO_ID,
15+
E2E_USER_ONE_SESSION_ID,
16+
E2E_USER_TWO_SESSION_ID,
17+
} from "../e2e/constants";
1018

1119
const DATABASE_URL = process.env.DATABASE_URL || "";
12-
// These can be removed in a follow on PR. Until this hits main we cant add E2E_USER_* stuff to the env.
13-
const E2E_USER_ONE_SESSION_ID =
14-
process.env.E2E_USER_ONE_SESSION_ID || "df8a11f2-f20a-43d6-80a0-a213f1efedc1";
15-
const E2E_USER_ONE_ID =
16-
process.env.E2E_USER_ONE_ID || "8e3179ce-f32b-4d0a-ba3b-234d66b836ad";
17-
const E2E_USER_ONE_EMAIL =
18-
process.env.E2E_USER_ONE_EMAIL || "e2e-user-one@codu.co";
19-
20-
const E2E_USER_TWO_SESSION_ID =
21-
process.env.E2E_USER_TWO_SESSION_ID || "10134766-bc6c-4b52-83d7-46ec0a4cb95d";
22-
const E2E_USER_TWO_ID =
23-
process.env.E2E_USER_TWO_ID || "a15a104a-0e34-4101-8800-ed25c9231345";
24-
const E2E_USER_TWO_EMAIL =
25-
process.env.E2E_USER_TWO_EMAIL || "e2e-user-two@codu.co";
2620

2721
if (!DATABASE_URL) {
2822
throw new Error("DATABASE_URL is not set");

e2e/constants/constants.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export const articleContent =
2+
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas vitae ipsum id metus vestibulum rutrum eget a diam. Integer eget vulputate risus, ac convallis nulla. Mauris sed augue nunc. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nam congue posuere tempor. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Ut ac augue non libero ullamcorper ornare. Ut commodo ligula vitae malesuada maximus. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Etiam sagittis justo non justo placerat, a dapibus sapien volutpat. Nullam ullamcorper sodales justo sed.";
3+
4+
export const articleExcerpt = "Lorem ipsum dolor sit amet";
5+
6+
export const E2E_USER_ONE_EMAIL = "e2e@codu.co";
7+
export const E2E_USER_ONE_ID = "8e3179ce-f32b-4d0a-ba3b-234d66b836ad";
8+
export const E2E_USER_ONE_SESSION_ID = "df8a11f2-f20a-43d6-80a0-a213f1efedc1";
9+
10+
export const E2E_USER_TWO_EMAIL = "e2e-user-two@codu.co";
11+
export const E2E_USER_TWO_ID = "a15a104a-0e34-4101-8800-ed25c9231345";
12+
export const E2E_USER_TWO_SESSION_ID = "10134766-bc6c-4b52-83d7-46ec0a4cb95d";

e2e/constants/index.ts

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

e2e/setup.ts

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
1-
import dotenv from "dotenv";
21
import postgres from "postgres";
32
import { drizzle } from "drizzle-orm/postgres-js";
43
import { post, comment } from "@/server/db/schema";
5-
6-
dotenv.config(); // Load .env file contents into process.env
4+
import { E2E_USER_ONE_ID, E2E_USER_TWO_ID } from "./constants";
75

86
export const setup = async () => {
9-
if (
10-
!process.env.DATABASE_URL ||
11-
!process.env.E2E_USER_ONE_ID ||
12-
!process.env.E2E_USER_TWO_ID
13-
) {
14-
throw new Error("Missing env variables for DB clean up script");
15-
}
16-
const db = drizzle(postgres(process.env.DATABASE_URL as string));
7+
const db = drizzle(
8+
postgres("postgresql://postgres:secret@127.0.0.1:5432/postgres"),
9+
);
1710

1811
const addE2EArticleAndComment = async (
1912
authorId: string,
@@ -52,10 +45,7 @@ export const setup = async () => {
5245
try {
5346
console.log("creating articles");
5447

55-
await addE2EArticleAndComment(
56-
process.env.E2E_USER_ONE_ID as string,
57-
process.env.E2E_USER_TWO_ID as string,
58-
);
48+
await addE2EArticleAndComment(E2E_USER_ONE_ID, E2E_USER_TWO_ID);
5949
console.log("DB setup successful");
6050
} catch (err) {
6151
console.log("Error while setting up DB before E2E test run", err);

e2e/teardown.ts

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,23 @@
1-
import dotenv from "dotenv";
21
import postgres from "postgres";
3-
4-
dotenv.config(); // Load .env file contents into process.env
2+
import { E2E_USER_ONE_ID, E2E_USER_TWO_ID } from "./constants";
53

64
export const teardown = async () => {
75
try {
8-
if (
9-
!process.env.DATABASE_URL ||
10-
!process.env.E2E_USER_ONE_ID ||
11-
!process.env.E2E_USER_TWO_ID
12-
)
13-
throw new Error("Missing env variables for DB clean up script");
14-
const db = postgres(process.env.DATABASE_URL as string);
6+
const db = postgres("postgresql://postgres:secret@127.0.0.1:5432/postgres");
157

168
// the test suit adds posts created by the E2E users. We want to remove them between test runs
179
await db`
18-
DELETE FROM "Post" WHERE "userId" = ${process.env.E2E_USER_ONE_ID as string}
10+
DELETE FROM "Post" WHERE "userId" = ${E2E_USER_ONE_ID}
1911
`;
2012
await db`
21-
DELETE FROM "Post" WHERE "userId" = ${process.env.E2E_USER_TWO_ID as string}
13+
DELETE FROM "Post" WHERE "userId" = ${E2E_USER_TWO_ID}
2214
`;
2315
// the test suit adds comments created by the E2E user. We want to remove them between test runs
2416
await db`
25-
DELETE FROM "Comment" WHERE "userId" = ${process.env.E2E_USER_ONE_ID as string}
17+
DELETE FROM "Comment" WHERE "userId" = ${E2E_USER_ONE_ID}
2618
`;
2719
await db`
28-
DELETE FROM "Comment" WHERE "userId" = ${process.env.E2E_USER_TWO_ID as string}
20+
DELETE FROM "Comment" WHERE "userId" = ${E2E_USER_TWO_ID}
2921
`;
3022

3123
console.log("DB clean up successful");

e2e/utils/utils.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import { expect, Page } from "@playwright/test";
2+
import { E2E_USER_ONE_SESSION_ID, E2E_USER_TWO_SESSION_ID } from "../constants";
23

34
export const loggedInAsUserOne = async (page: Page) => {
45
try {
5-
expect(process.env.E2E_USER_ONE_SESSION_ID).toBeDefined();
6-
76
await page.context().addCookies([
87
{
98
name: "next-auth.session-token",
10-
value: process.env.E2E_USER_ONE_SESSION_ID as string,
9+
value: E2E_USER_ONE_SESSION_ID,
1110
domain: "localhost",
1211
path: "/",
1312
sameSite: "Lax",
@@ -26,14 +25,12 @@ export const loggedInAsUserOne = async (page: Page) => {
2625

2726
export const loggedInAsUserTwo = async (page: Page) => {
2827
try {
29-
expect(process.env.E2E_USER_TWO_SESSION_ID).toBeDefined();
30-
3128
await page.context().clearCookies();
3229

3330
await page.context().addCookies([
3431
{
3532
name: "next-auth.session-token",
36-
value: process.env.E2E_USER_TWO_SESSION_ID as string,
33+
value: E2E_USER_TWO_SESSION_ID,
3734
domain: "localhost",
3835
path: "/",
3936
sameSite: "Lax",

sample.env

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,3 @@ GITLAB_ID= ### Replace with GitLab OAuth ID (https://gitlab.com/-/user_settings
44
GITLAB_SECRET= ### Replace with GitLab OAuth Secret (https://gitlab.com/-/user_settings/applications)
55
NEXTAUTH_URL=http://localhost:3000/api/auth
66
DATABASE_URL=postgresql://postgres:secret@127.0.0.1:5432/postgres
7-
8-
E2E_USER_EMAIL=e2e@codu.co
9-
E2E_USER_ONE_ID=8e3179ce-f32b-4d0a-ba3b-234d66b836ad
10-
E2E_USER_TWO_ID=a15a104a-0e34-4101-8800-ed25c9231345
11-
E2E_USER_ONE_SESSION_ID=df8a11f2-f20a-43d6-80a0-a213f1efedc1
12-
E2E_USER_TWO_SESSION_ID=10134766-bc6c-4b52-83d7-46ec0a4cb95d

0 commit comments

Comments
 (0)