Skip to content

Commit

Permalink
updated fixtures and names of env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
WhyAsh5114 committed Dec 20, 2023
1 parent 0a731d5 commit aca0f35
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 33 deletions.
12 changes: 6 additions & 6 deletions src/hooks.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import GitHub from "@auth/core/providers/github";
import { MongoDBAdapter } from "@auth/mongodb-adapter";
import clientPromise from "$lib/mongo/mongodb";
import {
AUTH_GOOGLE_ID,
AUTH_GOOGLE_SECRET,
AUTH_GITHUB_ID,
AUTH_GITHUB_SECRET
GOOGLE_CLIENT_ID,
GOOGLE_CLIENT_SECRET,
GITHUB_CLIENT_ID,
GITHUB_CLIENT_SECRET
} from "$env/static/private";

export const handle = SvelteKitAuth({
providers: [
Google({ clientId: AUTH_GOOGLE_ID, clientSecret: AUTH_GOOGLE_SECRET }),
GitHub({ clientId: AUTH_GITHUB_ID, clientSecret: AUTH_GITHUB_SECRET })
Google({ clientId: GOOGLE_CLIENT_ID, clientSecret: GOOGLE_CLIENT_SECRET }),
GitHub({ clientId: GITHUB_CLIENT_ID, clientSecret: GITHUB_CLIENT_SECRET })
],
adapter: MongoDBAdapter(clientPromise, {
databaseName: "MyFit_v2"
Expand Down
42 changes: 15 additions & 27 deletions tests/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@ import path from "path";
import dotenv from "dotenv";
dotenv.config();

function acquireAccount(id: number) {
id++;
return {
username: process.env[`USERNAME${id}`] as string,
password: process.env[`PASSWORD${id}`] as string
};
}

export * from "@playwright/test";
export const test = baseTest.extend<{}, { workerStorageState: string }>({
// Use the same storage state for all tests in this worker.
Expand All @@ -33,31 +25,27 @@ export const test = baseTest.extend<{}, { workerStorageState: string }>({

// Important: make sure we authenticate in a clean environment by unsetting storage state.
const page = await browser.newPage({ storageState: undefined });

// Acquire a unique account, for example create a new one.
// Alternatively, you can have a list of precreated accounts for testing.
// Make sure that accounts are unique, so that multiple team members
// can run tests at the same time without interference.
const account = acquireAccount(id);

// Perform authentication steps. Replace these actions with your own.
await page.goto("http://localhost:4173/login");
await page.getByText("Sign in with GitHub").click();
await page.waitForURL(/github.com/);

await page.getByLabel("Username or email address").fill(account.username);
await page.getByLabel("Password").fill(account.password);
await page.getByRole("button", { name: "Sign in" }).click();
const testSession = process.env[`TEST_SESSION_${id + 1}`] ?? "";

// Perform authentication steps. Just set a test user's cookie.
await page.context().addCookies([
{
name: "authjs.session-token",
value: testSession,
path: "/",
domain: "localhost",
}
]);
// Wait until the page receives the cookies.
//
// Sometimes login flow sets cookies in the process of several redirects.
// Wait for the final URL to ensure that the cookies are actually set.
await page.waitForURL(/localhost:4173/);
// Reload to get user info
await page.reload();
// End of authentication steps.

await page.context().storageState({ path: fileName });
await page.close();
await use(fileName);

// Clear user data
},
{ scope: "worker" }
]
Expand Down

0 comments on commit aca0f35

Please sign in to comment.