Skip to content

Commit

Permalink
fix: allow companies without address (#2234)
Browse files Browse the repository at this point in the history
Fix YTJ (Service Bus) integration to allow companies to be saved without address.
  • Loading branch information
mjturt authored Aug 30, 2023
1 parent a6d126f commit dc78d34
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion backend/benefit/companies/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def test_get_company_from_service_bus_invalid_response(
"BusinessId"
]
response = deepcopy(DUMMY_SERVICE_BUS_RESPONSE)
response["GetCompanyResult"]["Company"]["PostalAddress"] = {}
response["GetCompanyResult"]["Company"] = {}

matcher = re.compile(re.escape(SERVICE_BUS_INFO_PATH))
requests_mock.post(matcher, json=response)
Expand Down
11 changes: 8 additions & 3 deletions backend/shared/shared/service_bus/service_bus_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@ def _get_organisation_data_from_service_bus_data(
that hasn't been covered in the code
"""

address = cls._get_address(service_bus_data["PostalAddress"]["DomesticAddress"])
try:
address = cls._get_address(
service_bus_data["PostalAddress"]["DomesticAddress"]
)
except (KeyError, TypeError):
address = {"StreetAddress": "", "PostalCode": "", "City": ""}
company_data = {
"name": service_bus_data["TradeName"]["Name"],
"business_id": service_bus_data["BusinessId"],
Expand Down Expand Up @@ -152,10 +157,10 @@ def _get_company_form_code(legal_form_json: dict) -> int:
raise ValueError("Cannot determine company form - invalid PrimaryCode")
try:
return int(legal_form_json["Type"]["SecondaryCode"])
except (TypeError, ValueError) as e:
except (TypeError, ValueError) as exc:
raise ValueError(
"Cannot determine company form - invalid SecondaryCode"
) from e
) from exc

@staticmethod
def _get_finnish_description(descriptions: dict) -> Optional[dict]:
Expand Down

0 comments on commit dc78d34

Please sign in to comment.