Skip to content

Commit 453e00a

Browse files
VIA-630 MD/DB Redirect user to service failure page if age unknown on hub page
Restores changes from 70350c7, moved up a layer to the hub page itself so that the age based card component will still continue to load for the other age ranges that have not been implemented yet (returns empty element but still allows the hub to be loaded). It was considered whether the error should be thrown in the session loader instead and let the default existing error handling run; however this redirects the user back to NHS app, which was not the required behaviour for the age based hub feature.
1 parent 5220c55 commit 453e00a

File tree

2 files changed

+37
-16
lines changed

2 files changed

+37
-16
lines changed

src/app/check-and-book-vaccinations/page.test.tsx

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ import { AgeGroup } from "@src/models/ageBasedHub";
66
import { NhsNumber } from "@src/models/vaccine";
77
import { render, screen } from "@testing-library/react";
88
import { Session } from "next-auth";
9+
import { redirect } from "next/navigation";
10+
11+
jest.mock("next/navigation", () => ({
12+
redirect: jest.fn(),
13+
}));
914

1015
jest.mock("@src/app/_components/nhs-app/BackToNHSAppLink");
1116

@@ -67,6 +72,17 @@ describe("Vaccination Hub Page", () => {
6772
);
6873
});
6974

75+
it("should redirect to service failure page if user age unknown", async () => {
76+
(auth as jest.Mock).mockResolvedValue(mockSessionDataForAgeGroup(AgeGroup.UNKNOWN_AGE_GROUP));
77+
78+
try {
79+
render(await VaccinationsHub());
80+
} catch {
81+
expect(redirect).toHaveBeenCalledTimes(1);
82+
expect(redirect).toHaveBeenCalledWith("/service-failure");
83+
}
84+
});
85+
7086
it("should show at risk expander ", () => {
7187
const atRiskHubExpander: HTMLElement = screen.getByTestId("at-risk-hub-expander");
7288
expect(atRiskHubExpander).toBeVisible();
@@ -84,22 +100,22 @@ describe("Vaccination Hub Page", () => {
84100
});
85101

86102
describe("pregnancy hub content", () => {
87-
it.each([
88-
{ description: "hide", ageGroup: AgeGroup.AGE_65_to_74, shouldShowPregnancyContent: false },
89-
{ description: "show", ageGroup: AgeGroup.UNKNOWN_AGE_GROUP, shouldShowPregnancyContent: true },
90-
])(`$ageGroup should $description pregnancy content`, async ({ ageGroup, shouldShowPregnancyContent }) => {
91-
(auth as jest.Mock).mockResolvedValue(mockSessionDataForAgeGroup(ageGroup));
92-
93-
render(await VaccinationsHub());
94-
95-
const pregnancyHubContent: HTMLElement | null = screen.queryByTestId("pregnancy-hub-content");
96-
97-
if (shouldShowPregnancyContent) {
98-
expect(pregnancyHubContent).toBeVisible();
99-
} else {
100-
expect(pregnancyHubContent).toBeNull();
101-
}
102-
});
103+
it.each([{ description: "hide", ageGroup: AgeGroup.AGE_65_to_74, shouldShowPregnancyContent: false }])(
104+
`$ageGroup should $description pregnancy content`,
105+
async ({ ageGroup, shouldShowPregnancyContent }) => {
106+
(auth as jest.Mock).mockResolvedValue(mockSessionDataForAgeGroup(ageGroup));
107+
108+
render(await VaccinationsHub());
109+
110+
const pregnancyHubContent: HTMLElement | null = screen.queryByTestId("pregnancy-hub-content");
111+
112+
if (shouldShowPregnancyContent) {
113+
expect(pregnancyHubContent).toBeVisible();
114+
} else {
115+
expect(pregnancyHubContent).toBeNull();
116+
}
117+
},
118+
);
103119
});
104120
});
105121

src/app/check-and-book-vaccinations/page.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,18 @@ import { NHS_TITLE_SUFFIX, SERVICE_HEADING } from "@src/app/constants";
1010
import { AgeBasedHubDetails, AgeBasedHubInfo, AgeGroup } from "@src/models/ageBasedHub";
1111
import { Session } from "next-auth";
1212
import Link from "next/link";
13+
import { redirect } from "next/navigation";
1314
import React from "react";
1415

1516
const VaccinationsHub = async () => {
1617
// TODO: VIA-630 add missing request scoped storage wrapper. Check other new pages and add as required
1718

1819
const session: Session | null = await auth();
1920
const ageGroup: AgeGroup = session?.user.age_group as AgeGroup;
21+
if (ageGroup === AgeGroup.UNKNOWN_AGE_GROUP) {
22+
redirect("/service-failure");
23+
}
24+
2025
const hubInfoForAgeGroup: AgeBasedHubDetails | undefined = AgeBasedHubInfo[ageGroup];
2126

2227
return (

0 commit comments

Comments
 (0)