@@ -5,13 +5,6 @@ import { parseSqsRecord } from 'app/parse-sqs-message';
55import { InvalidPdmResourceAvailableEvent } from 'domain/invalid-pdm-resource-available-event' ;
66import { validPdmEvent } from '__tests__/constants' ;
77
8- // Import the mocked validator after the mock setup
9- import { messagePDMResourceAvailableValidator } from 'digital-letters-events/PDMResourceAvailable.js' ;
10-
11- jest . mock ( 'digital-letters-events/PDMResourceAvailable.js' , ( ) => ( {
12- messagePDMResourceAvailableValidator : jest . fn ( ) ,
13- } ) ) ;
14-
158const mockLogger = mock < Logger > ( ) ;
169
1710describe ( 'parseSqsRecord' , ( ) => {
@@ -20,9 +13,7 @@ describe('parseSqsRecord', () => {
2013 const createSqsRecord = ( detail : any ) : SQSRecord => ( {
2114 messageId,
2215 receiptHandle : 'receipt-handle' ,
23- body : JSON . stringify ( {
24- detail,
25- } ) ,
16+ body : JSON . stringify ( detail ) ,
2617 attributes : {
2718 ApproximateReceiveCount : '1' ,
2819 SentTimestamp : '1234567890' ,
@@ -43,56 +34,43 @@ describe('parseSqsRecord', () => {
4334 describe ( 'when SQS record contains a valid PDMResourceAvailable event' , ( ) => {
4435 it ( 'parses and returns the PDMResourceAvailable event' , ( ) => {
4536 const sqsRecord = createSqsRecord ( validPdmEvent ) ;
46- ( messagePDMResourceAvailableValidator as jest . Mock ) . mockReturnValueOnce (
47- true ,
48- ) ;
4937
5038 const result = parseSqsRecord ( sqsRecord , mockLogger ) ;
5139
5240 expect ( result ) . toEqual ( validPdmEvent ) ;
5341 expect ( mockLogger . info ) . toHaveBeenCalledWith ( 'Parsing SQS Record' , {
5442 messageId,
43+ body : sqsRecord . body ,
5544 } ) ;
5645 expect ( mockLogger . info ) . toHaveBeenCalledWith (
5746 'Parsed valid PDMResourceAvailable Event' ,
5847 {
5948 messageId,
49+ messageReference : validPdmEvent . data . messageReference ,
50+ senderId : validPdmEvent . data . senderId ,
51+ resourceId : validPdmEvent . data . resourceId ,
6052 } ,
6153 ) ;
62- expect ( messagePDMResourceAvailableValidator ) . toHaveBeenCalledWith (
63- validPdmEvent ,
64- ) ;
6554 } ) ;
6655 } ) ;
6756
6857 describe ( 'when SQS record contains an invalid PDMResourceAvailable event' , ( ) => {
6958 it ( 'logs error and throws InvalidPdmResourceAvailableEvent' , ( ) => {
7059 const invalidEvent = { ...validPdmEvent , data : { } } ;
7160 const sqsRecord = createSqsRecord ( invalidEvent ) ;
72- const validationErrors = [
73- {
74- instancePath : '/data' ,
75- schemaPath : '#/properties/data/required' ,
76- keyword : 'required' ,
77- params : { missingProperty : 'senderId' } ,
78- message : "must have required property 'senderId'" ,
79- } ,
80- ] ;
81- ( messagePDMResourceAvailableValidator as jest . Mock ) . mockReturnValueOnce (
82- false ,
83- ) ;
84- messagePDMResourceAvailableValidator . errors = validationErrors ;
8561
8662 expect ( ( ) => parseSqsRecord ( sqsRecord , mockLogger ) ) . toThrow (
8763 InvalidPdmResourceAvailableEvent ,
8864 ) ;
8965
90- expect ( mockLogger . error ) . toHaveBeenCalledWith ( {
91- err : validationErrors ,
92- description :
93- 'The SQS message does not contain a valid PDMResourceAvailable event' ,
94- messageId,
95- } ) ;
66+ expect ( mockLogger . error ) . toHaveBeenCalledWith (
67+ expect . objectContaining ( {
68+ description :
69+ 'The SQS message does not contain a valid PDMResourceAvailable event' ,
70+ messageId,
71+ err : expect . any ( Array ) ,
72+ } ) ,
73+ ) ;
9674 } ) ;
9775 } ) ;
9876
@@ -118,6 +96,7 @@ describe('parseSqsRecord', () => {
11896 expect ( ( ) => parseSqsRecord ( sqsRecord , mockLogger ) ) . toThrow ( SyntaxError ) ;
11997 expect ( mockLogger . info ) . toHaveBeenCalledWith ( 'Parsing SQS Record' , {
12098 messageId,
99+ body : sqsRecord . body ,
121100 } ) ;
122101 } ) ;
123102 } ) ;
0 commit comments