-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5ad3987
commit 5eaa59c
Showing
6 changed files
with
70 additions
and
58 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 |
---|---|---|
@@ -1,10 +1,12 @@ | ||
import { Variant } from "@/types"; | ||
|
||
export const MockConsultants: Variant[] = [{ | ||
id: 'id', | ||
name: 'Test Consultant', | ||
email: '[email protected]', | ||
competences: ['Frontend'], | ||
department: 'My Department', | ||
bookings: [{year: 2023, weekNumber: 10, bookedHours: 10}] | ||
}] | ||
export const MockConsultants: Variant[] = [ | ||
{ | ||
id: "id", | ||
name: "Test Consultant", | ||
email: "[email protected]", | ||
competences: ["Frontend"], | ||
department: "My Department", | ||
bookings: [{ year: 2023, weekNumber: 10, bookedHours: 10 }], | ||
}, | ||
]; |
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
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 |
---|---|---|
@@ -1,31 +1,37 @@ | ||
"use client" | ||
import { Variant } from '@/types'; | ||
import { fetchWithToken } from '@/auth/fetchWithToken'; | ||
import { useIsAuthenticated } from '@azure/msal-react'; | ||
"use client"; | ||
import { Variant } from "@/types"; | ||
import { fetchWithToken } from "@/auth/fetchWithToken"; | ||
import { useIsAuthenticated } from "@azure/msal-react"; | ||
import { useQuery, useQueryClient } from "react-query"; | ||
import { useEffect } from "react"; | ||
|
||
function useVibesApi(includeOccupied: boolean) { | ||
const isAuthenticated = useIsAuthenticated() || process.env.NEXT_PUBLIC_NO_AUTH; | ||
const isAuthenticated = | ||
useIsAuthenticated() || process.env.NEXT_PUBLIC_NO_AUTH; | ||
const client = useQueryClient(); | ||
|
||
//TODO: We need a better way of handling state/cache. This works for now though, but it's a bit hacky ngl | ||
useEffect(()=> client.clear(), [includeOccupied, client]) | ||
useEffect(() => client.clear(), [includeOccupied, client]); | ||
|
||
return useQuery({queryKey: 'vibes', queryFn: async () => { | ||
if (isAuthenticated) { | ||
try { | ||
const response: Variant[] = await fetchWithToken(`/api/v0/variants?weeks=8&includeOccupied=${includeOccupied}`); | ||
return response; | ||
|
||
} catch (err) { | ||
console.error(err) | ||
return [] | ||
return useQuery({ | ||
queryKey: "vibes", | ||
queryFn: async () => { | ||
if (isAuthenticated) { | ||
try { | ||
const response: Variant[] = await fetchWithToken( | ||
`/api/v0/variants?weeks=8&includeOccupied=${includeOccupied}`, | ||
); | ||
return response; | ||
} catch (err) { | ||
console.error(err); | ||
return []; | ||
} | ||
} | ||
} | ||
// If not authenticated, return an empty array | ||
return []; | ||
}, refetchOnWindowFocus: false | ||
})} | ||
// If not authenticated, return an empty array | ||
return []; | ||
}, | ||
refetchOnWindowFocus: false, | ||
}); | ||
} | ||
|
||
export default useVibesApi; |
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,10 +1,8 @@ | ||
import { test, expect } from '@playwright/test'; | ||
import { test, expect } from "@playwright/test"; | ||
|
||
test('has title', async ({ page }) => { | ||
await page.goto('/'); | ||
const consultantName = await page.getByText('Test Consultant'); | ||
|
||
// Expect a title "to contain" a substring. | ||
await expect(consultantName).toBeVisible() | ||
test("has title", async ({ page }) => { | ||
await page.goto("/"); | ||
const consultantName = page.getByText("Test Consultant"); | ||
|
||
await expect(consultantName).toBeVisible(); | ||
}); |