@@ -13,7 +13,11 @@ import {
1313import getRestApiGatewayBaseUrl from "tests/helpers/aws-gateway-helper" ;
1414import { SUPPLIER_LETTERS } from "tests/constants/api-constants" ;
1515import { supplierDataSetup } from "tests/helpers/suppliers-setup-helper" ;
16- import { checkLetterQueueTable } from "tests/helpers/generate-fetch-test-data" ;
16+ import {
17+ checkLetterQueueTable ,
18+ getLetterFromQueueById ,
19+ } from "tests/helpers/generate-fetch-test-data" ;
20+ import { createValidRequestHeaders } from "../../constants/request-headers" ;
1721import {
1822 patchRequestHeaders ,
1923 patchValidRequestBody ,
@@ -104,4 +108,65 @@ test.describe("Letter Queue Tests", () => {
104108
105109 await pollUpsertLetterLogForWarning ( "Letter already exists" , letterId ) ;
106110 } ) ;
111+
112+ test ( "Verify if VisibilityTimeStamp is updated when Get /letters endpoint is called and subsequent calls returns no data until VisibilityTimeStamp is reached" , async ( {
113+ request,
114+ } ) => {
115+ const letterId = randomUUID ( ) ;
116+ logger . info ( `Sending event with domainId: ${ letterId } ` ) ;
117+ const preparedEvent = createPreparedV1Event ( { domainId : letterId } ) ;
118+ const response = await sendSnsEvent ( preparedEvent ) ;
119+
120+ expect ( response . MessageId ) . toBeTruthy ( ) ;
121+
122+ const supplierId = await supplierIdFromSupplierAllocatorLog ( letterId ) ;
123+
124+ await supplierDataSetup ( supplierId ) ;
125+
126+ const letters = await getLetterFromQueueById ( supplierId , letterId ) ;
127+ expect ( letters ) . toHaveLength ( 1 ) ;
128+ const letter = letters [ 0 ] ;
129+ expect ( letter . visibilityTimestamp ) . toBe ( letter . queueTimestamp ) ;
130+ logger . info (
131+ "Visibility timestamp is same as queue timestamp before calling Get /letters endpoint" ,
132+ ) ;
133+
134+ // call get letters endpoint which should update the visibility timestamp
135+ const header = createValidRequestHeaders ( supplierId ) ;
136+ const getLettersResponse = await request . get (
137+ `${ baseUrl } /${ SUPPLIER_LETTERS } ` ,
138+ {
139+ headers : header ,
140+ } ,
141+ ) ;
142+
143+ expect ( getLettersResponse . status ( ) ) . toBe ( 200 ) ;
144+ const currentTimeWithTimeOut = Math . floor (
145+ ( Date . now ( ) + 5 * 60 * 1000 ) / 1000 ,
146+ ) ;
147+
148+ logger . info (
149+ "Called Get /letters endpoint verify visibility timestamp is updated and subsequent calls returns no data until visibility timestamp is reached" ,
150+ ) ;
151+ const lettersAfterGet = await getLetterFromQueueById ( supplierId , letterId ) ;
152+ const visibilityTimestampAfterGet = Math . floor (
153+ new Date ( lettersAfterGet [ 0 ] . visibilityTimestamp ) . getTime ( ) / 1000 ,
154+ ) ;
155+
156+ // allow a 1 second tolerance
157+ expect (
158+ Math . abs ( visibilityTimestampAfterGet - currentTimeWithTimeOut ) ,
159+ ) . toBeLessThanOrEqual ( 1 ) ;
160+
161+ const getLettersWithInVisibility = await request . get (
162+ `${ baseUrl } /${ SUPPLIER_LETTERS } ` ,
163+ {
164+ headers : header ,
165+ } ,
166+ ) ;
167+
168+ expect ( getLettersWithInVisibility . status ( ) ) . toBe ( 200 ) ;
169+ const responseBody = await getLettersWithInVisibility . json ( ) ;
170+ expect ( responseBody . data ) . toHaveLength ( 0 ) ;
171+ } ) ;
107172} ) ;
0 commit comments