@@ -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' , ( ) => {
@@ -43,56 +36,43 @@ describe('parseSqsRecord', () => {
4336 describe ( 'when SQS record contains a valid PDMResourceAvailable event' , ( ) => {
4437 it ( 'parses and returns the PDMResourceAvailable event' , ( ) => {
4538 const sqsRecord = createSqsRecord ( validPdmEvent ) ;
46- ( messagePDMResourceAvailableValidator as jest . Mock ) . mockReturnValueOnce (
47- true ,
48- ) ;
4939
5040 const result = parseSqsRecord ( sqsRecord , mockLogger ) ;
5141
5242 expect ( result ) . toEqual ( validPdmEvent ) ;
5343 expect ( mockLogger . info ) . toHaveBeenCalledWith ( 'Parsing SQS Record' , {
5444 messageId,
45+ body : sqsRecord . body ,
5546 } ) ;
5647 expect ( mockLogger . info ) . toHaveBeenCalledWith (
5748 'Parsed valid PDMResourceAvailable Event' ,
5849 {
5950 messageId,
51+ messageReference : validPdmEvent . data . messageReference ,
52+ senderId : validPdmEvent . data . senderId ,
53+ resourceId : validPdmEvent . data . resourceId ,
6054 } ,
6155 ) ;
62- expect ( messagePDMResourceAvailableValidator ) . toHaveBeenCalledWith (
63- validPdmEvent ,
64- ) ;
6556 } ) ;
6657 } ) ;
6758
6859 describe ( 'when SQS record contains an invalid PDMResourceAvailable event' , ( ) => {
6960 it ( 'logs error and throws InvalidPdmResourceAvailableEvent' , ( ) => {
7061 const invalidEvent = { ...validPdmEvent , data : { } } ;
7162 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 ;
8563
8664 expect ( ( ) => parseSqsRecord ( sqsRecord , mockLogger ) ) . toThrow (
8765 InvalidPdmResourceAvailableEvent ,
8866 ) ;
8967
90- expect ( mockLogger . error ) . toHaveBeenCalledWith ( {
91- err : validationErrors ,
92- description :
93- 'The SQS message does not contain a valid PDMResourceAvailable event' ,
94- messageId,
95- } ) ;
68+ expect ( mockLogger . error ) . toHaveBeenCalledWith (
69+ expect . objectContaining ( {
70+ description :
71+ 'The SQS message does not contain a valid PDMResourceAvailable event' ,
72+ messageId,
73+ err : expect . any ( Array ) ,
74+ } ) ,
75+ ) ;
9676 } ) ;
9777 } ) ;
9878
@@ -118,6 +98,7 @@ describe('parseSqsRecord', () => {
11898 expect ( ( ) => parseSqsRecord ( sqsRecord , mockLogger ) ) . toThrow ( SyntaxError ) ;
11999 expect ( mockLogger . info ) . toHaveBeenCalledWith ( 'Parsing SQS Record' , {
120100 messageId,
101+ body : sqsRecord . body ,
121102 } ) ;
122103 } ) ;
123104 } ) ;
0 commit comments