@@ -4,42 +4,48 @@ import { Campaigns } from "@src/utils/campaigns/types";
44jest . mock ( "sanitize-data" , ( ) => ( { sanitize : jest . fn ( ) } ) ) ;
55
66describe ( "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 ) ;
0 commit comments