Skip to content

Commit acc0f5f

Browse files
committed
fix: Extend year-specific speaker and talk data fetching and routing to include 2025 and 2026.
1 parent 23d1bdd commit acc0f5f

File tree

7 files changed

+148
-13
lines changed

7 files changed

+148
-13
lines changed

src/hooks/useFetchSpeakers.test.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,24 @@ describe("fetch speaker hook and speaker adapter", () => {
123123
expect(result.current.data).toEqual(speakerAdapter(payload.data));
124124
});
125125

126+
it("should use 2025 URL when '2025' is passed", async () => {
127+
const { wrapper } = getQueryClientWrapper();
128+
mockedAxios.get.mockImplementation(() => Promise.resolve(payload));
129+
130+
const { result } = renderHook(() => useFetchSpeakers("2025"), {
131+
wrapper,
132+
});
133+
await waitFor(() => result.current.isSuccess, {});
134+
await waitFor(() => !result.current.isLoading, {});
135+
136+
expect(mockedAxios.get).toHaveBeenCalledWith(SPEAKER_URLS["2025"], {
137+
headers: { Accept: "application/json; charset=utf-8" },
138+
});
139+
expect(result.current.isLoading).toEqual(false);
140+
expect(result.current.error).toEqual(null);
141+
expect(result.current.data).toEqual(speakerAdapter(payload.data));
142+
});
143+
126144
it("should use custom URL when a URL is passed", async () => {
127145
const { wrapper } = getQueryClientWrapper();
128146
mockedAxios.get.mockImplementation(() => Promise.resolve(payload));

src/hooks/useFetchSpeakers.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const URLS = {
1111
default: "https://sessionize.com/api/v2/xhudniix/view/Speakers",
1212
2023: "https://sessionize.com/api/v2/ttsitynd/view/Speakers",
1313
2024: "https://sessionize.com/api/v2/teq4asez/view/Speakers",
14+
2025: "https://sessionize.com/api/v2/xhudniix/view/Speakers",
1415
};
1516

1617
export const useFetchSpeakers = (

src/hooks/useFetchTalks.test.tsx

Lines changed: 80 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ import { renderHook, waitFor } from "@testing-library/react";
22
import axios from "axios";
33
import { type MockedFunction, vi } from "vitest";
44

5-
import {
6-
useFetchLiveView,
7-
useFetchTalks,
8-
useFetchTalksById,
9-
} from "./useFetchTalks";
105
import {
116
createMockAxiosResponse,
127
createMockGroup,
138
createMockSession,
149
getQueryClientWrapper,
1510
SESSION_URLS,
1611
} from "../utils/testing/testUtils";
12+
import {
13+
useFetchLiveView,
14+
useFetchTalks,
15+
useFetchTalksById,
16+
} from "./useFetchTalks";
1717

1818
import type { IGroup } from "../types/sessions";
1919

@@ -79,6 +79,24 @@ describe("useFetchTalks", () => {
7979
expect(result.current.data).toEqual(mockData);
8080
});
8181

82+
it("should use 2025 URL when '2025' is provided", async () => {
83+
const mockData: IGroup[] = [createMockGroup({ groupName: "test" })];
84+
const payload = createMockAxiosResponse(mockData);
85+
86+
mockedAxios.get.mockResolvedValue(payload);
87+
88+
const { wrapper } = getQueryClientWrapper();
89+
const { result } = renderHook(() => useFetchTalks("2025"), {
90+
wrapper,
91+
});
92+
93+
await waitFor(() => result.current.isSuccess);
94+
await waitFor(() => !result.current.isLoading);
95+
96+
expect(mockedAxios.get).toHaveBeenCalledWith(SESSION_URLS["2025"]);
97+
expect(result.current.data).toEqual(mockData);
98+
});
99+
82100
it("should use custom URL when a URL is provided", async () => {
83101
const mockData: IGroup[] = [createMockGroup({ groupName: "test" })];
84102
const payload = createMockAxiosResponse(mockData);
@@ -186,6 +204,35 @@ describe("useFetchTalksById", () => {
186204
expect(result.current.data).toEqual(expectedData);
187205
});
188206

207+
it("should use 2025 URL when '2025' is provided", async () => {
208+
const mockSession = createMockSession({
209+
track: "",
210+
description: "",
211+
startsAt: "2025-01-01T00:00:00",
212+
});
213+
const mockData: IGroup[] = [
214+
createMockGroup({
215+
groupName: "test ",
216+
sessions: [mockSession],
217+
}),
218+
];
219+
const payload = createMockAxiosResponse(mockData);
220+
221+
mockedAxios.get.mockResolvedValue(payload);
222+
223+
const { wrapper } = getQueryClientWrapper();
224+
const { result } = renderHook(() => useFetchTalksById("123", "2025"), {
225+
wrapper,
226+
});
227+
228+
await waitFor(() => result.current.isSuccess);
229+
await waitFor(() => !result.current.isLoading);
230+
231+
expect(mockedAxios.get).toHaveBeenCalledWith(SESSION_URLS["2025"]);
232+
const expectedData = mockData[0].sessions[0];
233+
expect(result.current.data).toEqual(expectedData);
234+
});
235+
189236
it("should use custom URL when a URL is provided", async () => {
190237
const mockSession = createMockSession();
191238
const mockData: IGroup[] = [
@@ -296,6 +343,34 @@ describe("useFetchLiveView", () => {
296343
expect(result.current.data).toEqual([mockSession]);
297344
});
298345

346+
it("should use 2025 URL when '2025' is provided", async () => {
347+
const mockSession = createMockSession({
348+
track: "",
349+
description: "",
350+
startsAt: "2025-01-01T00:00:00",
351+
});
352+
const mockData: IGroup[] = [
353+
createMockGroup({
354+
groupName: "test ",
355+
sessions: [mockSession],
356+
}),
357+
];
358+
const payload = createMockAxiosResponse(mockData);
359+
360+
mockedAxios.get.mockResolvedValue(payload);
361+
362+
const { wrapper } = getQueryClientWrapper();
363+
const { result } = renderHook(() => useFetchLiveView("2025"), {
364+
wrapper,
365+
});
366+
367+
await waitFor(() => result.current.isSuccess);
368+
await waitFor(() => !result.current.isLoading);
369+
370+
expect(mockedAxios.get).toHaveBeenCalledWith(SESSION_URLS["2025"]);
371+
expect(result.current.data).toEqual([mockSession]);
372+
});
373+
299374
it("should use custom URL when a URL is provided", async () => {
300375
const mockSession = createMockSession();
301376
const mockData: IGroup[] = [

src/hooks/useFetchTalks.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const URLS = {
99
default: "https://sessionize.com/api/v2/xhudniix/view/Sessions",
1010
2023: "https://sessionize.com/api/v2/ttsitynd/view/Sessions",
1111
2024: "https://sessionize.com/api/v2/teq4asez/view/Sessions",
12+
2025: "https://sessionize.com/api/v2/xhudniix/view/Sessions",
1213
};
1314

1415
/**

src/utils/testing/testUtils.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,14 @@ export const SESSION_URLS = {
8484
DEFAULT: "https://sessionize.com/api/v2/xhudniix/view/Sessions",
8585
2023: "https://sessionize.com/api/v2/ttsitynd/view/Sessions",
8686
2024: "https://sessionize.com/api/v2/teq4asez/view/Sessions",
87+
2025: "https://sessionize.com/api/v2/xhudniix/view/Sessions",
8788
};
8889

8990
export const SPEAKER_URLS = {
9091
DEFAULT: "https://sessionize.com/api/v2/xhudniix/view/Speakers",
9192
2023: "https://sessionize.com/api/v2/ttsitynd/view/Speakers",
9293
2024: "https://sessionize.com/api/v2/teq4asez/view/Speakers",
94+
2025: "https://sessionize.com/api/v2/xhudniix/view/Speakers",
9395
};
9496

9597
export const createMockSpeaker = (overrides = {}) => ({

src/views/Speakers/components/SpeakersCard.test.tsx

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import { screen } from "@testing-library/react";
2-
import React from "react";
32

4-
import { SpeakerCard, getSpeakerRoute } from "./SpeakersCard";
53
import {
64
ROUTE_2023_SPEAKER_DETAIL,
75
ROUTE_2024_SPEAKER_DETAIL,
6+
ROUTE_2025_SPEAKER_DETAIL,
7+
ROUTE_2026_SPEAKER_DETAIL,
88
ROUTE_SPEAKER_DETAIL,
99
} from "../../../constants/routes";
1010
import {
1111
createMockSpeaker,
1212
renderWithRouter,
1313
} from "../../../utils/testing/speakerTestUtils";
14+
import { SpeakerCard, getSpeakerRoute } from "./SpeakersCard";
1415

1516
describe("SpeakerCard", () => {
1617
const mockSpeaker = createMockSpeaker();
@@ -49,6 +50,28 @@ describe("SpeakerCard", () => {
4950
);
5051
});
5152

53+
it("creates a link to the correct speaker detail page for 2025", () => {
54+
renderWithRouter(<SpeakerCard speaker={mockSpeaker} year="2025" />);
55+
56+
// Check that the link points to the correct route
57+
const link = screen.getByRole("link");
58+
expect(link).toHaveAttribute(
59+
"href",
60+
`${ROUTE_2025_SPEAKER_DETAIL}/${mockSpeaker.id}`,
61+
);
62+
});
63+
64+
it("creates a link to the correct speaker detail page for 2026", () => {
65+
renderWithRouter(<SpeakerCard speaker={mockSpeaker} year="2026" />);
66+
67+
// Check that the link points to the correct route
68+
const link = screen.getByRole("link");
69+
expect(link).toHaveAttribute(
70+
"href",
71+
`${ROUTE_2026_SPEAKER_DETAIL}/${mockSpeaker.id}`,
72+
);
73+
});
74+
5275
it("creates a link to the default speaker detail page for other years", () => {
5376
renderWithRouter(<SpeakerCard speaker={mockSpeaker} year="2022" />);
5477

@@ -70,6 +93,14 @@ describe("getSpeakerRoute", () => {
7093
expect(getSpeakerRoute("2024")).toBe(ROUTE_2024_SPEAKER_DETAIL);
7194
});
7295

96+
it("returns the 2025 route for year 2025", () => {
97+
expect(getSpeakerRoute("2025")).toBe(ROUTE_2025_SPEAKER_DETAIL);
98+
});
99+
100+
it("returns the 2026 route for year 2026", () => {
101+
expect(getSpeakerRoute("2026")).toBe(ROUTE_2026_SPEAKER_DETAIL);
102+
});
103+
73104
it("returns the default route for other years", () => {
74105
expect(getSpeakerRoute("2022")).toBe(ROUTE_SPEAKER_DETAIL);
75106
expect(getSpeakerRoute("")).toBe(ROUTE_SPEAKER_DETAIL);

src/views/Speakers/components/SpeakersCard.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { Link } from "react-router";
44
import {
55
ROUTE_2023_SPEAKER_DETAIL,
66
ROUTE_2024_SPEAKER_DETAIL,
7+
ROUTE_2025_SPEAKER_DETAIL,
8+
ROUTE_2026_SPEAKER_DETAIL,
79
ROUTE_SPEAKER_DETAIL,
810
} from "@constants/routes";
911

@@ -26,13 +28,18 @@ type SpeakerCardProps = {
2628

2729
// eslint-disable-next-line react-refresh/only-export-components
2830
export const getSpeakerRoute = (year: string): string => {
29-
if (year === "2023") {
30-
return ROUTE_2023_SPEAKER_DETAIL;
31+
switch (year) {
32+
case "2023":
33+
return ROUTE_2023_SPEAKER_DETAIL;
34+
case "2024":
35+
return ROUTE_2024_SPEAKER_DETAIL;
36+
case "2025":
37+
return ROUTE_2025_SPEAKER_DETAIL;
38+
case "2026":
39+
return ROUTE_2026_SPEAKER_DETAIL;
40+
default:
41+
return ROUTE_SPEAKER_DETAIL;
3142
}
32-
if (year === "2024") {
33-
return ROUTE_2024_SPEAKER_DETAIL;
34-
}
35-
return ROUTE_SPEAKER_DETAIL;
3643
};
3744

3845
export const SpeakerCard: FC<React.PropsWithChildren<SpeakerCardProps>> = ({

0 commit comments

Comments
 (0)