@@ -24,7 +24,6 @@ const mockAddDimensions = Metrics.prototype.addDimensions as Mock;
2424const mockSerializeMetrics = Metrics . prototype . serializeMetrics as Mock ;
2525
2626const loggerErrorSpy = vi . spyOn ( logger , 'error' ) ;
27- const loggerWarnSpy = vi . spyOn ( logger , 'warn' ) ;
2827
2928describe ( 'Account Deletion Processor' , ( ) => {
3029 let mockEvent : SQSEvent ;
@@ -110,46 +109,58 @@ describe('Account Deletion Processor', () => {
110109 mockRecord = { ...mockRecord , body : mockBody } ;
111110 mockEvent = { Records : [ mockRecord ] } ;
112111 await handler ( mockEvent , mockContext ) ;
113- expect ( loggerErrorSpy ) . toHaveBeenCalledWith ( 'The SQS message can not be parsed. ✖ Invalid input' ) ;
112+ expect ( loggerErrorSpy )
113+ . toHaveBeenCalledWith ( `The SQS message can not be parsed. ✖ Invalid input: expected "AUTH_DELETE_ACCOUNT"
114+ → at event_name
115+ ✖ Invalid input: expected object, received undefined
116+ → at user` ) ;
114117 } ) ;
115118
116119 it ( "does not process the SQS Record when the message doesn't contain user id" , async ( ) => {
117120 const mockBody = JSON . stringify ( { event_name : 'AUTH_DELETE_ACCOUNT' } ) ;
118121 mockRecord = { ...mockRecord , body : mockBody } ;
119122 mockEvent = { Records : [ mockRecord ] } ;
120123 await handler ( mockEvent , mockContext ) ;
121- expect ( loggerWarnSpy ) . toHaveBeenCalledWith ( 'Attribute missing: user_id.' ) ;
124+ expect ( loggerErrorSpy )
125+ . toHaveBeenCalledWith ( `The SQS message can not be parsed. ✖ Invalid input: expected object, received undefined
126+ → at user` ) ;
122127 } ) ;
123128
124129 it ( 'does not process the SQS Record when user_id is an empty string in the SNS Event' , async ( ) => {
125- const mockBody = JSON . stringify ( { event_name : 'AUTH_DELETE_ACCOUNT' , user_id : '' } ) ;
130+ const mockBody = JSON . stringify ( { event_name : 'AUTH_DELETE_ACCOUNT' , user : { user_id : '' } } ) ;
126131 mockRecord = { ...mockRecord , body : mockBody } ;
127132 mockEvent = { Records : [ mockRecord ] } ;
128133 await handler ( mockEvent , mockContext ) ;
129- expect ( loggerWarnSpy ) . toHaveBeenCalledWith ( 'Attribute invalid: user_id is empty.' ) ;
134+ expect ( loggerErrorSpy )
135+ . toHaveBeenCalledWith ( `The SQS message can not be parsed. ✖ String cannot be empty or just spaces
136+ → at user.user_id` ) ;
130137 } ) ;
131138
132139 it ( 'does not process the SQS Record when user_id is a string with whitespaces in the SNS Event and tests the trim function' , async ( ) => {
133- const mockBody = JSON . stringify ( { event_name : 'AUTH_DELETE_ACCOUNT' , user_id : ' ' } ) ;
140+ const mockBody = JSON . stringify ( { event_name : 'AUTH_DELETE_ACCOUNT' , user : { user_id : ' ' } } ) ;
134141 mockRecord = { ...mockRecord , body : mockBody } ;
135142 mockEvent = { Records : [ mockRecord ] } ;
136143 await handler ( mockEvent , mockContext ) ;
137- expect ( loggerWarnSpy ) . toHaveBeenCalledWith ( 'Attribute invalid: user_id is empty.' ) ;
144+ expect ( loggerErrorSpy )
145+ . toHaveBeenCalledWith ( `The SQS message can not be parsed. ✖ String cannot be empty or just spaces
146+ → at user.user_id` ) ;
138147 } ) ;
139148
140149 it ( 'does not process the SQS Record when user_id is not a string' , async ( ) => {
141- const mockBody = JSON . stringify ( { event_name : 'AUTH_DELETE_ACCOUNT' , user_id : 123 } ) ;
150+ const mockBody = JSON . stringify ( { event_name : 'AUTH_DELETE_ACCOUNT' , user : { user_id : 123 } } ) ;
142151 mockRecord = { ...mockRecord , body : mockBody } ;
143152 mockEvent = { Records : [ mockRecord ] } ;
144153 await handler ( mockEvent , mockContext ) ;
145- expect ( loggerErrorSpy ) . toHaveBeenCalledWith ( `The SQS message can not be parsed. ✖ Invalid input` ) ;
154+ expect ( loggerErrorSpy )
155+ . toHaveBeenCalledWith ( `The SQS message can not be parsed. ✖ Invalid input: expected string, received number
156+ → at user.user_id` ) ;
146157 } ) ;
147158
148159 it ( 'successfully processes the message when the user id passed contains trailing spaces' , async ( ) => {
149160 mockDynamoDBServiceUpdateDeleteStatus . mockReturnValueOnce ( [ '1' ] ) ;
150161 const mockBody = JSON . stringify ( {
151162 event_name : 'AUTH_DELETE_ACCOUNT' ,
152- user_id : 'abcdef ' ,
163+ user : { user_id : 'abcdef ' } ,
153164 } ) ;
154165 mockRecord = { ...mockRecord , body : mockBody } ;
155166 mockEvent = { Records : [ mockRecord ] } ;
@@ -241,7 +252,9 @@ describe('Account Deletion Processor', () => {
241252 ...mockRecord ,
242253 body : JSON . stringify ( {
243254 event_name : 'AUTH_DELETE_ACCOUNT' ,
244- user_id : 'other_user_id' ,
255+ user : {
256+ user_id : 'other_user_id' ,
257+ } ,
245258 } ) ,
246259 } ;
247260 const mockEvent = { Records : [ mockRecord , mockRecord2 ] } ;
0 commit comments