diff --git a/booking-app/app/api/isTestEnv/route.ts b/booking-app/app/api/isTestEnv/route.ts new file mode 100644 index 00000000..925b2fe1 --- /dev/null +++ b/booking-app/app/api/isTestEnv/route.ts @@ -0,0 +1,12 @@ +import { NextResponse } from "next/server"; + +export async function GET() { + try { + if(process.env.NEXT_PUBLIC_BRANCH_NAME === "development") { + return NextResponse.json({ isOnTestEnv: true }); + } + } catch (error) { + } + + return NextResponse.json({ isOnTestEnv: false }); +} \ No newline at end of file diff --git a/booking-app/components/src/client/routes/components/AuthProvider.tsx b/booking-app/components/src/client/routes/components/AuthProvider.tsx index 5653b7c4..ef12762e 100644 --- a/booking-app/components/src/client/routes/components/AuthProvider.tsx +++ b/booking-app/components/src/client/routes/components/AuthProvider.tsx @@ -9,12 +9,14 @@ type AuthContextType = { user: User | null; loading: boolean; error: string | null; + isOnTestEnv: boolean; }; const AuthContext = createContext({ user: null, loading: true, error: null, + isOnTestEnv: false, }); export const useAuth = () => useContext(AuthContext); @@ -25,13 +27,20 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ const [user, setUser] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); + const [isOnTestEnv, setIsOnTestEnv] = useState(false); + const router = useRouter(); const pathname = usePathname(); + useEffect(() => { const handleAuth = async () => { + const testEnvRes = await fetch("/api/isTestEnv"); + const { isOnTestEnv } = await testEnvRes.json(); + setIsOnTestEnv(isOnTestEnv); + const user = auth.currentUser; if (user) { - if (user.email?.endsWith("@nyu.edu")) { + if (user.email?.endsWith("@nyu.edu") || isOnTestEnv) { setUser(user); } else { await auth.signOut(); @@ -62,7 +71,7 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ }, [error, router]); return ( - + {children} ); diff --git a/booking-app/components/src/client/routes/components/GoogleSignIn.tsx b/booking-app/components/src/client/routes/components/GoogleSignIn.tsx index 5b8bc9e2..89ad72ed 100644 --- a/booking-app/components/src/client/routes/components/GoogleSignIn.tsx +++ b/booking-app/components/src/client/routes/components/GoogleSignIn.tsx @@ -1,10 +1,11 @@ "use client"; -import React from "react"; // Added this line +import React, { useContext } from "react"; // Added this line import { useState } from "react"; import { signInWithPopup } from "firebase/auth"; import { auth, googleProvider } from "@/lib/firebase/firebaseClient"; import { useRouter } from "next/navigation"; import { Box, Button, styled } from "@mui/material"; +import { useAuth } from "./AuthProvider"; const Center = styled(Box)` display: flex; @@ -20,7 +21,8 @@ const GoogleSignIn = () => { try { const result = await signInWithPopup(auth, googleProvider); const user = result.user; - if (user.email?.endsWith("@nyu.edu")) { + const {isOnTestEnv} = useAuth(); + if (user.email?.endsWith("@nyu.edu") || isOnTestEnv) { console.log("Google sign-in successful", user); router.push("/"); } else { diff --git a/booking-app/lib/firebase/firebaseClient.ts b/booking-app/lib/firebase/firebaseClient.ts index fd2310e6..23bf57ea 100644 --- a/booking-app/lib/firebase/firebaseClient.ts +++ b/booking-app/lib/firebase/firebaseClient.ts @@ -31,15 +31,18 @@ export const getDb = () => { }; export const auth = getAuth(app); export const googleProvider = new GoogleAuthProvider(); -googleProvider.setCustomParameters({ - hd: "nyu.edu", -}); + +if(process.env.NEXT_PUBLIC_BRANCH_NAME !== "development") { + googleProvider.setCustomParameters({ + hd: "nyu.edu", + }); +} export const signInWithGoogle = async () => { try { const result = await signInWithPopup(auth, googleProvider); const user = result.user; - if (!user.email?.endsWith("@nyu.edu")) { + if (!user.email?.endsWith("@nyu.edu") && process.env.NEXT_PUBLIC_BRANCH_NAME !== "development") { await auth.signOut(); throw new Error("Only nyu.edu email addresses are allowed."); } diff --git a/booking-app/playwright.config.ts b/booking-app/playwright.config.ts index 3c2bd65f..709bb193 100644 --- a/booking-app/playwright.config.ts +++ b/booking-app/playwright.config.ts @@ -26,6 +26,7 @@ export default defineConfig({ reporter: 'html', /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ use: { + headless:false, /* Base URL to use in actions like `await page.goto('/')`. */ // baseURL: 'http://127.0.0.1:3000', diff --git a/booking-app/tests/sample.e2e.test.ts b/booking-app/tests/sample.e2e.test.ts index 975e4ed2..f2c2d3dc 100644 --- a/booking-app/tests/sample.e2e.test.ts +++ b/booking-app/tests/sample.e2e.test.ts @@ -1,9 +1,13 @@ import { test, expect } from '@playwright/test'; -test('search for text Media Commons', async ({ page }) => { +test('Search for text Media Commons in the title', async ({ page }) => { await page.goto('http://localhost:3000'); //make sure there is an h4 element with the text "Media Commons" await expect(page).toHaveTitle('Media commons booking app'); -}); \ No newline at end of file +}); + +test('Go through the booking process', async ({ page }) => { + await page.goto('http://localhost:3000'); +});