Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 167
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
02aabfe984b47d168f007eb1276ec089605a2f1d346f18a55File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -5,17 +5,27 @@ dotenv.config(); // Load .env file contents into process.env | ||
| export const teardown = async () => { | ||
| try { | ||
| if (!process.env.DATABASE_URL || !process.env.E2E_USER_ID) | ||
| if ( | ||
| !process.env.DATABASE_URL || | ||
| !process.env.E2E_USER_ONE_ID || | ||
| !process.env.E2E_USER_TWO_ID | ||
| ) | ||
JohnAllenTech marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| throw new Error("Missing env variables for DB clean up script"); | ||
| const db = postgres(process.env.DATABASE_URL as string); | ||
| // the test suit adds posts created by the E2E user. We want to remove them between test runs | ||
| // 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_ID as string} | ||
| DELETE FROM "Post" WHERE "userId" = ${process.env.E2E_USER_ONE_ID as string} | ||
| `; | ||
| await db` | ||
| DELETE FROM "Post" WHERE "userId" = ${process.env.E2E_USER_TWO_ID as string} | ||
| `; | ||
JohnAllenTech marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| // 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_ID as string} | ||
| DELETE FROM "Comment" WHERE "userId" = ${process.env.E2E_USER_ONE_ID as string} | ||
| `; | ||
| await db` | ||
| DELETE FROM "Comment" WHERE "userId" = ${process.env.E2E_USER_TWO_ID as string} | ||
| `; | ||
JohnAllenTech marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. JohnAllenTech marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| console.log("DB clean up successful"); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -23,3 +23,29 @@ export const loggedInAsUserOne = async (page: Page) => { | ||
| throw Error("Error while authenticating E2E test user one"); | ||
| } | ||
| }; | ||
| 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, | ||
| domain: "localhost", | ||
| path: "/", | ||
| sameSite: "Lax", | ||
| }, | ||
| ]); | ||
| expect( | ||
| (await page.context().cookies()).find( | ||
| (cookie) => cookie.name === "next-auth.session-token", | ||
| ), | ||
| ).toBeTruthy(); | ||
| } catch (err) { | ||
| throw Error("Error while authenticating E2E test user two"); | ||
| } | ||
| }; | ||
JohnAllenTech marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
Uh oh!
There was an error while loading. Please reload this page.