Skip to content

Commit

Permalink
Fix issue with reverting TSOJ on EP400. (#2831)
Browse files Browse the repository at this point in the history
  • Loading branch information
dfitchett authored Apr 9, 2024
1 parent 112250e commit 6d22e47
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,21 @@ class EpMergeMachine(StateMachine):
)
resume_restart = process
resume_processing_from_running_cancel_ep400_claim = (
pending.to(running_get_pending_claim)
| running_get_pending_claim.to(running_cancel_ep400_claim, unless="has_error")
pending.to(running_get_pending_claim) # pending claim needed to populate cancellation reason
| running_get_pending_claim.to(running_get_ep400_claim, unless="has_error")
| running_get_pending_claim.to(running_get_pending_claim_failed_remove_special_issue, cond="has_error")
| running_get_pending_claim_failed_remove_special_issue.to(completed_error)
| running_get_ep400_claim.to(running_cancel_ep400_claim, unless="has_error") # ep400 claim needed for original tsoj
| running_get_ep400_claim.to(running_get_ep400_claim_failed_remove_special_issue, cond="has_error")
| running_get_ep400_claim_failed_remove_special_issue.to(completed_error)
| running_cancel_ep400_claim.to(running_add_claim_note_to_ep400, unless="has_error")
| running_cancel_ep400_claim.to(running_cancel_claim_failed_revert_temp_station_of_jurisdiction, cond="has_error")
| running_cancel_claim_failed_revert_temp_station_of_jurisdiction.to(completed_error)
| running_add_claim_note_to_ep400.to(completed_success, unless="has_error")
| running_add_claim_note_to_ep400.to(completed_error, cond="has_error")
)
resume_processing_from_running_add_note_to_ep400_claim = (
pending.to(running_get_pending_claim)
pending.to(running_get_pending_claim) # pending claim needed to populate cancellation reason
| running_get_pending_claim.to(running_add_claim_note_to_ep400, unless="has_error")
| running_get_pending_claim.to(running_get_pending_claim_failed_remove_special_issue, cond="has_error")
| running_get_pending_claim_failed_remove_special_issue.to(completed_error)
Expand Down Expand Up @@ -190,7 +193,6 @@ def on_get_pending_claim(self, event):
)
else:
self.cancellation_reason = CANCELLATION_REASON_FORMAT.format(ep_code=response.claim.end_product_code, claim_id=self.job.pending_claim_id)
self.original_tsoj = response.claim.temp_station_of_jurisdiction

self.send(event=event)

Expand All @@ -209,6 +211,8 @@ def on_get_ep400_claim(self, event):
self.add_job_error(f"EP400 claim #{self.job.ep400_claim_id} does not have a benefit claim type code")
elif claim.benefit_claim_type.code not in EP400_BENEFIT_CLAIM_TYPE_CODES:
self.add_job_error(f"EP400 claim #{self.job.ep400_claim_id} benefit claim type code of '{claim.benefit_claim_type.code}' is not supported")
else:
self.original_tsoj = response.claim.temp_station_of_jurisdiction

self.send(event=event)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ class TestUpToMoveContentionsToPendingClaim:
],
)
def test_fail(self, machine, mock_hoppy_async_client, metric_logger_distribution, metric_logger_increment, invalid_request, original_tsoj):
get_pending_claim_200.claim.temp_station_of_jurisdiction = original_tsoj
get_ep400_claim_200.claim.temp_station_of_jurisdiction = original_tsoj
revert_temporary_station_of_jurisdiction_req['tempStationOfJurisdiction'] = original_tsoj

mock_async_responses(
Expand Down Expand Up @@ -857,7 +857,7 @@ class TestUpToCancelClaim:
def test_invalid_request_at_cancel_claim_due_to_exception(
self, machine, mock_hoppy_async_client, metric_logger_distribution, metric_logger_increment, invalid_request, original_tsoj
):
get_pending_claim_200.claim.temp_station_of_jurisdiction = original_tsoj
get_ep400_claim_200.claim.temp_station_of_jurisdiction = original_tsoj
revert_temporary_station_of_jurisdiction_req['tempStationOfJurisdiction'] = original_tsoj

mock_async_responses(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
add_claim_note_req,
cancel_claim_200,
cancel_ep400_claim_req,
get_ep400_claim_200,
get_ep400_claim_req,
get_ep400_contentions_200,
get_ep400_contentions_req,
get_pending_claim_200,
Expand Down Expand Up @@ -166,15 +168,18 @@ class TestUpToCancelClaim:
],
)
def test_invalid_request_at_cancel_claim_due_to_exception(self, machine, mock_hoppy_async_client, invalid_request, original_tsoj):
get_pending_claim_200.claim.temp_station_of_jurisdiction = original_tsoj
get_ep400_claim_200.claim.temp_station_of_jurisdiction = original_tsoj
revert_temporary_station_of_jurisdiction_req['tempStationOfJurisdiction'] = original_tsoj

