@@ -104,7 +104,7 @@ def get_event(event_name="INSERT", operation="operation", supplier="EMIS"):
104104 """Returns test event data."""
105105 return ValuesForTests .get_event (event_name , operation , supplier )
106106
107- def assert_dynamodb_record (self , operation_flag , items , expected_values , expected_imms , response ):
107+ def assert_dynamodb_record (self , operation_flag , action_flag , items , expected_values , expected_imms , response ):
108108 """
109109 Asserts that a record with the expected structure exists in DynamoDB.
110110 Ignores dynamically generated fields like PK, DateTimeStamp, and ExpiresAt.
@@ -117,6 +117,7 @@ def assert_dynamodb_record(self, operation_flag, items, expected_values, expecte
117117 {k : v for k , v in item .items () if k not in ["PK" , "DateTimeStamp" , "ExpiresAt" ]}
118118 for item in items
119119 if item .get ("Operation" ) == operation_flag
120+ and item .get ("Imms" , {}).get ("ACTION_FLAG" ) == action_flag
120121 ]
121122
122123 self .assertGreater (len (filtered_items ), 0 , f"No matching item found for { operation_flag } " )
@@ -126,12 +127,7 @@ def assert_dynamodb_record(self, operation_flag, items, expected_values, expecte
126127 self .assertGreater (len (imms_data ), 0 )
127128
128129 # Check Imms JSON structure matches exactly
129- # self.assertEqual(imms_data, expected_imms, "Imms data does not match expected JSON structure")
130- for key , expected_value in expected_imms .items ():
131- actual = imms_data .get (key )
132- print (f"Key: { key } , Actual: { actual } , Expected: { expected_value } " )
133- self .assertEqual (actual , expected_value , f"{ key } mismatch" )
134-
130+ self .assertEqual (imms_data , expected_imms , "Imms data does not match expected JSON structure" )
135131
136132 for key , expected_value in expected_values .items ():
137133 self .assertIn (key , filtered_items [0 ], f"{ key } is missing" )
@@ -171,7 +167,7 @@ def test_fhir_converter_json_error_scenario(self):
171167 def test_handler_imms_convert_to_flat_json (self ):
172168 """Test that the Imms field contains the correct flat JSON data for CREATE, UPDATE, and DELETE operations."""
173169 expected_action_flags = [
174- {"Operation" : "CREATE" , "EXPECTED_ACTION_FLAG" : "CREATE " },
170+ {"Operation" : "CREATE" , "EXPECTED_ACTION_FLAG" : "NEW " },
175171 {"Operation" : "UPDATE" , "EXPECTED_ACTION_FLAG" : "UPDATE" },
176172 {"Operation" : "DELETE" , "EXPECTED_ACTION_FLAG" : "DELETE" },
177173 ]
@@ -191,7 +187,9 @@ def test_handler_imms_convert_to_flat_json(self):
191187 expected_imms = ValuesForTests .get_expected_imms (test_case ["EXPECTED_ACTION_FLAG" ])
192188
193189 self .assert_dynamodb_record (
194- test_case ["EXPECTED_ACTION_FLAG" ], items , expected_values , expected_imms , response
190+ test_case ["Operation" ],
191+ test_case ["EXPECTED_ACTION_FLAG" ],
192+ items , expected_values , expected_imms , response
195193 )
196194
197195 result = self .table .scan ()
0 commit comments