@@ -5,9 +5,11 @@ import { Campaigns } from "@src/utils/campaigns/types";
55import config from "@src/utils/config" ;
66import { ConfigMock , configBuilder } from "@test-data/config/builders" ;
77import { genericVaccineContentAPIResponse } from "@test-data/content-api/data" ;
8+ import { headers } from "next/headers" ;
89
910jest . mock ( "sanitize-data" , ( ) => ( { sanitize : jest . fn ( ) } ) ) ;
1011jest . mock ( "@src/services/nbs/nbs-service" , ( ) => ( { buildNbsUrl : jest . fn ( ) } ) ) ;
12+ jest . mock ( "next/headers" ) ;
1113
1214describe ( "buildFilteredContentForCovid19Vaccine" , ( ) => {
1315 const mockedConfig = config as ConfigMock ;
@@ -28,6 +30,11 @@ describe("buildFilteredContentForCovid19Vaccine", () => {
2830 Object . assign ( mockedConfig , defaultConfig ) ;
2931
3032 ( buildNbsUrl as jest . Mock ) . mockResolvedValue ( new URL ( "https://test-nbs-url.example.com/sausages" ) ) ;
33+
34+ const mockHeaders = {
35+ get : jest . fn ( ) ,
36+ } ;
37+ ( headers as jest . Mock ) . mockResolvedValue ( mockHeaders ) ;
3138 } ) ;
3239
3340 jest . useFakeTimers ( ) ;
@@ -112,4 +119,36 @@ describe("buildFilteredContentForCovid19Vaccine", () => {
112119 expect ( pageCopy ) . toEqual ( expect . objectContaining ( expected ) ) ;
113120 expect ( pageCopy . callout ) . toBeUndefined ( ) ;
114121 } ) ;
122+
123+ describe ( "with x-e2e-datetime header set" , ( ) => {
124+ it ( "should return a callout but no actions when no campaign is active" , async ( ) => {
125+ const mockHeaders = {
126+ get : jest . fn ( ( key : string ) => {
127+ if ( key === "x-e2e-datetime" ) return "2025-10-01T12:00:00Z" ;
128+ return null ;
129+ } ) ,
130+ } ;
131+ ( headers as jest . Mock ) . mockResolvedValue ( mockHeaders ) ;
132+
133+ const pageCopy = await buildFilteredContentForCovid19Vaccine ( JSON . stringify ( genericVaccineContentAPIResponse ) ) ;
134+
135+ expect ( pageCopy . callout ) . not . toBeUndefined ( ) ;
136+ expect ( pageCopy . actions ) . toHaveLength ( 0 ) ;
137+ } ) ;
138+
139+ it ( "should return actions but no callout when no campaign is active" , async ( ) => {
140+ const mockHeaders = {
141+ get : jest . fn ( ( key : string ) => {
142+ if ( key === "x-e2e-datetime" ) return "2025-12-01T12:00:00Z" ;
143+ return null ;
144+ } ) ,
145+ } ;
146+ ( headers as jest . Mock ) . mockResolvedValue ( mockHeaders ) ;
147+
148+ const pageCopy = await buildFilteredContentForCovid19Vaccine ( JSON . stringify ( genericVaccineContentAPIResponse ) ) ;
149+
150+ expect ( pageCopy . callout ) . toBeUndefined ( ) ;
151+ expect ( pageCopy . actions ) . not . toHaveLength ( 0 ) ;
152+ } ) ;
153+ } ) ;
115154} ) ;
0 commit comments