diff --git a/domain-ee/ee-ep-merge-app/integration/test_merge_request.py b/domain-ee/ee-ep-merge-app/integration/test_merge_request.py index ca0037b027..1e6b58b92e 100644 --- a/domain-ee/ee-ep-merge-app/integration/test_merge_request.py +++ b/domain-ee/ee-ep-merge-app/integration/test_merge_request.py @@ -69,7 +69,7 @@ async def test_completed_success( cancel_claim_endpoint: MqEndpoint, add_claim_note_endpoint: MqEndpoint, ): - get_claim_endpoint.set_responses([pending_claim_200, ep400_claim_200]) + get_claim_endpoint.set_responses([pending_claim_200, ep400_claim_200, pending_claim_200]) get_claim_contentions_endpoint.set_responses([pending_contentions_200, ep400_contentions_200]) put_tsoj_endpoint.set_responses([response_200]) create_claim_contentions_endpoint.set_responses([response_201]) @@ -90,7 +90,7 @@ async def test_completed_success_with_duplicate_contention( cancel_claim_endpoint: MqEndpoint, add_claim_note_endpoint: MqEndpoint, ): - get_claim_endpoint.set_responses([pending_claim_200, ep400_claim_200]) + get_claim_endpoint.set_responses([pending_claim_200, ep400_claim_200, pending_claim_200]) get_claim_contentions_endpoint.set_responses([pending_contentions_200, ep400_duplicate_contentions_200]) put_tsoj_endpoint.set_responses([response_200]) cancel_claim_endpoint.set_responses([response_200]) @@ -110,7 +110,7 @@ async def test_completed_no_ep400_contentions_on_first_attempt( cancel_claim_endpoint: MqEndpoint, add_claim_note_endpoint: MqEndpoint, ): - get_claim_endpoint.set_responses([pending_claim_200, ep400_claim_200]) + get_claim_endpoint.set_responses([pending_claim_200, ep400_claim_200, pending_claim_200]) get_claim_contentions_endpoint.set_responses([pending_contentions_200, response_204, ep400_contentions_200]) put_tsoj_endpoint.set_responses([response_200]) create_claim_contentions_endpoint.set_responses([response_201]) @@ -279,7 +279,7 @@ async def test( put_tsoj_endpoint: MqEndpoint, update_claim_contentions_endpoint: MqEndpoint, ): - get_claim_endpoint.set_responses([pending_claim_200, ep400_claim_200]) + get_claim_endpoint.set_responses([pending_claim_200, ep400_claim_200, pending_claim_200]) get_claim_contentions_endpoint.set_responses([pending_contentions_200, ep400_contentions_200]) put_tsoj_endpoint.set_responses([response_500]) update_claim_contentions_endpoint.set_responses([response_200]) @@ -296,7 +296,7 @@ async def test_error_at_remove_special_issue_fail_to_update_ep400_contentions( put_tsoj_endpoint: MqEndpoint, update_claim_contentions_endpoint: MqEndpoint, ): - get_claim_endpoint.set_responses([pending_claim_200, ep400_claim_200]) + get_claim_endpoint.set_responses([pending_claim_200, ep400_claim_200, pending_claim_200]) get_claim_contentions_endpoint.set_responses([pending_contentions_200, ep400_contentions_200]) put_tsoj_endpoint.set_responses([response_500]) update_claim_contentions_endpoint.set_responses([response_500]) @@ -317,7 +317,7 @@ async def test( create_claim_contentions_endpoint: MqEndpoint, update_claim_contentions_endpoint: MqEndpoint, ): - get_claim_endpoint.set_responses([pending_claim_200, ep400_claim_200]) + get_claim_endpoint.set_responses([pending_claim_200, ep400_claim_200, pending_claim_200]) get_claim_contentions_endpoint.set_responses([pending_contentions_200, ep400_contentions_200]) put_tsoj_endpoint.set_responses([response_200, response_200]) # Second response is to revert the tsoj create_claim_contentions_endpoint.set_responses([response_500]) @@ -336,7 +336,7 @@ async def test_error_at_remove_special_issue_fail_to_update_ep400_contentions( create_claim_contentions_endpoint: MqEndpoint, update_claim_contentions_endpoint: MqEndpoint, ): - get_claim_endpoint.set_responses([pending_claim_200, ep400_claim_200]) + get_claim_endpoint.set_responses([pending_claim_200, ep400_claim_200, pending_claim_200]) get_claim_contentions_endpoint.set_responses([pending_contentions_200, ep400_contentions_200]) put_tsoj_endpoint.set_responses([response_200, response_200]) create_claim_contentions_endpoint.set_responses([response_500]) @@ -355,7 +355,7 @@ async def test_error_at_revert_tsoj( create_claim_contentions_endpoint: MqEndpoint, update_claim_contentions_endpoint: MqEndpoint, ): - get_claim_endpoint.set_responses([pending_claim_200, ep400_claim_200]) + get_claim_endpoint.set_responses([pending_claim_200, ep400_claim_200, pending_claim_200]) get_claim_contentions_endpoint.set_responses([pending_contentions_200, ep400_contentions_200]) put_tsoj_endpoint.set_responses([response_200, response_500]) # Note the 500 on second response create_claim_contentions_endpoint.set_responses([response_500]) @@ -377,7 +377,7 @@ async def test( create_claim_contentions_endpoint: MqEndpoint, cancel_claim_endpoint: MqEndpoint, ): - get_claim_endpoint.set_responses([pending_claim_200, ep400_claim_200]) + get_claim_endpoint.set_responses([pending_claim_200, ep400_claim_200, pending_claim_200]) get_claim_contentions_endpoint.set_responses([pending_contentions_200, ep400_contentions_200]) put_tsoj_endpoint.set_responses([response_200, response_200]) # Note the 200 to revert tsoj create_claim_contentions_endpoint.set_responses([response_201]) @@ -396,7 +396,7 @@ async def test_error_at_revert_tsoj( create_claim_contentions_endpoint: MqEndpoint, cancel_claim_endpoint: MqEndpoint, ): - get_claim_endpoint.set_responses([pending_claim_200, ep400_claim_200]) + get_claim_endpoint.set_responses([pending_claim_200, ep400_claim_200, pending_claim_200]) get_claim_contentions_endpoint.set_responses([pending_contentions_200, ep400_contentions_200]) put_tsoj_endpoint.set_responses([response_200, response_500]) # Note the 500 on second response create_claim_contentions_endpoint.set_responses([response_201]) @@ -420,7 +420,7 @@ async def test( add_claim_note_endpoint: MqEndpoint, update_claim_contentions_endpoint: MqEndpoint, ): - get_claim_endpoint.set_responses([pending_claim_200, ep400_claim_200]) + get_claim_endpoint.set_responses([pending_claim_200, ep400_claim_200, pending_claim_200]) get_claim_contentions_endpoint.set_responses([pending_contentions_200, ep400_contentions_200]) put_tsoj_endpoint.set_responses([response_200]) create_claim_contentions_endpoint.set_responses([response_201]) @@ -443,7 +443,7 @@ async def test_error_at_remove_special_issue_fail_to_update_ep400_contentions( add_claim_note_endpoint: MqEndpoint, update_claim_contentions_endpoint: MqEndpoint, ): - get_claim_endpoint.set_responses([pending_claim_200, ep400_claim_200]) + get_claim_endpoint.set_responses([pending_claim_200, ep400_claim_200, pending_claim_200]) get_claim_contentions_endpoint.set_responses([pending_contentions_200, ep400_contentions_200]) put_tsoj_endpoint.set_responses([response_200]) create_claim_contentions_endpoint.set_responses([response_201]) diff --git a/domain-ee/ee-ep-merge-app/src/python_src/schema/claim.py b/domain-ee/ee-ep-merge-app/src/python_src/schema/claim.py index 66f6c5e82e..e40ba1342f 100644 --- a/domain-ee/ee-ep-merge-app/src/python_src/schema/claim.py +++ b/domain-ee/ee-ep-merge-app/src/python_src/schema/claim.py @@ -20,3 +20,4 @@ class ClaimDetail(BaseModel): benefit_claim_type: BenefitClaimType | None = None end_product_code: str | None = None temp_station_of_jurisdiction: str | None = None + claim_lifecycle_status: str | None = None diff --git a/domain-ee/ee-ep-merge-app/src/python_src/schema/merge_job.py b/domain-ee/ee-ep-merge-app/src/python_src/schema/merge_job.py index 911b3e4ac9..f3b8e0021c 100644 --- a/domain-ee/ee-ep-merge-app/src/python_src/schema/merge_job.py +++ b/domain-ee/ee-ep-merge-app/src/python_src/schema/merge_job.py @@ -14,6 +14,7 @@ class JobState(StrEnum): GET_PENDING_CLAIM_CONTENTIONS = auto() GET_EP400_CLAIM = auto() GET_EP400_CLAIM_CONTENTIONS = auto() + CHECK_PENDING_EP_IS_OPEN = auto() SET_TEMP_STATION_OF_JURISDICTION = auto() MERGE_CONTENTIONS = auto() MOVE_CONTENTIONS_TO_PENDING_CLAIM = auto() @@ -24,6 +25,7 @@ class JobState(StrEnum): GET_PENDING_CLAIM_FAILED_REMOVE_SPECIAL_ISSUE = auto() GET_EP400_CLAIM_FAILED_REMOVE_SPECIAL_ISSUE = auto() GET_PENDING_CLAIM_CONTENTIONS_FAILED_REMOVE_SPECIAL_ISSUE = auto() + CHECK_PENDING_EP_IS_OPEN_FAILED_REMOVE_SPECIAL_ISSUE = auto() SET_TEMP_STATION_OF_JURISDICTION_FAILED_REMOVE_SPECIAL_ISSUE = auto() MOVE_CONTENTIONS_FAILED_REMOVE_SPECIAL_ISSUE = auto() MOVE_CONTENTIONS_FAILED_REVERT_TEMP_STATION_OF_JURISDICTION = auto() diff --git a/domain-ee/ee-ep-merge-app/src/python_src/service/ep_merge_machine.py b/domain-ee/ee-ep-merge-app/src/python_src/service/ep_merge_machine.py index 875d84153c..348e2ae3ec 100644 --- a/domain-ee/ee-ep-merge-app/src/python_src/service/ep_merge_machine.py +++ b/domain-ee/ee-ep-merge-app/src/python_src/service/ep_merge_machine.py @@ -17,6 +17,7 @@ get_contentions, update_contentions, ) +from schema.claim import ClaimDetail from schema import update_temp_station_of_jurisdiction as tsoj from schema.merge_job import JobState, MergeJob from schema.request import GeneralRequest @@ -40,6 +41,7 @@ JOB_SKIPPED_MERGE_METRIC = 'job.skipped_merge' JOB_NEW_CONTENTIONS_METRIC = 'job.new_contentions' +ELIGIBLE_CLAIM_LIFECYCLE_STATUSES = frozenset(['open']) EP400_PRODUCT_CODES = frozenset([str(i) for i in range(400, 410)]) EP400_BENEFIT_CLAIM_TYPE_CODES = frozenset(['400SUPP']) @@ -55,6 +57,13 @@ def ep400_has_no_contentions(response: get_contentions.Response): return not response.contentions +def is_claim_open(claim: ClaimDetail): + """ + Check if the claim's lifecycle status is in the list of ELIGIBLE_CLAIM_LIFECYCLE_STATUSES + """ + return claim and claim.claim_lifecycle_status and claim.claim_lifecycle_status.lower() in ELIGIBLE_CLAIM_LIFECYCLE_STATUSES + + class Workflow(str, Enum): PROCESS = 'process' RESTART = ('resume_restart',) @@ -79,6 +88,8 @@ class EpMergeMachine(StateMachine): running_get_ep400_claim = State(value=JobState.GET_EP400_CLAIM) running_get_ep400_claim_failed_remove_special_issue = State(value=JobState.GET_EP400_CLAIM_FAILED_REMOVE_SPECIAL_ISSUE) running_get_ep400_contentions = State(value=JobState.GET_EP400_CLAIM_CONTENTIONS) + running_check_pending_is_open = State(value=JobState.CHECK_PENDING_EP_IS_OPEN) + running_check_pending_is_open_failed_remove_special_issue = State(value=JobState.CHECK_PENDING_EP_IS_OPEN_FAILED_REMOVE_SPECIAL_ISSUE) running_set_temp_station_of_jurisdiction = State(value=JobState.SET_TEMP_STATION_OF_JURISDICTION) running_set_temp_station_of_jurisdiction_failed_remove_special_issue = State(value=JobState.SET_TEMP_STATION_OF_JURISDICTION_FAILED_REMOVE_SPECIAL_ISSUE) running_merge_contentions = State(value=JobState.MERGE_CONTENTIONS) @@ -102,8 +113,11 @@ class EpMergeMachine(StateMachine): | running_get_pending_contentions.to(running_get_ep400_contentions, unless="has_error") | running_get_pending_contentions.to(running_get_pending_contentions_failed_remove_special_issue, cond="has_error") | running_get_pending_contentions_failed_remove_special_issue.to(completed_error) - | running_get_ep400_contentions.to(running_set_temp_station_of_jurisdiction, unless="has_error") + | running_get_ep400_contentions.to(running_check_pending_is_open, unless="has_error") | running_get_ep400_contentions.to(completed_error, cond="has_error") + | running_check_pending_is_open.to(running_set_temp_station_of_jurisdiction, unless="has_error") + | running_check_pending_is_open.to(running_check_pending_is_open_failed_remove_special_issue, cond="has_error") + | running_check_pending_is_open_failed_remove_special_issue.to(completed_error) | running_set_temp_station_of_jurisdiction.to(running_merge_contentions, cond="has_new_contentions", unless="has_error") | running_set_temp_station_of_jurisdiction.to(running_cancel_ep400_claim, unless=["has_new_contentions", "has_error"]) | running_set_temp_station_of_jurisdiction.to(running_set_temp_station_of_jurisdiction_failed_remove_special_issue, cond="has_error") @@ -169,6 +183,11 @@ def on_get_pending_claim(self, event): if response is not None and response.status_code == 200: if response.claim is None or response.claim.end_product_code is None: self.add_job_error(f"Pending claim #{self.job.pending_claim_id} does not have an end product code") + if not is_claim_open(response.claim): + self.add_job_error( + f"Pending claim #{self.job.pending_claim_id} does not have an eligible lifecycle status of: " + f"{', '.join(list(ELIGIBLE_CLAIM_LIFECYCLE_STATUSES))}" + ) 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 @@ -217,6 +236,20 @@ def on_get_ep400_contentions(self, event, pending_contentions_response=None): self.send(event=event, pending_contentions_response=pending_contentions_response, ep400_contentions_response=response) + @running_check_pending_is_open.enter + def on_check_pending_claim_is_open(self, event, pending_contentions_response, ep400_contentions_response): + request = get_claim.Request(claim_id=self.job.pending_claim_id) + response = self.make_request(request=request, hoppy_client=HOPPY.get_client(ClientName.GET_CLAIM), response_type=get_claim.Response) + + if response is not None and response.status_code == 200: + if not is_claim_open(response.claim): + self.add_job_error( + f"Pending claim #{self.job.pending_claim_id} does not have an eligible lifecycle status of: " + f"{', '.join(list(ELIGIBLE_CLAIM_LIFECYCLE_STATUSES))}" + ) + + self.send(event=event, pending_contentions_response=pending_contentions_response, ep400_contentions_response=ep400_contentions_response) + @running_set_temp_station_of_jurisdiction.enter def on_set_temp_station_of_jurisdiction(self, event, pending_contentions_response=None, ep400_contentions_response=None): request = tsoj.Request(temp_station_of_jurisdiction="398", claim_id=self.job.ep400_claim_id) @@ -257,6 +290,7 @@ def on_add_claim_note_to_ep400(self, event): @running_get_pending_claim_failed_remove_special_issue.enter @running_get_pending_contentions_failed_remove_special_issue.enter @running_get_ep400_claim_failed_remove_special_issue.enter + @running_check_pending_is_open_failed_remove_special_issue.enter @running_set_temp_station_of_jurisdiction_failed_remove_special_issue.enter @running_move_contentions_failed_remove_special_issue.enter def on_pre_cancel_step_failed_remove_special_issue_code(self, event, ep400_contentions_response=None): diff --git a/domain-ee/ee-ep-merge-app/tests/responses/get_pending_claim_200.json b/domain-ee/ee-ep-merge-app/tests/responses/get_pending_claim_200.json index ebf4a59b5b..5fcd8cf3bb 100644 --- a/domain-ee/ee-ep-merge-app/tests/responses/get_pending_claim_200.json +++ b/domain-ee/ee-ep-merge-app/tests/responses/get_pending_claim_200.json @@ -4,6 +4,7 @@ "claim": { "claimId": 1, "endProductCode": "010", - "tempStationOfJurisdiction": "111" + "tempStationOfJurisdiction": "111", + "claimLifecycleStatus": "Open" } } diff --git a/domain-ee/ee-ep-merge-app/tests/service/conftest.py b/domain-ee/ee-ep-merge-app/tests/service/conftest.py index 1c6a6840e6..52cb5b5fe7 100644 --- a/domain-ee/ee-ep-merge-app/tests/service/conftest.py +++ b/domain-ee/ee-ep-merge-app/tests/service/conftest.py @@ -140,6 +140,13 @@ def process_and_assert(machine, expected_state: JobState, expected_error_state: assert len(machine.job.messages) == num_errors +def assert_hoppy_requests(mock_hoppy_async_client, calls): + # Number of expected calls should be equal number of actual calls + assert len(calls) == len(mock_hoppy_async_client.make_request.call_args_list) + # Assert calls are made in expected order + mock_hoppy_async_client.make_request.assert_has_calls(calls) + + def assert_metrics_called( metric_logger_distribution, metric_logger_increment, diff --git a/domain-ee/ee-ep-merge-app/tests/service/test_ep_merge_process.py b/domain-ee/ee-ep-merge-app/tests/service/test_ep_merge_process.py index 6d48f3daf3..ea74b1056e 100644 --- a/domain-ee/ee-ep-merge-app/tests/service/test_ep_merge_process.py +++ b/domain-ee/ee-ep-merge-app/tests/service/test_ep_merge_process.py @@ -8,6 +8,7 @@ add_claim_note_200, add_claim_note_req, assert_metrics_called, + assert_hoppy_requests, cancel_claim_200, cancel_ep400_claim_req, create_contentions_on_pending_claim_201, @@ -76,18 +77,38 @@ class TestUpToGetPendingClaim: pytest.param(load_response(response_400, get_claim.Response), id="400"), pytest.param(load_response(response_404, get_claim.Response), id="404"), pytest.param(load_response(response_500, get_claim.Response), id="500"), - pytest.param(get_claim.Response(statusCode=200, statusMessage="OK", claim=ClaimDetail(claimId=3)).model_dump(), id="claim has no endProductCode"), + pytest.param( + get_claim.Response(statusCode=200, statusMessage="OK", claim=ClaimDetail(claimId=3, claimLifecycleStatus="OPEN")).model_dump(), + id="claim has no endProductCode", + ), + pytest.param( + get_claim.Response(statusCode=200, statusMessage="OK", claim=ClaimDetail(claimId=3, endProductCode="010")).model_dump(), + id="claim has no claim_lifecycle_status", + ), + pytest.param( + get_claim.Response( + statusCode=200, statusMessage="OK", claim=ClaimDetail(claimId=3, endProductCode="010", claimLifecycleStatus="Cancelled") + ).model_dump(), + id="claim has ineligible claim_lifecycle_status 'Cancelled'", + ), + pytest.param( + get_claim.Response( + statusCode=200, statusMessage="OK", claim=ClaimDetail(claimId=3, endProductCode="010", claimLifecycleStatus="Ready For Decision") + ).model_dump(), + id="claim has ineligible claim_lifecycle_status 'Ready to Work'", + ), ], ) def test_invalid_request(self, machine, mock_hoppy_async_client, metric_logger_distribution, metric_logger_increment, invalid_request): mock_async_responses(mock_hoppy_async_client, [invalid_request, get_ep400_contentions_200, update_contentions_on_ep400_200]) process_and_assert(machine, JobState.COMPLETED_ERROR, JobState.GET_PENDING_CLAIM, 1) - mock_hoppy_async_client.make_request.assert_has_calls( + assert_hoppy_requests( + mock_hoppy_async_client, [ call(machine.job.job_id, get_pending_claim_req), call(machine.job.job_id, get_ep400_contentions_req), call(machine.job.job_id, update_contentions_on_ep400_req), - ] + ], ) assert_metrics_called(metric_logger_distribution, metric_logger_increment, JobState.COMPLETED_ERROR, JobState.GET_PENDING_CLAIM) @@ -104,11 +125,12 @@ def test_no_contentions_on_ep400_after_get_pending_claim_failure( ): mock_async_responses(mock_hoppy_async_client, [ResponseException("Oops"), no_contentions_response]) process_and_assert(machine, JobState.COMPLETED_ERROR, JobState.GET_PENDING_CLAIM, 2) - mock_hoppy_async_client.make_request.assert_has_calls( + assert_hoppy_requests( + mock_hoppy_async_client, [ call(machine.job.job_id, get_pending_claim_req), call(machine.job.job_id, get_ep400_contentions_req), - ] + ], ) assert_metrics_called(metric_logger_distribution, metric_logger_increment, JobState.COMPLETED_ERROR, JobState.GET_PENDING_CLAIM) @@ -132,11 +154,12 @@ def test_invalid_request_at_get_ep400_contentions_after_get_pending_claim_failur ], ) process_and_assert(machine, JobState.COMPLETED_ERROR, JobState.GET_PENDING_CLAIM_FAILED_REMOVE_SPECIAL_ISSUE, 3) - mock_hoppy_async_client.make_request.assert_has_calls( + assert_hoppy_requests( + mock_hoppy_async_client, [ call(machine.job.job_id, get_pending_claim_req), call(machine.job.job_id, get_ep400_contentions_req), - ] + ], ) assert_metrics_called( metric_logger_distribution, metric_logger_increment, JobState.COMPLETED_ERROR, JobState.GET_PENDING_CLAIM_FAILED_REMOVE_SPECIAL_ISSUE @@ -163,11 +186,13 @@ def test_invalid_request_at_update_ep400_contentions_after_get_pending_claim_fai ], ) process_and_assert(machine, JobState.COMPLETED_ERROR, JobState.GET_PENDING_CLAIM_FAILED_REMOVE_SPECIAL_ISSUE, 2) - mock_hoppy_async_client.make_request.assert_has_calls( + assert_hoppy_requests( + mock_hoppy_async_client, [ call(machine.job.job_id, get_pending_claim_req), call(machine.job.job_id, get_ep400_contentions_req), - ] + call(machine.job.job_id, update_contentions_on_ep400_req), + ], ) assert_metrics_called( metric_logger_distribution, metric_logger_increment, JobState.COMPLETED_ERROR, JobState.GET_PENDING_CLAIM_FAILED_REMOVE_SPECIAL_ISSUE @@ -210,13 +235,14 @@ class TestUpToGetEP400Claim: def test_invalid_request(self, machine, mock_hoppy_async_client, metric_logger_distribution, metric_logger_increment, invalid_request): mock_async_responses(mock_hoppy_async_client, [get_pending_claim_200, invalid_request, get_ep400_contentions_200, update_contentions_on_ep400_200]) process_and_assert(machine, JobState.COMPLETED_ERROR, JobState.GET_EP400_CLAIM, 1) - mock_hoppy_async_client.make_request.assert_has_calls( + 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, get_ep400_contentions_req), call(machine.job.job_id, update_contentions_on_ep400_req), - ] + ], ) assert_metrics_called(metric_logger_distribution, metric_logger_increment, JobState.COMPLETED_ERROR, JobState.GET_EP400_CLAIM) @@ -233,12 +259,13 @@ def test_no_contentions_on_ep400_after_get_ep400_claim_failure( ): mock_async_responses(mock_hoppy_async_client, [get_pending_claim_200, ResponseException("Oops"), no_contentions_response]) process_and_assert(machine, JobState.COMPLETED_ERROR, JobState.GET_EP400_CLAIM, 2) - mock_hoppy_async_client.make_request.assert_has_calls( + 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, get_ep400_contentions_req), - ] + ], ) assert_metrics_called(metric_logger_distribution, metric_logger_increment, JobState.COMPLETED_ERROR, JobState.GET_EP400_CLAIM) @@ -263,12 +290,13 @@ def test_invalid_request_at_get_ep400_contentions_after_get_ep400_claim_failure( ], ) process_and_assert(machine, JobState.COMPLETED_ERROR, JobState.GET_EP400_CLAIM_FAILED_REMOVE_SPECIAL_ISSUE, 3) - mock_hoppy_async_client.make_request.assert_has_calls( + 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, get_ep400_contentions_req), - ] + ], ) assert_metrics_called( metric_logger_distribution, metric_logger_increment, JobState.COMPLETED_ERROR, JobState.GET_EP400_CLAIM_FAILED_REMOVE_SPECIAL_ISSUE @@ -296,12 +324,14 @@ def test_invalid_request_at_update_ep400_contentions_after_get_ep400_claim_failu ], ) process_and_assert(machine, JobState.COMPLETED_ERROR, JobState.GET_EP400_CLAIM_FAILED_REMOVE_SPECIAL_ISSUE, 2) - mock_hoppy_async_client.make_request.assert_has_calls( + 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, get_ep400_contentions_req), - ] + call(machine.job.job_id, update_contentions_on_ep400_req), + ], ) assert_metrics_called( metric_logger_distribution, metric_logger_increment, JobState.COMPLETED_ERROR, JobState.GET_EP400_CLAIM_FAILED_REMOVE_SPECIAL_ISSUE @@ -323,14 +353,15 @@ def test_invalid_request(self, machine, mock_hoppy_async_client, metric_logger_d mock_hoppy_async_client, [get_pending_claim_200, get_ep400_claim_200, invalid_request, get_ep400_contentions_200, update_contentions_on_ep400_200] ) process_and_assert(machine, JobState.COMPLETED_ERROR, JobState.GET_PENDING_CLAIM_CONTENTIONS, 1) - mock_hoppy_async_client.make_request.assert_has_calls( + 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, get_pending_contentions_req), call(machine.job.job_id, get_ep400_contentions_req), call(machine.job.job_id, update_contentions_on_ep400_req), - ] + ], ) assert_metrics_called(metric_logger_distribution, metric_logger_increment, JobState.COMPLETED_ERROR, JobState.GET_PENDING_CLAIM_CONTENTIONS) @@ -347,13 +378,14 @@ def test_no_contentions_on_ep400_after_get_pending_contentions_failure( ): mock_async_responses(mock_hoppy_async_client, [get_pending_claim_200, get_ep400_claim_200, ResponseException("Oops"), no_contentions_response]) process_and_assert(machine, JobState.COMPLETED_ERROR, JobState.GET_PENDING_CLAIM_CONTENTIONS, 2) - mock_hoppy_async_client.make_request.assert_has_calls( + 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, get_pending_contentions_req), call(machine.job.job_id, get_ep400_contentions_req), - ] + ], ) assert_metrics_called(metric_logger_distribution, metric_logger_increment, JobState.COMPLETED_ERROR, JobState.GET_PENDING_CLAIM_CONTENTIONS) @@ -379,13 +411,14 @@ def test_invalid_request_at_get_ep400_contentions_after_get_pending_contentions_ ], ) process_and_assert(machine, JobState.COMPLETED_ERROR, JobState.GET_PENDING_CLAIM_CONTENTIONS_FAILED_REMOVE_SPECIAL_ISSUE, 3) - mock_hoppy_async_client.make_request.assert_has_calls( + 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, get_pending_contentions_req), call(machine.job.job_id, get_ep400_contentions_req), - ] + ], ) assert_metrics_called( metric_logger_distribution, @@ -417,13 +450,15 @@ def test_invalid_request_at_update_ep400_contentions_after_get_pending_contentio ], ) process_and_assert(machine, JobState.COMPLETED_ERROR, JobState.GET_PENDING_CLAIM_CONTENTIONS_FAILED_REMOVE_SPECIAL_ISSUE, 2) - mock_hoppy_async_client.make_request.assert_has_calls( + 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, get_pending_contentions_req), call(machine.job.job_id, get_ep400_contentions_req), - ] + call(machine.job.job_id, update_contentions_on_ep400_req), + ], ) assert_metrics_called( metric_logger_distribution, @@ -441,22 +476,144 @@ class TestUpToGetEp400Contentions: pytest.param(load_response(response_400, get_contentions.Response), id="400"), pytest.param(load_response(response_404, get_contentions.Response), id="404"), pytest.param(load_response(response_500, get_contentions.Response), id="500"), + ], + ) + def test_invalid_request_at_get_ep400_contentions( + self, machine, mock_hoppy_async_client, metric_logger_distribution, metric_logger_increment, invalid_request + ): + mock_async_responses( + mock_hoppy_async_client, [get_pending_claim_200, get_ep400_claim_200, get_pending_contentions_200, invalid_request, invalid_request] + ) + process_and_assert(machine, JobState.COMPLETED_ERROR, JobState.GET_EP400_CLAIM_CONTENTIONS, 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, get_pending_contentions_req), + call(machine.job.job_id, get_ep400_contentions_req), + ], + ) + assert_metrics_called(metric_logger_distribution, metric_logger_increment, JobState.COMPLETED_ERROR, JobState.GET_EP400_CLAIM_CONTENTIONS) + + @pytest.mark.parametrize( + "valid_request", + [ pytest.param(get_ep400_contentions_204, id="No contentions found"), pytest.param(get_contentions.Response(status_code=200, status_message="OK", contentions=None), id="None"), pytest.param(get_contentions.Response(status_code=200, status_message="OK", contentions=[]), id="Empty"), ], ) - def test_invalid_request_at_get_ep400_contentions( - self, machine, mock_hoppy_async_client, metric_logger_distribution, metric_logger_increment, invalid_request + def test_valid_request_but_empty_contentions_at_get_ep400_contentions( + self, machine, mock_hoppy_async_client, metric_logger_distribution, metric_logger_increment, valid_request ): - mock_async_responses(mock_hoppy_async_client, [get_pending_claim_200, get_ep400_claim_200, get_pending_contentions_200, invalid_request]) + mock_async_responses(mock_hoppy_async_client, [get_pending_claim_200, get_ep400_claim_200, get_pending_contentions_200, valid_request, valid_request]) process_and_assert(machine, JobState.COMPLETED_ERROR, JobState.GET_EP400_CLAIM_CONTENTIONS, 1) - mock_hoppy_async_client.make_request.assert_has_calls( - [call(machine.job.job_id, get_pending_contentions_req), call(machine.job.job_id, get_ep400_contentions_req)] + 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, get_pending_contentions_req), + call(machine.job.job_id, get_ep400_contentions_req), + call(machine.job.job_id, get_ep400_contentions_req), + ], ) assert_metrics_called(metric_logger_distribution, metric_logger_increment, JobState.COMPLETED_ERROR, JobState.GET_EP400_CLAIM_CONTENTIONS) +class TestUpToCheckPendingIsOpen: + @pytest.mark.parametrize( + "invalid_request", + [ + pytest.param(ResponseException("Oops"), id="Caught Exception"), + pytest.param(load_response(response_400, get_claim.Response), id="400"), + pytest.param(load_response(response_404, get_claim.Response), id="404"), + pytest.param(load_response(response_500, get_claim.Response), id="500"), + pytest.param( + get_claim.Response(statusCode=200, statusMessage="OK", claim=ClaimDetail(claimId=3, endProductCode="010")).model_dump(), + id="claim has no claim_lifecycle_status", + ), + pytest.param( + get_claim.Response( + statusCode=200, statusMessage="OK", claim=ClaimDetail(claimId=3, endProductCode="010", claimLifecycleStatus="Cancelled") + ).model_dump(), + id="claim has ineligible claim_lifecycle_status 'Cancelled'", + ), + pytest.param( + get_claim.Response( + statusCode=200, statusMessage="OK", claim=ClaimDetail(claimId=3, endProductCode="010", claimLifecycleStatus="Ready For Decision") + ).model_dump(), + id="claim has ineligible claim_lifecycle_status 'Ready to Work'", + ), + ], + ) + def test_invalid_request(self, machine, mock_hoppy_async_client, metric_logger_distribution, metric_logger_increment, invalid_request): + mock_async_responses( + mock_hoppy_async_client, + [ + get_pending_claim_200, + get_ep400_claim_200, + get_pending_contentions_200, + get_ep400_contentions_200, + invalid_request, + update_contentions_on_ep400_200, + ], + ) + process_and_assert(machine, JobState.COMPLETED_ERROR, JobState.CHECK_PENDING_EP_IS_OPEN, 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, get_pending_contentions_req), + call(machine.job.job_id, get_ep400_contentions_req), + call(machine.job.job_id, get_pending_claim_req), + call(machine.job.job_id, update_contentions_on_ep400_req), + ], + ) + assert_metrics_called(metric_logger_distribution, metric_logger_increment, JobState.COMPLETED_ERROR, JobState.CHECK_PENDING_EP_IS_OPEN) + + @pytest.mark.parametrize( + "invalid_request", + [ + pytest.param(ResponseException("Oops"), id="Caught Exception"), + pytest.param(load_response(response_400, update_contentions.Response), id="400"), + pytest.param(load_response(response_404, update_contentions.Response), id="404"), + pytest.param(load_response(response_500, update_contentions.Response), id="500"), + ], + ) + def test_invalid_request_at_update_ep400_contentions_after_get_pending_claim_failure( + self, machine, mock_hoppy_async_client, metric_logger_distribution, metric_logger_increment, invalid_request + ): + mock_async_responses( + mock_hoppy_async_client, + [ + get_pending_claim_200, + get_ep400_claim_200, + get_pending_contentions_200, + get_ep400_contentions_200, + ResponseException("Oops"), + invalid_request, + ], + ) + process_and_assert(machine, JobState.COMPLETED_ERROR, JobState.CHECK_PENDING_EP_IS_OPEN_FAILED_REMOVE_SPECIAL_ISSUE, 2) + 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, get_pending_contentions_req), + call(machine.job.job_id, get_ep400_contentions_req), + call(machine.job.job_id, get_pending_claim_req), + call(machine.job.job_id, update_contentions_on_ep400_req), + ], + ) + assert_metrics_called( + metric_logger_distribution, metric_logger_increment, JobState.COMPLETED_ERROR, JobState.CHECK_PENDING_EP_IS_OPEN_FAILED_REMOVE_SPECIAL_ISSUE + ) + + class TestUpToSetTemporaryStationOfJurisdiction: @pytest.mark.parametrize( "invalid_request", @@ -475,20 +632,23 @@ def test_invalid_request(self, machine, mock_hoppy_async_client, metric_logger_d get_ep400_claim_200, get_pending_contentions_200, get_ep400_contentions_200, + get_pending_claim_200, invalid_request, update_contentions_on_ep400_200, ], ) process_and_assert(machine, JobState.COMPLETED_ERROR, JobState.SET_TEMP_STATION_OF_JURISDICTION, 1) - mock_hoppy_async_client.make_request.assert_has_calls( + 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, get_pending_contentions_req), call(machine.job.job_id, get_ep400_contentions_req), + call(machine.job.job_id, get_pending_claim_req), call(machine.job.job_id, update_temporary_station_of_jurisdiction_req), call(machine.job.job_id, update_contentions_on_ep400_req), - ] + ], ) assert_metrics_called(metric_logger_distribution, metric_logger_increment, JobState.COMPLETED_ERROR, JobState.SET_TEMP_STATION_OF_JURISDICTION) @@ -511,20 +671,23 @@ def test_invalid_request_on_update_contentions_after_set_tsoj_failure( get_ep400_claim_200, get_pending_contentions_200, get_ep400_contentions_200, + get_pending_claim_200, ResponseException("Oops"), invalid_request, ], ) process_and_assert(machine, JobState.COMPLETED_ERROR, JobState.SET_TEMP_STATION_OF_JURISDICTION_FAILED_REMOVE_SPECIAL_ISSUE, 2) - mock_hoppy_async_client.make_request.assert_has_calls( + 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, get_pending_contentions_req), call(machine.job.job_id, get_ep400_contentions_req), + call(machine.job.job_id, get_pending_claim_req), call(machine.job.job_id, update_temporary_station_of_jurisdiction_req), call(machine.job.job_id, update_contentions_on_ep400_req), - ] + ], ) assert_metrics_called( metric_logger_distribution, @@ -559,6 +722,7 @@ def test_fail(self, machine, mock_hoppy_async_client, metric_logger_distribution get_ep400_claim_200, get_pending_contentions_200, get_ep400_contentions_200, + get_pending_claim_200, update_temporary_station_of_jurisdiction_200, invalid_request, update_contentions_on_ep400_200, @@ -566,17 +730,19 @@ def test_fail(self, machine, mock_hoppy_async_client, metric_logger_distribution ], ) process_and_assert(machine, JobState.COMPLETED_ERROR, JobState.MOVE_CONTENTIONS_TO_PENDING_CLAIM, 1) - mock_hoppy_async_client.make_request.assert_has_calls( + 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, get_pending_contentions_req), call(machine.job.job_id, get_ep400_contentions_req), + call(machine.job.job_id, get_pending_claim_req), call(machine.job.job_id, update_temporary_station_of_jurisdiction_req), call(machine.job.job_id, create_contentions_on_pending_claim_req), call(machine.job.job_id, update_contentions_on_ep400_req), call(machine.job.job_id, revert_temporary_station_of_jurisdiction_req), - ] + ], ) assert_metrics_called(metric_logger_distribution, metric_logger_increment, JobState.COMPLETED_ERROR, JobState.MOVE_CONTENTIONS_TO_PENDING_CLAIM) @@ -599,6 +765,7 @@ def test_fail_to_remove_special_issues_after_move_contentions_to_pending_claim_f get_ep400_claim_200, get_pending_contentions_200, get_ep400_contentions_200, + get_pending_claim_200, update_temporary_station_of_jurisdiction_200, ResponseException("Oops"), invalid_request, @@ -606,17 +773,19 @@ def test_fail_to_remove_special_issues_after_move_contentions_to_pending_claim_f ], ) process_and_assert(machine, JobState.COMPLETED_ERROR, JobState.MOVE_CONTENTIONS_FAILED_REMOVE_SPECIAL_ISSUE, 2) - mock_hoppy_async_client.make_request.assert_has_calls( + 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, get_pending_contentions_req), call(machine.job.job_id, get_ep400_contentions_req), + call(machine.job.job_id, get_pending_claim_req), call(machine.job.job_id, update_temporary_station_of_jurisdiction_req), call(machine.job.job_id, create_contentions_on_pending_claim_req), call(machine.job.job_id, update_contentions_on_ep400_req), call(machine.job.job_id, revert_temporary_station_of_jurisdiction_req), - ] + ], ) assert_metrics_called( metric_logger_distribution, metric_logger_increment, JobState.COMPLETED_ERROR, JobState.MOVE_CONTENTIONS_FAILED_REMOVE_SPECIAL_ISSUE @@ -641,6 +810,7 @@ def test_fail_to_revert_tsoj_after_failure_to_move_contentions_to_pending_claim( get_ep400_claim_200, get_pending_contentions_200, get_ep400_contentions_200, + get_pending_claim_200, update_temporary_station_of_jurisdiction_200, ResponseException("Oops"), update_contentions_on_ep400_200, @@ -648,15 +818,19 @@ def test_fail_to_revert_tsoj_after_failure_to_move_contentions_to_pending_claim( ], ) process_and_assert(machine, JobState.COMPLETED_ERROR, JobState.MOVE_CONTENTIONS_FAILED_REVERT_TEMP_STATION_OF_JURISDICTION, 3) - mock_hoppy_async_client.make_request.assert_has_calls( + 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, get_pending_contentions_req), call(machine.job.job_id, get_ep400_contentions_req), + call(machine.job.job_id, get_pending_claim_req), call(machine.job.job_id, update_temporary_station_of_jurisdiction_req), call(machine.job.job_id, create_contentions_on_pending_claim_req), - ] + call(machine.job.job_id, update_contentions_on_ep400_req), + call(machine.job.job_id, revert_temporary_station_of_jurisdiction_req), + ], ) assert_metrics_called( metric_logger_distribution, @@ -693,6 +867,7 @@ def test_invalid_request_at_cancel_claim_due_to_exception( get_ep400_claim_200, get_pending_contentions_200, get_ep400_contentions_200, + get_pending_claim_200, update_temporary_station_of_jurisdiction_200, create_contentions_on_pending_claim_201, invalid_request, @@ -700,14 +875,19 @@ def test_invalid_request_at_cancel_claim_due_to_exception( ], ) process_and_assert(machine, JobState.COMPLETED_ERROR, JobState.CANCEL_EP400_CLAIM, 1) - mock_hoppy_async_client.make_request.assert_has_calls( + 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, get_pending_contentions_req), call(machine.job.job_id, get_ep400_contentions_req), + call(machine.job.job_id, get_pending_claim_req), call(machine.job.job_id, update_temporary_station_of_jurisdiction_req), call(machine.job.job_id, create_contentions_on_pending_claim_req), call(machine.job.job_id, cancel_ep400_claim_req), - ] + call(machine.job.job_id, revert_temporary_station_of_jurisdiction_req), + ], ) assert_metrics_called(metric_logger_distribution, metric_logger_increment, JobState.COMPLETED_ERROR, JobState.CANCEL_EP400_CLAIM, 1, False) @@ -730,6 +910,7 @@ def test_invalid_request_at_revert_tsoj_due_to_failure_to_cancel_claim( get_ep400_claim_200, get_pending_contentions_200, get_ep400_contentions_200, + get_pending_claim_200, update_temporary_station_of_jurisdiction_200, create_contentions_on_pending_claim_201, ResponseException("Oops"), @@ -737,15 +918,19 @@ def test_invalid_request_at_revert_tsoj_due_to_failure_to_cancel_claim( ], ) process_and_assert(machine, JobState.COMPLETED_ERROR, JobState.CANCEL_CLAIM_FAILED_REVERT_TEMP_STATION_OF_JURISDICTION, 3) - mock_hoppy_async_client.make_request.assert_has_calls( + 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, get_pending_contentions_req), call(machine.job.job_id, get_ep400_contentions_req), + call(machine.job.job_id, get_pending_claim_req), call(machine.job.job_id, update_temporary_station_of_jurisdiction_req), call(machine.job.job_id, create_contentions_on_pending_claim_req), call(machine.job.job_id, cancel_ep400_claim_req), call(machine.job.job_id, revert_temporary_station_of_jurisdiction_req), - ] + ], ) assert_metrics_called( metric_logger_distribution, @@ -777,6 +962,7 @@ def test_invalid_request_at_add_claim_note_due_to_exception( get_ep400_claim_200, get_pending_contentions_200, get_ep400_contentions_200, + get_pending_claim_200, update_temporary_station_of_jurisdiction_200, create_contentions_on_pending_claim_201, cancel_claim_200, @@ -784,15 +970,19 @@ def test_invalid_request_at_add_claim_note_due_to_exception( ], ) process_and_assert(machine, JobState.COMPLETED_ERROR, JobState.ADD_CLAIM_NOTE_TO_EP400, 1) - mock_hoppy_async_client.make_request.assert_has_calls( + 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, get_pending_contentions_req), call(machine.job.job_id, get_ep400_contentions_req), + call(machine.job.job_id, get_pending_claim_req), call(machine.job.job_id, update_temporary_station_of_jurisdiction_req), call(machine.job.job_id, create_contentions_on_pending_claim_req), call(machine.job.job_id, cancel_ep400_claim_req), call(machine.job.job_id, add_claim_note_req), - ] + ], ) assert_metrics_called(metric_logger_distribution, metric_logger_increment, JobState.COMPLETED_ERROR, JobState.ADD_CLAIM_NOTE_TO_EP400, 1, False) @@ -838,6 +1028,7 @@ def test_process_succeeds_with_different_contention( get_ep400_claim_200, pending_contentions, ep400_contentions, + get_pending_claim_200, update_temporary_station_of_jurisdiction_200, create_contentions_on_pending_claim_201, cancel_claim_200, @@ -845,14 +1036,19 @@ def test_process_succeeds_with_different_contention( ], ) process_and_assert(machine, JobState.COMPLETED_SUCCESS) - mock_hoppy_async_client.make_request.assert_has_calls( + 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, get_pending_contentions_req), call(machine.job.job_id, get_ep400_contentions_req), + call(machine.job.job_id, get_pending_claim_req), call(machine.job.job_id, update_temporary_station_of_jurisdiction_req), call(machine.job.job_id, create_pending_claim_req), call(machine.job.job_id, cancel_ep400_claim_req), - ] + call(machine.job.job_id, add_claim_note_req), + ], ) assert_metrics_called(metric_logger_distribution, metric_logger_increment, JobState.COMPLETED_SUCCESS, None, 1, False) @@ -864,18 +1060,24 @@ def test_process_succeeds_with_duplicate_contention(self, machine, mock_hoppy_as get_ep400_claim_200, get_pending_contentions_increase_tinnitus_200, get_ep400_contentions_200, + get_pending_claim_200, update_temporary_station_of_jurisdiction_200, cancel_claim_200, add_claim_note_200, ], ) process_and_assert(machine, JobState.COMPLETED_SUCCESS) - mock_hoppy_async_client.make_request.assert_has_calls( + 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, get_pending_contentions_req), call(machine.job.job_id, get_ep400_contentions_req), + call(machine.job.job_id, get_pending_claim_req), call(machine.job.job_id, update_temporary_station_of_jurisdiction_req), call(machine.job.job_id, cancel_ep400_claim_req), - ] + call(machine.job.job_id, add_claim_note_req), + ], ) assert_metrics_called(metric_logger_distribution, metric_logger_increment, JobState.COMPLETED_SUCCESS, None, 0, True) diff --git a/domain-ee/ee-ep-merge-app/tests/service/test_ep_merge_resume_at_add_note.py b/domain-ee/ee-ep-merge-app/tests/service/test_ep_merge_resume_at_add_note.py index bace944522..847d025ae6 100644 --- a/domain-ee/ee-ep-merge-app/tests/service/test_ep_merge_resume_at_add_note.py +++ b/domain-ee/ee-ep-merge-app/tests/service/test_ep_merge_resume_at_add_note.py @@ -5,6 +5,7 @@ EP400_CLAIM_ID, JOB_ID, PENDING_CLAIM_ID, + assert_hoppy_requests, add_claim_note_200, add_claim_note_req, get_ep400_contentions_200, @@ -43,19 +44,23 @@ class TestUpToGetPendingClaim: pytest.param(load_response(response_400, get_claim.Response), id="400"), pytest.param(load_response(response_404, get_claim.Response), id="404"), pytest.param(load_response(response_500, get_claim.Response), id="500"), - pytest.param(get_claim.Response(statusCode=200, statusMessage="OK", claim=ClaimDetail(claimId=3)).model_dump(), id="claim has no endProductCode"), + pytest.param( + get_claim.Response(statusCode=200, statusMessage="OK", claim=ClaimDetail(claimId=3, claimLifecycleStatus="Open")).model_dump(), + id="claim has no endProductCode", + ), ], ) def test_invalid_request(self, machine, mock_hoppy_async_client, invalid_request): mock_async_responses(mock_hoppy_async_client, [invalid_request, get_ep400_contentions_200, update_contentions_on_ep400_200]) process_and_assert(machine, JobState.COMPLETED_ERROR, JobState.GET_PENDING_CLAIM, 1) - mock_hoppy_async_client.make_request.assert_has_calls( + assert_hoppy_requests( + mock_hoppy_async_client, [ call(machine.job.job_id, get_pending_claim_req), # calls below are to attempt remove the special issue codes upon failure to get pending_claim call(machine.job.job_id, get_ep400_contentions_req), call(machine.job.job_id, update_contentions_on_ep400_req), - ] + ], ) @pytest.mark.parametrize( @@ -69,12 +74,13 @@ def test_invalid_request(self, machine, mock_hoppy_async_client, invalid_request def test_no_contentions_on_ep400_after_get_pending_claim_failure(self, machine, mock_hoppy_async_client, no_contentions_response): mock_async_responses(mock_hoppy_async_client, [ResponseException("Oops"), no_contentions_response]) process_and_assert(machine, JobState.COMPLETED_ERROR, JobState.GET_PENDING_CLAIM, 2) - mock_hoppy_async_client.make_request.assert_has_calls( + assert_hoppy_requests( + mock_hoppy_async_client, [ call(machine.job.job_id, get_pending_claim_req), # calls below are to attempt remove the special issue codes upon failure to get pending_claim, but there are no ep400 contentions call(machine.job.job_id, get_ep400_contentions_req), - ] + ], ) @pytest.mark.parametrize( @@ -95,12 +101,13 @@ def test_invalid_request_at_get_ep400_contentions_after_get_pending_claim_failur ], ) process_and_assert(machine, JobState.COMPLETED_ERROR, JobState.GET_PENDING_CLAIM_FAILED_REMOVE_SPECIAL_ISSUE, 3) - mock_hoppy_async_client.make_request.assert_has_calls( + assert_hoppy_requests( + mock_hoppy_async_client, [ call(machine.job.job_id, get_pending_claim_req), # calls below are to attempt remove the special issue codes upon failure to get pending_claim, fails on call to get ep400 contentions call(machine.job.job_id, get_ep400_contentions_req), - ] + ], ) @pytest.mark.parametrize( @@ -122,12 +129,14 @@ def test_invalid_request_at_update_ep400_contentions_after_get_pending_claim_fai ], ) process_and_assert(machine, JobState.COMPLETED_ERROR, JobState.GET_PENDING_CLAIM_FAILED_REMOVE_SPECIAL_ISSUE, 2) - mock_hoppy_async_client.make_request.assert_has_calls( + assert_hoppy_requests( + mock_hoppy_async_client, [ call(machine.job.job_id, get_pending_claim_req), # calls below are to attempt remove the special issue codes upon failure to get pending_claim, fails on update ep400 contentions call(machine.job.job_id, get_ep400_contentions_req), - ] + call(machine.job.job_id, update_contentions_on_ep400_req), + ], ) @@ -144,12 +153,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, invalid_request]) process_and_assert(machine, JobState.COMPLETED_ERROR, JobState.ADD_CLAIM_NOTE_TO_EP400, 1) - mock_hoppy_async_client.make_request.assert_has_calls( + assert_hoppy_requests( + mock_hoppy_async_client, [ call(machine.job.job_id, get_pending_claim_req), # call below is attempt to add note, which fails call(machine.job.job_id, add_claim_note_req), - ] + ], ) @@ -158,4 +168,4 @@ 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, add_claim_note_200]) process_and_assert(machine, JobState.COMPLETED_SUCCESS) - mock_hoppy_async_client.make_request.assert_has_calls([call(machine.job.job_id, get_pending_claim_req), call(machine.job.job_id, add_claim_note_req)]) + assert_hoppy_requests(mock_hoppy_async_client, [call(machine.job.job_id, get_pending_claim_req), call(machine.job.job_id, add_claim_note_req)]) diff --git a/domain-ee/ee-ep-merge-app/tests/service/test_ep_merge_resume_at_cancel_ep400.py b/domain-ee/ee-ep-merge-app/tests/service/test_ep_merge_resume_at_cancel_ep400.py index 6d02255fae..50e760a2d6 100644 --- a/domain-ee/ee-ep-merge-app/tests/service/test_ep_merge_resume_at_cancel_ep400.py +++ b/domain-ee/ee-ep-merge-app/tests/service/test_ep_merge_resume_at_cancel_ep400.py @@ -5,6 +5,7 @@ EP400_CLAIM_ID, JOB_ID, PENDING_CLAIM_ID, + assert_hoppy_requests, add_claim_note_200, add_claim_note_req, cancel_claim_200, @@ -54,19 +55,23 @@ class TestUpToGetPendingClaim: pytest.param(load_response(response_400, get_claim.Response), id="400"), pytest.param(load_response(response_404, get_claim.Response), id="404"), pytest.param(load_response(response_500, get_claim.Response), id="500"), - pytest.param(get_claim.Response(statusCode=200, statusMessage="OK", claim=ClaimDetail(claimId=3)).model_dump(), id="claim has no endProductCode"), + pytest.param( + get_claim.Response(statusCode=200, statusMessage="OK", claim=ClaimDetail(claimId=3, claimLifecycleStatus="Open")).model_dump(), + id="claim has no endProductCode", + ), ], ) def test_invalid_request(self, machine, mock_hoppy_async_client, invalid_request): mock_async_responses(mock_hoppy_async_client, [invalid_request, get_ep400_contentions_200, update_contentions_on_ep400_200]) process_and_assert(machine, JobState.COMPLETED_ERROR, JobState.GET_PENDING_CLAIM, 1) - mock_hoppy_async_client.make_request.assert_has_calls( + assert_hoppy_requests( + mock_hoppy_async_client, [ call(machine.job.job_id, get_pending_claim_req), # calls below are to attempt remove the special issue codes upon failure to get pending_claim call(machine.job.job_id, get_ep400_contentions_req), call(machine.job.job_id, update_contentions_on_ep400_req), - ] + ], ) @pytest.mark.parametrize( @@ -80,12 +85,13 @@ def test_invalid_request(self, machine, mock_hoppy_async_client, invalid_request def test_no_contentions_on_ep400_after_get_pending_claim_failure(self, machine, mock_hoppy_async_client, no_contentions_response): mock_async_responses(mock_hoppy_async_client, [ResponseException("Oops"), no_contentions_response]) process_and_assert(machine, JobState.COMPLETED_ERROR, JobState.GET_PENDING_CLAIM, 2) - mock_hoppy_async_client.make_request.assert_has_calls( + assert_hoppy_requests( + mock_hoppy_async_client, [ call(machine.job.job_id, get_pending_claim_req), # calls below are to attempt remove the special issue codes upon failure to get pending_claim, but there are no ep400 contentions call(machine.job.job_id, get_ep400_contentions_req), - ] + ], ) @pytest.mark.parametrize( @@ -106,12 +112,13 @@ def test_invalid_request_at_get_ep400_contentions_after_get_pending_claim_failur ], ) process_and_assert(machine, JobState.COMPLETED_ERROR, JobState.GET_PENDING_CLAIM_FAILED_REMOVE_SPECIAL_ISSUE, 3) - mock_hoppy_async_client.make_request.assert_has_calls( + assert_hoppy_requests( + mock_hoppy_async_client, [ call(machine.job.job_id, get_pending_claim_req), # calls below are to attempt remove the special issue codes upon failure to get pending_claim, fails on call to get ep400 contentions call(machine.job.job_id, get_ep400_contentions_req), - ] + ], ) @pytest.mark.parametrize( @@ -133,12 +140,14 @@ def test_invalid_request_at_update_ep400_contentions_after_get_pending_claim_fai ], ) process_and_assert(machine, JobState.COMPLETED_ERROR, JobState.GET_PENDING_CLAIM_FAILED_REMOVE_SPECIAL_ISSUE, 2) - mock_hoppy_async_client.make_request.assert_has_calls( + assert_hoppy_requests( + mock_hoppy_async_client, [ call(machine.job.job_id, get_pending_claim_req), # calls below are to attempt remove the special issue codes upon failure to get pending_claim, fails on update ep400 contentions call(machine.job.job_id, get_ep400_contentions_req), - ] + call(machine.job.job_id, update_contentions_on_ep400_req), + ], ) @@ -162,13 +171,14 @@ def test_invalid_request_at_cancel_claim_due_to_exception(self, machine, mock_ho mock_async_responses(mock_hoppy_async_client, [get_pending_claim_200, invalid_request, revert_temporary_station_of_jurisdiction_200]) process_and_assert(machine, JobState.COMPLETED_ERROR, JobState.CANCEL_EP400_CLAIM, 1) - mock_hoppy_async_client.make_request.assert_has_calls( + 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), # calls below are to attempt revert tsoj due to fail to cancel call(machine.job.job_id, revert_temporary_station_of_jurisdiction_req), - ] + ], ) @pytest.mark.parametrize( @@ -183,13 +193,14 @@ 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]) process_and_assert(machine, JobState.COMPLETED_ERROR, JobState.CANCEL_CLAIM_FAILED_REVERT_TEMP_STATION_OF_JURISDICTION, 3) - mock_hoppy_async_client.make_request.assert_has_calls( + 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), # 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), - ] + ], ) @@ -206,13 +217,14 @@ 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]) process_and_assert(machine, JobState.COMPLETED_ERROR, JobState.ADD_CLAIM_NOTE_TO_EP400, 1) - mock_hoppy_async_client.make_request.assert_has_calls( + 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 below is attempt to add note, which fails call(machine.job.job_id, add_claim_note_req), - ] + ], ) @@ -221,6 +233,7 @@ 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]) process_and_assert(machine, JobState.COMPLETED_SUCCESS) - mock_hoppy_async_client.make_request.assert_has_calls( - [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)] + 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)], ) diff --git a/mocks/mock-bip-claims-api/src/main/resources/mock-claims.json b/mocks/mock-bip-claims-api/src/main/resources/mock-claims.json index db86281ae6..bfd5df05ac 100644 --- a/mocks/mock-bip-claims-api/src/main/resources/mock-claims.json +++ b/mocks/mock-bip-claims-api/src/main/resources/mock-claims.json @@ -791,7 +791,8 @@ "claimId": 10000, "phase": "Claim Received", "tempStationOfJurisdiction": "398", - "endProductCode": "010" + "endProductCode": "010", + "claimLifecycleStatus": "Open" }, "contentions": [ { @@ -1006,7 +1007,8 @@ "claimId": 5001, "phase": "Claim Received", "tempStationOfJurisdiction": "398", - "endProductCode": "010" + "endProductCode": "010", + "claimLifecycleStatus": "Open" }, "contentions": [ { @@ -1085,7 +1087,8 @@ "claimId": 5004, "phase": "Claim Received", "tempStationOfJurisdiction": "398", - "endProductCode": "010" + "endProductCode": "010", + "claimLifecycleStatus": "Open" }, "contentions": [ { @@ -1163,7 +1166,8 @@ "claimId": 5006, "phase": "Claim Received", "tempStationOfJurisdiction": "398", - "endProductCode": "010" + "endProductCode": "010", + "claimLifecycleStatus": "Open" }, "contentions": [ {