Skip to content

Commit 21efe7c

Browse files
VIA-629 SB & EO Build correct NBS URL.
1 parent 35647cb commit 21efe7c

File tree

4 files changed

+52
-11
lines changed

4 files changed

+52
-11
lines changed

src/models/vaccine.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ const VaccineInfo: Record<VaccineType, VaccineDetails> = {
337337
personalisedEligibilityStatusRequired: false,
338338
contentPath: "vaccinations/covid-19-vaccine" as UrlPathFragment,
339339
cacheFilename: "covid-19-vaccine.json" as Filename,
340-
nbsPath: "covid-19-vaccine" as UrlPathFragment, // TODO VIA-603: Is this correct?
340+
nbsPath: "covid" as UrlPathFragment,
341341
},
342342
[VaccineType.FLU_FOR_ADULTS]: {
343343
urlPath: "flu-vaccine" as UrlPathFragment,

src/services/content-api/parsers/custom/covid-19.test.ts

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,36 @@
11
import { buildFilteredContentForCovid19Vaccine } from "@src/services/content-api/parsers/custom/covid-19";
22
import { ActionDisplayType, ButtonUrl, Content, Label } from "@src/services/eligibility-api/types";
3+
import { Campaigns } from "@src/utils/campaigns/types";
4+
import config from "@src/utils/config";
5+
import { ConfigMock, configBuilder } from "@test-data/config/builders";
36
import { genericVaccineContentAPIResponse } from "@test-data/content-api/data";
47

58
jest.mock("sanitize-data", () => ({ sanitize: jest.fn() }));
69

10+
const nbsUrlFromConfig = new URL("https://test-nbs-url.example.com/sausages");
11+
const nbsBookingPathFromConfig = "/test/path/book";
12+
713
describe("buildFilteredContentForCovid19Vaccine", () => {
8-
process.env.CAMPAIGNS = JSON.stringify({
9-
COVID_19: [
10-
{ start: "2025-11-01T09:00:00Z", end: "2026-01-31T09:00:00Z" },
11-
{ start: "2026-11-01T09:00:00Z", end: "2027-01-31T09:00:00Z" },
12-
],
14+
const mockedConfig = config as ConfigMock;
15+
16+
beforeEach(() => {
17+
const defaultConfig = configBuilder()
18+
.withNbsUrl(nbsUrlFromConfig)
19+
.andNbsBookingPath(nbsBookingPathFromConfig)
20+
.andCampaigns(
21+
Campaigns.fromJson(
22+
JSON.stringify({
23+
COVID_19: [
24+
{ start: "2025-11-01T09:00:00Z", end: "2026-01-31T09:00:00Z" },
25+
{ start: "2026-11-01T09:00:00Z", end: "2027-01-31T09:00:00Z" },
26+
],
27+
}),
28+
)!,
29+
)
30+
.build();
31+
Object.assign(mockedConfig, defaultConfig);
1332
});
33+
1434
jest.useFakeTimers();
1535

1636
it("should return standard vaccine content and additional content for COVID-19 vaccine", async () => {
@@ -64,7 +84,10 @@ describe("buildFilteredContentForCovid19Vaccine", () => {
6484
{
6585
type: ActionDisplayType.buttonWithInfo,
6686
content: "## If this applies to you\n\n### Book an appointment online at a pharmacy" as Content,
67-
button: { label: "Continue to booking" as Label, url: new URL("https://example.com") as ButtonUrl },
87+
button: {
88+
label: "Continue to booking" as Label,
89+
url: new URL("https://test-nbs-url.example.com/sausages/test/path/book/covid") as ButtonUrl,
90+
},
6891
delineator: true,
6992
},
7093
{

src/services/content-api/parsers/custom/covid-19.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { VaccineType } from "@src/models/vaccine";
1+
import { VaccineInfo, VaccineType } from "@src/models/vaccine";
22
import { buildFilteredContentForStandardVaccine } from "@src/services/content-api/parsers/content-filter-service";
33
import { HeadingWithContent, HeadingWithTypedContent, VaccinePageContent } from "@src/services/content-api/types";
44
import {
@@ -25,7 +25,7 @@ export const buildFilteredContentForCovid19Vaccine = async (apiContent: string):
2525
if (campaigns.isActive(VaccineType.COVID_19)) {
2626
log.info("Campaign active");
2727
callout = undefined;
28-
actions.push(..._buildActions());
28+
actions.push(...(await _buildActions()));
2929
} else {
3030
log.info("No campaign active");
3131
callout = {
@@ -50,11 +50,18 @@ export const buildFilteredContentForCovid19Vaccine = async (apiContent: string):
5050
return { ...standardFilteredContent, callout, recommendation, actions };
5151
};
5252

53-
function _buildActions(): Action[] {
53+
async function _buildActions(): Promise<Action[]> {
54+
const nbsBaseUrl = await config.NBS_URL;
55+
const nbsBookingPath = await config.NBS_BOOKING_PATH;
56+
const nbsURl = new URL(
57+
`${nbsBaseUrl.pathname}${nbsBookingPath}/${VaccineInfo.COVID_19.nbsPath}`,
58+
nbsBaseUrl.origin,
59+
) as ButtonUrl;
60+
5461
const nbsBooking: ActionWithButton = {
5562
type: ActionDisplayType.buttonWithInfo,
5663
content: ["## If this applies to you", "### Book an appointment online at a pharmacy"].join("\n\n") as Content,
57-
button: { label: "Continue to booking" as Label, url: new URL("https://example.com") as ButtonUrl },
64+
button: { label: "Continue to booking" as Label, url: nbsURl },
5865
delineator: true,
5966
};
6067
const walkIn: ActionWithButton = {

test-data/config/builders.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Campaigns } from "@src/utils/campaigns/types";
12
import { AppConfig, ConfigValue } from "@src/utils/config";
23
import { randomBoolean, randomInteger, randomString, randomURL } from "@test-data/meta-builder";
34

@@ -24,6 +25,7 @@ class ConfigBuilder {
2425
MAX_SESSION_AGE_MINUTES: randomInteger(1, 999),
2526
IS_APIM_AUTH_ENABLED: randomBoolean(),
2627
AUTH_SECRET: randomString(10),
28+
CAMPAIGNS: Campaigns.fromJson("{}"),
2729
};
2830
}
2931

@@ -192,6 +194,15 @@ class ConfigBuilder {
192194
return this.withPinoLogLevel(value);
193195
}
194196

197+
public withCampaigns(value: Campaigns): this {
198+
this._configValues.CAMPAIGNS = value;
199+
return this;
200+
}
201+
202+
public andCampaigns(value: Campaigns): this {
203+
return this.withCampaigns(value);
204+
}
205+
195206
public build(): ConfigMock {
196207
const asyncMock: Record<string, Promise<ConfigValue>> = {};
197208
for (const key in this._configValues) {

0 commit comments

Comments
 (0)