Skip to content

Commit

Permalink
Hl 1455 (#3291)
Browse files Browse the repository at this point in the history
* feat: clear error_from_ahjo on success

* feat: no update request if errors in decision req
  • Loading branch information
rikuke authored Sep 10, 2024
1 parent d6a7f83 commit 8a8408a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
5 changes: 5 additions & 0 deletions backend/benefit/applications/api/v1/ahjo_integration_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ def handle_success_callback(
) -> Response:
try:
with transaction.atomic():
# Clear any previous error messages before creating a new success status
latest_status = application.ahjo_status.latest()
if latest_status.error_from_ahjo is not None:
latest_status.error_from_ahjo = None
latest_status.save()
info = self.cb_info_message(application, callback_data, request_type)
if request_type == AhjoRequestType.OPEN_CASE:
self._handle_open_case_success(application, callback_data)
Expand Down
10 changes: 8 additions & 2 deletions backend/benefit/applications/services/ahjo_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,10 +506,16 @@ def update_application_summary_record_in_ahjo(
application: Application, ahjo_token: AhjoToken
) -> Union[Tuple[Application, str], None]:
"""Update the application summary pdf in Ahjo.
Should be done just before the decision proposal is sent.
Should be done about the same time proposal is sent.
"""

ahjo_request = AhjoUpdateRecordsRequest(application)
if application.ahjo_status.latest().error_from_ahjo:
# If there are errors from Ahjo, do not send the update request
raise ValueError(
f"Application {application.id} has errors \
in Ahjo status {application.ahjo_status.latest().status}, not sending {ahjo_request}."
)

ahjo_client = AhjoApiClient(ahjo_token, ahjo_request)

pdf_summary = generate_application_attachment(
Expand Down
15 changes: 14 additions & 1 deletion backend/benefit/applications/tests/test_ahjo_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,22 +432,26 @@ def ahjo_callback_payload():


@pytest.mark.parametrize(
"request_type, ahjo_status",
"request_type, previous_ahjo_status, ahjo_status",
[
(
AhjoRequestType.OPEN_CASE,
AhjoStatusEnum.REQUEST_TO_OPEN_CASE_SENT,
AhjoStatusEnum.CASE_OPENED,
),
(
AhjoRequestType.UPDATE_APPLICATION,
AhjoStatusEnum.UPDATE_REQUEST_SENT,
AhjoStatusEnum.UPDATE_REQUEST_RECEIVED,
),
(
AhjoRequestType.DELETE_APPLICATION,
AhjoStatusEnum.DELETE_REQUEST_SENT,
AhjoStatusEnum.DELETE_REQUEST_RECEIVED,
),
(
AhjoRequestType.SEND_DECISION_PROPOSAL,
AhjoStatusEnum.DECISION_PROPOSAL_SENT,
AhjoStatusEnum.DECISION_PROPOSAL_ACCEPTED,
),
],
Expand All @@ -459,6 +463,7 @@ def test_ahjo_callback_success(
decided_application,
settings,
request_type,
previous_ahjo_status,
ahjo_status,
ahjo_callback_payload,
):
Expand All @@ -473,6 +478,14 @@ def test_ahjo_callback_success(
ahjo_callback_payload["message"] = AhjoCallBackStatus.SUCCESS
ahjo_callback_payload["records"][0]["hashValue"] = attachment_hash_value

status = AhjoStatus.objects.create(
application=decided_application,
status=previous_ahjo_status,
)
# make sure the previous status is created earlier than the new status
status.created_at = timezone.now() - timedelta(days=5)
status.save()

if request_type in [
AhjoRequestType.SEND_DECISION_PROPOSAL,
AhjoRequestType.DELETE_APPLICATION,
Expand Down

0 comments on commit 8a8408a

Please sign in to comment.