-
-
Notifications
You must be signed in to change notification settings - Fork 173
Feat/multiple user support in e2e tests #1182
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
Merged
NiallJoeMaher
merged 7 commits into
codu-code:develop
from
JohnAllenTech:feat/multiple-user-support-in-e2e-tests
Oct 28, 2024
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
02aabfe
chore: moving out from user auth out into a util
JohnAllenTech 984b47d
chore: missed some updates in the README
JohnAllenTech 168f007
chore: split out e2e user creation/seeding to support two e2e users i…
JohnAllenTech eb1276e
Merge branch 'develop' into feat/multiple-user-support-in-e2e-tests
JohnAllenTech c089605
Update README.md
JohnAllenTech a2f1d34
Merge branch 'develop' into feat/multiple-user-support-in-e2e-tests
JohnAllenTech 6f18a55
Merge branch 'develop' into feat/multiple-user-support-in-e2e-tests
NiallJoeMaher File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,9 +44,12 @@ jobs: | |
| GITHUB_ID: ${{ secrets.E2E_GITHUB_ID }} | ||
| GITHUB_SECRET: ${{ secrets.E2E_GITHUB_SECRET }} | ||
| NEXTAUTH_SECRET: ${{ secrets.NEXTAUTH_SECRET }} | ||
| E2E_USER_EMAIL: [email protected] | ||
| E2E_USER_ID: 8e3179ce-f32b-4d0a-ba3b-234d66b836ad | ||
| E2E_USER_ONE_EMAIL: e2e-user-one@codu.co | ||
| 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -10,11 +10,19 @@ import postgres from "postgres"; | |
|
|
||
| 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_SESSION_ID = | ||
| const E2E_USER_ONE_SESSION_ID = | ||
| process.env.E2E_USER_ONE_SESSION_ID || "df8a11f2-f20a-43d6-80a0-a213f1efedc1"; | ||
| const E2E_USER_ID = | ||
| process.env.E2E_USER_ID || "8e3179ce-f32b-4d0a-ba3b-234d66b836ad"; | ||
| const E2E_USER_EMAIL = process.env.E2E_USER_EMAIL || "[email protected]"; | ||
| 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"); | ||
|
|
@@ -116,27 +124,25 @@ ${chance.paragraph()} | |
| return users; | ||
| }; | ||
|
|
||
| const seedE2EUser = async () => { | ||
| const name = "E2E Test User"; | ||
|
|
||
| const seedE2EUser = async (email: string, id: string, name: string) => { | ||
| const [existingE2EUser] = await db | ||
| .selectDistinct() | ||
| .from(user) | ||
| .where(eq(user.id, E2E_USER_ID)); | ||
| .where(eq(user.id, id)); | ||
|
|
||
| if (existingE2EUser) { | ||
| console.log("E2E Test user already exists. Skipping creation"); | ||
| return existingE2EUser; | ||
| } | ||
|
|
||
| const userData = { | ||
| id: E2E_USER_ID, | ||
| id: id, | ||
| username: `${name.split(" ").join("-").toLowerCase()}-${chance.integer({ | ||
| min: 0, | ||
| max: 999, | ||
| })}`, | ||
| name, | ||
| email: E2E_USER_EMAIL, | ||
| email, | ||
| image: `https://robohash.org/${encodeURIComponent(name)}?bgset=bg1`, | ||
| location: chance.country({ full: true }), | ||
| bio: chance.sentence({ words: 10 }), | ||
|
|
@@ -146,11 +152,11 @@ ${chance.paragraph()} | |
| return createdUser; | ||
| }; | ||
|
|
||
| const seedE2EUserSession = async (userId: string) => { | ||
| const seedE2EUserSession = async (userId: string, sessionToken: string) => { | ||
| const [existingE2EUserSession] = await db | ||
| .selectDistinct() | ||
| .from(session) | ||
| .where(eq(session.sessionToken, E2E_SESSION_ID)); | ||
| .where(eq(session.sessionToken, sessionToken)); | ||
|
|
||
| if (existingE2EUserSession) { | ||
| console.log("E2E Test session already exists. Skipping creation"); | ||
|
|
@@ -164,7 +170,7 @@ ${chance.paragraph()} | |
| .insert(session) | ||
| .values({ | ||
| userId, | ||
| sessionToken: E2E_SESSION_ID, | ||
| sessionToken, | ||
| // Set session to expire in 6 months. | ||
| expires: new Date(currentDate.setMonth(currentDate.getMonth() + 6)), | ||
| }) | ||
|
|
@@ -249,8 +255,19 @@ ${chance.paragraph()} | |
|
|
||
| try { | ||
| await addUserData(); | ||
| const user = await seedE2EUser(); | ||
| await seedE2EUserSession(user.id); | ||
| const userOne = await seedE2EUser( | ||
| E2E_USER_ONE_EMAIL, | ||
| E2E_USER_ONE_ID, | ||
| "E2E Test User One", | ||
| ); | ||
| const userTwo = await seedE2EUser( | ||
| E2E_USER_TWO_EMAIL, | ||
| E2E_USER_TWO_ID, | ||
| "E2E Test User Two", | ||
| ); | ||
|
|
||
| await seedE2EUserSession(userOne.id, E2E_USER_ONE_SESSION_ID); | ||
| await seedE2EUserSession(userTwo.id, E2E_USER_TWO_SESSION_ID); | ||
| } catch (error) { | ||
| console.log("Error:", error); | ||
| } | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -6,5 +6,7 @@ NEXTAUTH_URL=http://localhost:3000/api/auth | |
| DATABASE_URL=postgresql://postgres:[email protected]:5432/postgres | ||
|
|
||
| [email protected] | ||
| E2E_USER_ID=8e3179ce-f32b-4d0a-ba3b-234d66b836ad | ||
| 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 | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.