Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: removed all e2e env variables and migrated them to constants file #1189

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@ jobs:
GITHUB_ID: ${{ secrets.E2E_GITHUB_ID }}
GITHUB_SECRET: ${{ secrets.E2E_GITHUB_SECRET }}
NEXTAUTH_SECRET: ${{ secrets.NEXTAUTH_SECRET }}
E2E_USER_ONE_EMAIL: [email protected]
E2E_USER_ONE_ID: 8e3179ce-f32b-4d0a-ba3b-234d66b836ad
E2E_USER_ONE_SESSION_ID: df8a11f2-f20a-43d6-80a0-a213f1efedc1
E2E_USER_TWO_EMAIL: [email protected]
E2E_USER_TWO_ID: a15a104a-0e34-4101-8800-ed25c9231345
E2E_USER_TWO_SESSION_ID: 10134766-bc6c-4b52-83d7-46ec0a4cb95d

steps:
- name: Checkout repository
Expand Down
12 changes: 1 addition & 11 deletions E2E Overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,7 @@

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

### Environment Variables

Ensure you have the following variables set in your `.env` file:

- `E2E_USER_ID`: The ID of the E2E user for testing.
- `E2E_USER_EMAIL`: The email of the E2E user for testing.
- `E2E_USER_ONE_SESSION_ID`: The session ID that the user will use to authenticate.

Note: The sample `.env` file is fine to use.

### Session and User Setup

