@@ -24,6 +24,12 @@ def test_person_postal_code_single_address(self):
2424 "type" : "physical" ,
2525 "period" : {"start" : "2018-01-01" , "end" : "2020-12-31" },
2626 }]
27+
28+ def test_person_postal_code_single_address_only_postal_code (self ):
29+ """Test case where only one address instance exists with one postalCode"""
30+ self .request_json_data ["contained" ][1 ]["address" ] = [{
31+ "postalCode" : "AB12 3CD" ,
32+ }]
2733
2834 expected_postal_code = "AB12 3CD"
2935 self ._run_postal_code_test (expected_postal_code )
@@ -94,6 +100,25 @@ def test_person_postal_code_fallback_first_non_old(self):
94100 expected_postal_code = "KK20 2KK"
95101 self ._run_postal_code_test (expected_postal_code )
96102
103+ def test_person_postal_code_case_insensitive_match (self ):
104+ """Test case where 'use' and 'type' values require case-insensitive comparison"""
105+ self .request_json_data ["contained" ][1 ]["address" ] = [
106+ {
107+ "postalCode" : "LS8 4ED" ,
108+ "use" : "work" ,
109+ "type" : "both" ,
110+ "period" : {"start" : "2000-01-01" , "end" : "2023-01-01" },
111+ },
112+ {
113+ "postalCode" : "WF8 4ED" ,
114+ "use" : "Home" , # capital H
115+ "type" : "Physical" , # capital P
116+ "period" : {"start" : "2000-01-01" , "end" : "2023-01-01" },
117+ }
118+ ]
119+ expected_postal_code = "WF8 4ED"
120+ self ._run_postal_code_test (expected_postal_code )
121+
97122 def test_person_postal_code_default_to_ZZ99_3CZ (self ):
98123 """Test case where no valid postalCode is found, should default to ZZ99 3CZ"""
99124 self .request_json_data ["contained" ][1 ]["address" ] = [
@@ -103,6 +128,22 @@ def test_person_postal_code_default_to_ZZ99_3CZ(self):
103128 expected_postal_code = "ZZ99 3CZ"
104129 self ._run_postal_code_test (expected_postal_code )
105130
131+ def test_person_postal_code_blank_string_should_fallback (self ):
132+ """Test case where postalCode is an empty string — should fallback to ZZ99 3CZ"""
133+ self .request_json_data ["contained" ][1 ]["address" ] = [
134+ {"postalCode" : "" ,
135+ "use" : "home" ,
136+ "type" : "physical" ,
137+ "period" : {"start" : "2018-01-01" , "end" : "2030-12-31" },
138+ },
139+ ]
140+ expected_postal_code = "ZZ99 3CZ"
141+ self ._run_postal_code_test (expected_postal_code )
142+ assert "postalCode" in self .request_json_data ["contained" ][1 ]["address" ][0 ]
143+ assert self .request_json_data ["contained" ][1 ]["address" ][0 ]["postalCode" ] == ""
144+
145+
146+
106147 def _run_postal_code_test (self , expected_postal_code ):
107148 """Helper function to run the test"""
108149 self .converter = Converter (json .dumps (self .request_json_data ))
0 commit comments