Skip to content

Commit 04658e1

Browse files
test
1 parent 3186616 commit 04658e1

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

tests/helpers/generate-fetch-test-data.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,3 +263,46 @@ export async function getLettersFromQueueViaIndex(
263263
return [];
264264
}
265265
}
266+
267+
export async function getLetterFromQueueById(
268+
supplierId: string,
269+
letterId: string,
270+
): Promise<PendingLetter[]> {
271+
const MAX_ATTEMPTS = 5;
272+
const RETRY_DELAY_MS = 10_000;
273+
274+
try {
275+
const params = {
276+
TableName: LETTERQUEUE_TABLENAME,
277+
KeyConditionExpression:
278+
"supplierId = :supplierId AND letterId = :letterId",
279+
ExpressionAttributeValues: {
280+
":supplierId": supplierId,
281+
":letterId": letterId,
282+
},
283+
};
284+
285+
for (let attempt = 1; attempt <= MAX_ATTEMPTS; attempt++) {
286+
const { Items } = await docClient.send(new QueryCommand(params));
287+
288+
if (Items !== undefined && Items.length > 0) {
289+
logger.info(
290+
`Queried letter queue table to verify existence for supplier ${supplierId} and found items.`,
291+
);
292+
293+
// assumes no pagination needed as we expect a small number of letters in the queue for the test supplier
294+
return z.array(PendingLetterSchema).parse(Items);
295+
}
296+
if (attempt < MAX_ATTEMPTS) {
297+
logger.info(
298+
`Retrying get letters from queue for supplierId ${supplierId} in ${RETRY_DELAY_MS}ms`,
299+
);
300+
await delay(RETRY_DELAY_MS);
301+
}
302+
}
303+
return [];
304+
} catch (error) {
305+
logger.error({ supplierId, error }, "Letter queue query failed");
306+
return [];
307+
}
308+
}

0 commit comments

Comments
 (0)