Skip to content

Commit 654fe1e

Browse files
SPIKE SB Use yarl-like Url class.
1 parent 5d01e92 commit 654fe1e

39 files changed

+667
-107
lines changed

contract/fetch-eligibility-content.contract.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { NhsNumber } from "@src/models/vaccine";
22
import { EligibilityApiResponse } from "@src/services/eligibility-api/api-types";
33
import { fetchEligibilityContent } from "@src/services/eligibility-api/gateway/fetch-eligibility-content";
4+
import { Url } from "@src/utils/Url";
45
import config from "@src/utils/config";
56
import { asyncLocalStorage } from "@src/utils/requestContext";
67
import { ConfigMock, configBuilder } from "@test-data/config/builders";
@@ -44,7 +45,7 @@ pactWith({ consumer: "VitA", provider: "EliD", port: 1234, logLevel: "warn" }, (
4445

4546
beforeEach(() => {
4647
const defaultConfig = configBuilder()
47-
.withEligibilityApiEndpoint(new URL("http://localhost:1234/"))
48+
.withEligibilityApiEndpoint(new Url("http://localhost:1234/"))
4849
.andEligibilityApiKey("test-api-key")
4950
.andIsApimAuthEnabled(false)
5051
.build();

e2e/auth.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Browser, Page } from "@playwright/test";
22
import { getEnv } from "@project/e2e/helpers";
3+
import { Url } from "@src/utils/Url";
34

45
interface User {
56
nhsAppLoginUrl: string;
@@ -61,7 +62,7 @@ export const login = async (browser: Browser, nhsLoginUsername: string): Promise
6162
await page.getByRole("button", { name: "Continue" }).click();
6263

6364
await page.waitForURL(/\/(enter-mobile-code|choose-authentication-method)$/, { timeout: 30000 });
64-
if (new URL(page.url()).pathname === "/choose-authentication-method") {
65+
if (new Url(page.url()).path === "/choose-authentication-method") {
6566
await page.getByLabel("Use my mobile phone to recieve a security code by text message").click();
6667
await page.getByRole("button", { name: "Continue" }).click();
6768
}
@@ -78,7 +79,7 @@ export const login = async (browser: Browser, nhsLoginUsername: string): Promise
7879
return page;
7980
} else {
8081
await page.waitForURL(/\/(terms-and-conditions\?redirect_to=index|patient\/)$/, { timeout: 30000 });
81-
if (new URL(page.url()).pathname === "/terms-and-conditions") {
82+
if (new Url(page.url()).path === "/terms-and-conditions") {
8283
await page.locator("#termsAndConditions-agree_checkbox").setChecked(true);
8384
await page.getByRole("button", { name: "Continue" }).click();
8485
}

src/_lambda/content-cache-hydrator/content-change-detector.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { vitaContentChangedSinceLastApproved } from "@src/_lambda/content-cache-hydrator/content-change-detector";
22
import { VaccinePageContent } from "@src/services/content-api/types";
3+
import { Url } from "@src/utils/Url";
34

45
const mockPreviousApprovedVaccineContent: VaccinePageContent = {
56
overview: { content: "This is an overview", containsHtml: false },
@@ -47,7 +48,7 @@ const mockPreviousApprovedVaccineContent: VaccinePageContent = {
4748
},
4849
],
4950
},
50-
webpageLink: new URL("https://test.example.com/"),
51+
webpageLink: new Url("https://test.example.com/"),
5152
};
5253

5354
describe("vitaContentChangedSinceLastApproved", () => {

src/_lambda/content-cache-hydrator/content-fetcher.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { CONTENT_API_PATH_PREFIX, fetchContentForVaccine } from "@src/_lambda/content-cache-hydrator/content-fetcher";
22
import { VaccineInfo, VaccineType } from "@src/models/vaccine";
3+
import { Url } from "@src/utils/Url";
34
import config from "@src/utils/config";
45
import { ConfigMock, configBuilder } from "@test-data/config/builders";
56
import axios from "axios";
@@ -9,7 +10,7 @@ jest.mock("sanitize-data", () => ({ sanitize: jest.fn() }));
910

1011
describe("fetchContentForVaccine", () => {
1112
const testApiKey: string = "test-key";
12-
const testApiEndpoint: URL = new URL("https://test-endpoint/");
13+
const testApiEndpoint: Url = new Url("https://test-endpoint/");
1314
const testApiContent = { test: "content" };
1415
const mockedConfig = config as ConfigMock;
1516

src/_lambda/content-cache-hydrator/content-fetcher.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { VaccineInfo, VaccineType } from "@src/models/vaccine";
2+
import { Url } from "@src/utils/Url";
23
import config from "@src/utils/config";
34
import { logger } from "@src/utils/logger";
45
import axios, { AxiosError, AxiosResponse } from "axios";
@@ -7,7 +8,7 @@ const log = logger.child({ module: "content-fetcher" });
78
const CONTENT_API_PATH_PREFIX = "nhs-website-content/";
89

910
const fetchContentForVaccine = async (vaccineType: VaccineType): Promise<string> => {
10-
const apiEndpoint: URL = await config.CONTENT_API_ENDPOINT;
11+
const apiEndpoint: Url = await config.CONTENT_API_ENDPOINT;
1112
const vaccinePath = VaccineInfo[vaccineType].contentPath;
1213
const apiKey: string = await config.CONTENT_API_KEY;
1314

src/app/_components/content/FindOutMore.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { VaccineInfo, VaccineType } from "@src/models/vaccine";
2+
import { Url } from "@src/utils/Url";
23
import React, { JSX } from "react";
34

4-
const FindOutMoreLink = (props: { findOutMoreUrl: URL; vaccineType: VaccineType }): JSX.Element => {
5+
const FindOutMoreLink = (props: { findOutMoreUrl: Url; vaccineType: VaccineType }): JSX.Element => {
56
const vaccineInfo = VaccineInfo[props.vaccineType];
67

78
return (

src/app/_components/eligibility/EligibilityActions.test.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ActionDisplayType, ButtonUrl, Label } from "@src/services/eligibility-api/types";
2+
import { Url } from "@src/utils/Url";
23
import { actionBuilder, buttonBuilder } from "@test-data/eligibility-api/builders";
34
import { render, screen, within } from "@testing-library/react";
45
import React from "react";
@@ -288,7 +289,7 @@ describe("EligibilityActions", () => {
288289
.andButton(
289290
buttonBuilder()
290291
.withLabel("Action Link Test" as Label)
291-
.andUrl(new URL("https://example.com/bacon/") as ButtonUrl)
292+
.andUrl(new Url("https://example.com/bacon/") as ButtonUrl)
292293
.build(),
293294
)
294295
.build(),

src/app/_components/feedback/FeedbackBanner.test.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { FeedbackBanner } from "@src/app/_components/feedback/FeedbackBanner";
2+
import { Url } from "@src/utils/Url";
23
import { render, screen } from "@testing-library/react";
34

45
describe("FeedbackBanner", () => {
@@ -9,7 +10,7 @@ describe("FeedbackBanner", () => {
910

1011
const feedbackText: HTMLElement = screen.getByText(/This is a new NHS App service\. Help us improve it and/i);
1112
const feedbackLink: HTMLAnchorElement = screen.getByRole("link", { name: "give your feedback" });
12-
const feedbackUrl: URL = new URL(feedbackLink.href);
13+
const feedbackUrl: Url = new Url(feedbackLink.href);
1314

1415
expect(feedbackText).toBeVisible();
1516
expect(feedbackLink).toBeVisible();

src/app/_components/interceptor/LinksInterceptor.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ const LinksInterceptor = (): null => {
1414
const anchor: HTMLAnchorElement | null = target.closest("a");
1515
if (!anchor) return;
1616

17-
const url = new URL(anchor.href);
18-
const isExternal = url.origin !== window.location.origin;
17+
const isExternal = anchor.origin !== window.location.origin;
1918

2019
if (isExternal && hasContextLoaded && isOpenInMobileApp) {
2120
event.preventDefault(); // Stop default navigation

src/app/api/sso-to-nbs/route.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { SSO_FAILURE_ROUTE } from "@src/app/sso-failure/constants";
22
import { VaccineType } from "@src/models/vaccine";
33
import { getNbsQueryParams, getSSOUrlToNBSForVaccine } from "@src/services/nbs/nbs-service";
4+
import { Url } from "@src/utils/Url";
45
import { logger } from "@src/utils/logger";
56
import { getVaccineTypeFromLowercaseString } from "@src/utils/path";
67
import { profilePerformanceEnd, profilePerformanceStart } from "@src/utils/performance";
@@ -44,7 +45,7 @@ async function getGivenRedirectTarget(rawRedirectTarget: string | null) {
4445

4546
if (rawRedirectTarget) {
4647
try {
47-
const nbsURl = new URL(decodeURI(rawRedirectTarget ?? ""));
48+
const nbsURl = new Url(decodeURI(rawRedirectTarget ?? ""));
4849
try {
4950
const nbsQueryParams = await getNbsQueryParams();
5051
nbsQueryParams.forEach((param) => {

0 commit comments

Comments
 (0)