mock_async_responses(mock_hoppy_async_client, [get_pending_claim_200, invalid_request, revert_temporary_station_of_jurisdiction_200])
mock_async_responses(
mock_hoppy_async_client, [get_pending_claim_200, get_ep400_claim_200, invalid_request, revert_temporary_station_of_jurisdiction_200]
)
process_and_assert(machine, JobState.COMPLETED_ERROR, JobState.CANCEL_EP400_CLAIM, 1)
assert_hoppy_requests(
mock_hoppy_async_client,
[
call(machine.job.job_id, get_pending_claim_req),
call(machine.job.job_id, get_ep400_claim_req),
call(machine.job.job_id, cancel_ep400_claim_req),
# calls below are to attempt revert tsoj due to fail to cancel
call(machine.job.job_id, revert_temporary_station_of_jurisdiction_req),
Expand All @@ -191,12 +196,13 @@ def test_invalid_request_at_cancel_claim_due_to_exception(self, machine, mock_ho
],
)
def test_invalid_request_at_revert_tsoj_due_to_failure_to_cancel_claim(self, machine, mock_hoppy_async_client, invalid_request):
mock_async_responses(mock_hoppy_async_client, [get_pending_claim_200, ResponseException("Oops"), invalid_request])
mock_async_responses(mock_hoppy_async_client, [get_pending_claim_200, get_ep400_claim_200, ResponseException("Oops"), invalid_request])
process_and_assert(machine, JobState.COMPLETED_ERROR, JobState.CANCEL_CLAIM_FAILED_REVERT_TEMP_STATION_OF_JURISDICTION, 3)
assert_hoppy_requests(
mock_hoppy_async_client,
[
call(machine.job.job_id, get_pending_claim_req),
call(machine.job.job_id, get_ep400_claim_req),
call(machine.job.job_id, cancel_ep400_claim_req),
# calls below are to attempt revert tsoj due to fail to cancel which fails
call(machine.job.job_id, revert_temporary_station_of_jurisdiction_req),
Expand All @@ -215,12 +221,13 @@ class TestUpToAddClaimNote:
],
)
def test_invalid_request_at_add_claim_note_due_to_exception(self, machine, mock_hoppy_async_client, invalid_request):
mock_async_responses(mock_hoppy_async_client, [get_pending_claim_200, cancel_claim_200, invalid_request])
mock_async_responses(mock_hoppy_async_client, [get_pending_claim_200, get_ep400_claim_200, cancel_claim_200, invalid_request])
process_and_assert(machine, JobState.COMPLETED_ERROR, JobState.ADD_CLAIM_NOTE_TO_EP400, 1)
assert_hoppy_requests(
mock_hoppy_async_client,
[
call(machine.job.job_id, get_pending_claim_req),
call(machine.job.job_id, get_ep400_claim_req),
call(machine.job.job_id, cancel_ep400_claim_req),
# call below is attempt to add note, which fails
call(machine.job.job_id, add_claim_note_req),
Expand All @@ -231,9 +238,14 @@ def test_invalid_request_at_add_claim_note_due_to_exception(self, machine, mock_
class TestSuccess:

def test_process_succeeds_with_different_contention(self, machine, mock_hoppy_async_client):
mock_async_responses(mock_hoppy_async_client, [get_pending_claim_200, cancel_claim_200, add_claim_note_200])
mock_async_responses(mock_hoppy_async_client, [get_pending_claim_200, get_ep400_claim_200, cancel_claim_200, add_claim_note_200])
process_and_assert(machine, JobState.COMPLETED_SUCCESS)
assert_hoppy_requests(
mock_hoppy_async_client,
[call(machine.job.job_id, get_pending_claim_req), call(machine.job.job_id, cancel_ep400_claim_req), call(machine.job.job_id, add_claim_note_req)],
[
call(machine.job.job_id, get_pending_claim_req),
call(machine.job.job_id, get_ep400_claim_req),
call(machine.job.job_id, cancel_ep400_claim_req),
call(machine.job.job_id, add_claim_note_req),
],
)

0 comments on commit 6d22e47

Please sign in to comment.