Expand Down Expand Up @@ -38,11 +30,9 @@ For UI mode:
npx playwright test --ui
```

### Additional E2E Environment Variables
### Additional E2E constants

- **E2E_USER_ONE_SESSION_ID**: This is the session token UUID for one E2E user.
- **E2E_USER_TWO_SESSION_ID**: This is the session token UUID for another E2E user.
- **E2E_USER_ONE_ID**: The user ID of one of the E2E users.
- **E2E_USER_TWO_ID**: The user ID of another E2E user.

These values are currently hardcoded and should be unique for each user.
22 changes: 8 additions & 14 deletions drizzle/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,16 @@ import "dotenv/config";

import { drizzle, type PostgresJsDatabase } from "drizzle-orm/postgres-js";
import postgres from "postgres";
import {
E2E_USER_ONE_EMAIL,
E2E_USER_ONE_ID,
E2E_USER_TWO_EMAIL,
E2E_USER_TWO_ID,
E2E_USER_ONE_SESSION_ID,
E2E_USER_TWO_SESSION_ID,
} from "../e2e/constants";

const DATABASE_URL = process.env.DATABASE_URL || "";
// These can be removed in a follow on PR. Until this hits main we cant add E2E_USER_* stuff to the env.
const E2E_USER_ONE_SESSION_ID =
process.env.E2E_USER_ONE_SESSION_ID || "df8a11f2-f20a-43d6-80a0-a213f1efedc1";
const E2E_USER_ONE_ID =
process.env.E2E_USER_ONE_ID || "8e3179ce-f32b-4d0a-ba3b-234d66b836ad";
const E2E_USER_ONE_EMAIL =
process.env.E2E_USER_ONE_EMAIL || "[email protected]";

const E2E_USER_TWO_SESSION_ID =
process.env.E2E_USER_TWO_SESSION_ID || "10134766-bc6c-4b52-83d7-46ec0a4cb95d";
const E2E_USER_TWO_ID =
process.env.E2E_USER_TWO_ID || "a15a104a-0e34-4101-8800-ed25c9231345";
const E2E_USER_TWO_EMAIL =
process.env.E2E_USER_TWO_EMAIL || "[email protected]";

if (!DATABASE_URL) {
throw new Error("DATABASE_URL is not set");
Expand Down
12 changes: 12 additions & 0 deletions e2e/constants/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const articleContent =
"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.";

export const articleExcerpt = "Lorem ipsum dolor sit amet";
JohnAllenTech marked this conversation as resolved.
Show resolved Hide resolved

export const E2E_USER_ONE_EMAIL = "[email protected]";
export const E2E_USER_ONE_ID = "8e3179ce-f32b-4d0a-ba3b-234d66b836ad";
export const E2E_USER_ONE_SESSION_ID = "df8a11f2-f20a-43d6-80a0-a213f1efedc1";
JohnAllenTech marked this conversation as resolved.
Show resolved Hide resolved

export const E2E_USER_TWO_EMAIL = "[email protected]";
export const E2E_USER_TWO_ID = "a15a104a-0e34-4101-8800-ed25c9231345";
export const E2E_USER_TWO_SESSION_ID = "10134766-bc6c-4b52-83d7-46ec0a4cb95d";
1 change: 1 addition & 0 deletions e2e/constants/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./constants";
20 changes: 5 additions & 15 deletions e2e/setup.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
import dotenv from "dotenv";
import postgres from "postgres";
import { drizzle } from "drizzle-orm/postgres-js";
import { post, comment } from "@/server/db/schema";

dotenv.config(); // Load .env file contents into process.env
import { E2E_USER_ONE_ID, E2E_USER_TWO_ID } from "./constants";

export const setup = async () => {
if (
!process.env.DATABASE_URL ||
!process.env.E2E_USER_ONE_ID ||
!process.env.E2E_USER_TWO_ID
) {
throw new Error("Missing env variables for DB clean up script");
}
const db = drizzle(postgres(process.env.DATABASE_URL as string));
const db = drizzle(
postgres("postgresql://postgres:[email protected]:5432/postgres"),
);

JohnAllenTech marked this conversation as resolved.
Show resolved Hide resolved
const addE2EArticleAndComment = async (
authorId: string,
Expand Down Expand Up @@ -52,10 +45,7 @@ export const setup = async () => {
try {
console.log("creating articles");

await addE2EArticleAndComment(
process.env.E2E_USER_ONE_ID as string,
process.env.E2E_USER_TWO_ID as string,
);
await addE2EArticleAndComment(E2E_USER_ONE_ID, E2E_USER_TWO_ID);
console.log("DB setup successful");
} catch (err) {
console.log("Error while setting up DB before E2E test run", err);
Expand Down
20 changes: 6 additions & 14 deletions e2e/teardown.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,23 @@
import dotenv from "dotenv";
import postgres from "postgres";

dotenv.config(); // Load .env file contents into process.env
import { E2E_USER_ONE_ID, E2E_USER_TWO_ID } from "./constants";

export const teardown = async () => {
try {
if (
!process.env.DATABASE_URL ||
!process.env.E2E_USER_ONE_ID ||
!process.env.E2E_USER_TWO_ID
)
throw new Error("Missing env variables for DB clean up script");
const db = postgres(process.env.DATABASE_URL as string);
const db = postgres("postgresql://postgres:[email protected]:5432/postgres");

JohnAllenTech marked this conversation as resolved.
Show resolved Hide resolved
// the test suit adds posts created by the E2E users. We want to remove them between test runs
await db`
DELETE FROM "Post" WHERE "userId" = ${process.env.E2E_USER_ONE_ID as string}
DELETE FROM "Post" WHERE "userId" = ${E2E_USER_ONE_ID}
`;
await db`
DELETE FROM "Post" WHERE "userId" = ${process.env.E2E_USER_TWO_ID as string}
DELETE FROM "Post" WHERE "userId" = ${E2E_USER_TWO_ID}
`;
// the test suit adds comments created by the E2E user. We want to remove them between test runs
JohnAllenTech marked this conversation as resolved.
Show resolved Hide resolved
await db`
DELETE FROM "Comment" WHERE "userId" = ${process.env.E2E_USER_ONE_ID as string}
DELETE FROM "Comment" WHERE "userId" = ${E2E_USER_ONE_ID}
`;
await db`
DELETE FROM "Comment" WHERE "userId" = ${process.env.E2E_USER_TWO_ID as string}
DELETE FROM "Comment" WHERE "userId" = ${E2E_USER_TWO_ID}
`;

console.log("DB clean up successful");
Expand Down
9 changes: 3 additions & 6 deletions e2e/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { expect, Page } from "@playwright/test";
import { E2E_USER_ONE_SESSION_ID, E2E_USER_TWO_SESSION_ID } from "../constants";

export const loggedInAsUserOne = async (page: Page) => {
try {
expect(process.env.E2E_USER_ONE_SESSION_ID).toBeDefined();

await page.context().addCookies([
{
name: "next-auth.session-token",
value: process.env.E2E_USER_ONE_SESSION_ID as string,
value: E2E_USER_ONE_SESSION_ID,
domain: "localhost",
path: "/",
sameSite: "Lax",
Expand All @@ -26,14 +25,12 @@ export const loggedInAsUserOne = async (page: Page) => {

export const loggedInAsUserTwo = async (page: Page) => {
try {
expect(process.env.E2E_USER_TWO_SESSION_ID).toBeDefined();

await page.context().clearCookies();

await page.context().addCookies([
{
name: "next-auth.session-token",
value: process.env.E2E_USER_TWO_SESSION_ID as string,
value: E2E_USER_TWO_SESSION_ID,
domain: "localhost",
path: "/",
sameSite: "Lax",
Expand Down
6 changes: 0 additions & 6 deletions sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,3 @@ GITLAB_ID= ### Replace with GitLab OAuth ID (https://gitlab.com/-/user_settings
GITLAB_SECRET= ### Replace with GitLab OAuth Secret (https://gitlab.com/-/user_settings/applications)
NEXTAUTH_URL=http://localhost:3000/api/auth
DATABASE_URL=postgresql://postgres:[email protected]:5432/postgres

[email protected]
E2E_USER_ONE_ID=8e3179ce-f32b-4d0a-ba3b-234d66b836ad
E2E_USER_TWO_ID=a15a104a-0e34-4101-8800-ed25c9231345
E2E_USER_ONE_SESSION_ID=df8a11f2-f20a-43d6-80a0-a213f1efedc1
E2E_USER_TWO_SESSION_ID=10134766-bc6c-4b52-83d7-46ec0a4cb95d
Loading