Skip to content

Commit 9e7184f

Browse files
VIA-537 SB & AS Fix URL concatenation in getSSOUrlToNBSForVaccine().
1 parent 561b2a9 commit 9e7184f

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/services/nbs/nbs-service.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jest.mock("@src/utils/auth/generate-auth-payload", () => ({
99
}));
1010
jest.mock("sanitize-data", () => ({ sanitize: jest.fn() }));
1111

12-
const nbsUrlFromConfig = new URL("https://test-nbs-url");
12+
const nbsUrlFromConfig = new URL("https://test-nbs-url.example.com/sausages");
1313
const nbsBookingPathFromConfig = "/test/path/book";
1414

1515
const mockAssertedLoginIdentityJWT = "mock-jwt";
@@ -31,7 +31,8 @@ describe("getSSOUrlToNBSForVaccine", () => {
3131
it("returns sso url of NBS configured in config for RSV vaccine", async () => {
3232
const nbsRedirectUrl = new URL(await getSSOUrlToNBSForVaccine(VaccineType.RSV));
3333
expect(nbsRedirectUrl.origin).toEqual(nbsUrlFromConfig.origin);
34-
expect(nbsRedirectUrl.pathname).toEqual(`${nbsBookingPathFromConfig}/rsv`);
34+
expect(nbsRedirectUrl.pathname).toEqual(`/sausages${nbsBookingPathFromConfig}/rsv`);
35+
expect(nbsRedirectUrl.href).toMatch(/^https:\/\/test-nbs-url\.example\.com\/sausages\/test\/path\/book\/rsv.*/);
3536
});
3637

3738
it("should include campaignID query param in NBS URL", async () => {

src/services/nbs/nbs-service.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@ const nbsVaccinePath: Record<VaccinesWithNBSBookingAvailable, string> = {
2626
const getSSOUrlToNBSForVaccine = async (vaccineType: VaccinesWithNBSBookingAvailable) => {
2727
let redirectUrl;
2828
try {
29-
const nbsURl = new URL(
30-
`${await lazyConfig.NBS_BOOKING_PATH}${nbsVaccinePath[vaccineType]}`,
31-
(await lazyConfig.NBS_URL) as URL,
32-
);
29+
const nbsBaseUrl = (await lazyConfig.NBS_URL) as URL;
30+
const nbsBookingPath = await lazyConfig.NBS_BOOKING_PATH;
31+
const nbsURl = new URL(`${nbsBaseUrl.pathname}${nbsBookingPath}${nbsVaccinePath[vaccineType]}`, nbsBaseUrl.origin);
3332
const nbsQueryParams = await getNbsQueryParams();
3433
nbsQueryParams.forEach((param) => {
3534
nbsURl.searchParams.append(param.name, param.value);

0 commit comments

Comments
 (0)