-
-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: removed all e2e env variables and migrated them to constants f…
…ile (#1189)
- Loading branch information
1 parent
60267e5
commit 517763f
Showing
9 changed files
with
36 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
|
||
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"; | ||
|
||
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"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./constants"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"), | ||
); | ||
|
||
const addE2EArticleAndComment = async ( | ||
authorId: string, | ||
|
@@ -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); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
|
||
// 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 | ||
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"); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
||
E2E_USER_EMAIL=[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 |