Skip to content

Commit 4cba018

Browse files
VIA-629 SB Campaigns now use date-times, not just times.
1 parent cf7f9ad commit 4cba018

File tree

9 files changed

+46
-38
lines changed

9 files changed

+46
-38
lines changed

.env.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ PROFILE_PERFORMANCE=true
77
DEPLOY_ENVIRONMENT=local
88

99
# Vaccs campaigns
10-
CAMPAIGNS='{"COVID_19": [{ "start": "2025-11-12", "end": "2026-01-31" }, { "start": "2026-11-01", "end": "2027-01-31" }]}'
10+
CAMPAIGNS='{"COVID_19": [{ "start": "2025-11-12T09:00:00Z", "end": "2026-01-31T09:00:00Z" }, { "start": "2026-11-01T09:00:00Z", "end": "2027-01-31T09:00:00Z" }]}'
1111

1212
# content cache hydrator
1313
CONTENT_API_ENDPOINT=http://localhost:8081/
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"COVID_19": [
3-
{ "start": "2025-11-12", "end": "2026-01-31" },
4-
{ "start": "2026-11-01", "end": "2027-01-31" }
3+
{ "start": "2025-11-12T09:00:00Z", "end": "2026-01-31T09:00:00Z" },
4+
{ "start": "2026-11-01T09:00:00Z", "end": "2027-01-31T09:00:00Z" }
55
]
66
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"COVID_19": [
3-
{ "start": "2025-11-12", "end": "2026-01-31" },
4-
{ "start": "2026-11-01", "end": "2027-01-31" }
3+
{ "start": "2025-11-12T09:00:00Z", "end": "2026-01-31T09:00:00Z" },
4+
{ "start": "2026-11-01T09:00:00Z", "end": "2027-01-31T09:00:00Z" }
55
]
66
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"COVID_19": [
3-
{ "start": "2025-11-12", "end": "2026-01-31" },
4-
{ "start": "2026-11-01", "end": "2027-01-31" }
3+
{ "start": "2025-11-12T09:00:00Z", "end": "2026-01-31T09:00:00Z" },
4+
{ "start": "2026-11-01T09:00:00Z", "end": "2027-01-31T09:00:00Z" }
55
]
66
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"COVID_19": [
3-
{ "start": "2025-11-12", "end": "2026-01-31" },
4-
{ "start": "2026-11-01", "end": "2027-01-31" }
3+
{ "start": "2025-11-12T09:00:00Z", "end": "2026-01-31T09:00:00Z" },
4+
{ "start": "2026-11-01T09:00:00Z", "end": "2027-01-31T09:00:00Z" }
55
]
66
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ jest.mock("sanitize-data", () => ({ sanitize: jest.fn() }));
66
describe("buildFilteredContentForCovid19Vaccine", () => {
77
process.env.CAMPAIGNS = JSON.stringify({
88
COVID_19: [
9-
{ start: "2025-11-01", end: "2026-01-31" },
10-
{ start: "2026-11-01", end: "2027-01-31" },
9+
{ start: "2025-11-01T09:00:00Z", end: "2026-01-31T09:00:00Z" },
10+
{ start: "2026-11-01T09:00:00Z", end: "2027-01-31T09:00:00Z" },
1111
],
1212
});
1313
jest.useFakeTimers();

src/utils/campaigns/types.test.ts

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,48 @@ import { Campaigns } from "@src/utils/campaigns/types";
44
jest.mock("sanitize-data", () => ({ sanitize: jest.fn() }));
55

66
describe("Campaigns", () => {
7-
it("should convert json to a Campaigns ", async () => {
8-
const jsonString = JSON.stringify({
9-
COVID_19: [
10-
{ start: "2025-11-12", end: "2026-03-01" },
11-
{ start: "2026-09-01", end: "2027-03-01" },
12-
],
13-
FLU_FOR_ADULTS: [
14-
{ start: "2025-11-12", end: "2026-03-01" },
15-
{ start: "2026-09-01", end: "2027-03-01" },
16-
],
17-
});
7+
const jsonString = JSON.stringify({
8+
COVID_19: [
9+
{ start: "2025-11-12T09:00:00Z", end: "2026-03-01T09:00:00+02:00" },
10+
{ start: "2026-09-01T09:00:00+02:00", end: "2027-03-01T09:00:00Z" },
11+
],
12+
FLU_FOR_ADULTS: [
13+
{ start: "2025-11-12T09:00:00+02:00", end: "2026-03-01T09:00:00Z" },
14+
{ start: "2026-09-01T09:00:00Z", end: "2027-03-01T09:00:00+02:00" },
15+
],
16+
});
1817

18+
it("should convert json to a Campaigns ", async () => {
1919
const actual = Campaigns.fromJson(jsonString);
2020

2121
expect(actual!.get(VaccineType.COVID_19)).toStrictEqual([
22-
{ start: new Date("2025-11-12"), end: new Date("2026-03-01") },
23-
{ start: new Date("2026-09-01"), end: new Date("2027-03-01") },
22+
{ start: new Date("2025-11-12T09:00:00Z"), end: new Date("2026-03-01T07:00:00Z") },
23+
{ start: new Date("2026-09-01T07:00:00Z"), end: new Date("2027-03-01T09:00:00Z") },
2424
]);
2525

2626
expect(actual!.get(VaccineType.FLU_FOR_ADULTS)).toStrictEqual([
27-
{ start: new Date("2025-11-12"), end: new Date("2026-03-01") },
28-
{ start: new Date("2026-09-01"), end: new Date("2027-03-01") },
27+
{ start: new Date("2025-11-12T07:00:00Z"), end: new Date("2026-03-01T09:00:00Z") },
28+
{ start: new Date("2026-09-01T09:00:00Z"), end: new Date("2027-03-01T07:00:00Z") },
2929
]);
3030
});
3131

3232
describe("isActive", () => {
33-
const jsonString = JSON.stringify({ COVID_19: [{ start: "2025-11-12", end: "2026-03-01" }] });
3433
const campaigns = Campaigns.fromJson(jsonString)!;
3534

3635
it.each([
37-
["is inactive before start date", "2025-11-11", false],
38-
["is active on start date", "2025-11-12", true],
39-
["is active during campaign", "2025-12-25", true],
40-
["is active on end date", "2026-03-01", true],
41-
["is inactive after end date", "2026-03-02", false],
42-
["is inactive in different year", "2024-01-01", false],
36+
["inactive: before first start", "2025-11-12T08:59:59Z", false],
37+
["active: exact first start", "2025-11-12T09:00:00Z", true],
38+
["active: during first range", "2025-12-25T12:00:00Z", true],
39+
["active: exact first end", "2026-03-01T07:00:00Z", true],
40+
["inactive: 1 sec after first end", "2026-03-01T07:00:01Z", false],
41+
["inactive: in the gap (May)", "2026-05-01T09:00:00Z", false],
42+
["inactive: just before 2nd start", "2026-09-01T06:59:59Z", false],
43+
["active: exact second start", "2026-09-01T07:00:00Z", true],
44+
["active: during second range", "2026-12-25T12:00:00Z", true],
45+
["active: exact second end", "2027-03-01T09:00:00Z", true],
46+
["inactive: after second end", "2027-03-01T09:00:01Z", false],
47+
["inactive: way before", "2020-01-01T00:00:00Z", false],
48+
["inactive: way after", "2030-01-01T00:00:00Z", false],
4349
])("%s (%s) -> %s", (_, dateStr, expected) => {
4450
const dateToCheck = new Date(dateStr);
4551
const actual = campaigns.isActive(VaccineType.COVID_19, dateToCheck);

src/utils/campaigns/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { VaccineType } from "@src/models/vaccine";
2-
import { UtcDateFromStringSchema } from "@src/utils/date";
2+
import { UtcDateTimeFromStringSchema } from "@src/utils/date";
33
import { logger } from "@src/utils/logger";
44
import { Logger } from "pino";
55
import { z } from "zod";
@@ -8,8 +8,8 @@ const log: Logger = logger.child({ module: "campaigns" });
88

99
const CampaignSchema = z
1010
.object({
11-
start: UtcDateFromStringSchema,
12-
end: UtcDateFromStringSchema,
11+
start: UtcDateTimeFromStringSchema,
12+
end: UtcDateTimeFromStringSchema,
1313
})
1414
.refine((data) => data.end >= data.start, {
1515
message: "End date must be after start date",

src/utils/config.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,14 @@ describe("lazyConfig", () => {
8989

9090
it("should convert CAMPAIGNS to a Campaigns ", async () => {
9191
setupTestEnvVars("test/");
92-
process.env.CAMPAIGNS = JSON.stringify({ COVID_19: [{ start: "2025-11-12", end: "2026-03-01" }] });
92+
process.env.CAMPAIGNS = JSON.stringify({
93+
COVID_19: [{ start: "2025-11-12T09:00:00Z", end: "2026-03-01T09:00:00+02:00" }],
94+
});
9395

9496
const actual = await config.CAMPAIGNS;
9597

9698
expect(actual.get(VaccineType.COVID_19)).toStrictEqual([
97-
{ start: new Date("2025-11-12"), end: new Date("2026-03-01") },
99+
{ start: new Date("2025-11-12T09:00:00Z"), end: new Date("2026-03-01T07:00:00Z") },
98100
]);
99101
});
100102

0 commit comments

Comments
 (0)