Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pavlo-mk committed Jul 15, 2024
1 parent bf0584b commit 73e23d0
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion backend/hct_mis_api/apps/grievance/tests/test_services_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
to_phone_number_str,
verify_flex_fields,
)
from hct_mis_api.apps.grievance.utils import validate_individual_for_need_adjudication
from hct_mis_api.apps.grievance.utils import (
validate_all_individuals_before_close_needs_adjudication,
validate_individual_for_need_adjudication,
)
from hct_mis_api.apps.household.fixtures import (
BankAccountInfoFactory,
DocumentFactory,
Expand Down Expand Up @@ -254,3 +257,39 @@ def test_validate_individual_for_need_adjudication(self) -> None:
individuals[0].save()
validate_individual_for_need_adjudication(partner_unicef, individuals[0], ticket_details, "distinct")
assert str(e.value) == "The selected individual IND-333 is not valid, must be not withdrawn"

def test_validate_all_individuals_before_close_needs_adjudication(self) -> None:
BusinessAreaFactory(slug="afghanistan")
_, individuals_1 = create_household(
{"size": 1},
{"given_name": "John", "family_name": "Doe", "middle_name": "", "full_name": "John Doe"},
)

_, individuals_2 = create_household(
{"size": 1},
{"given_name": "John", "family_name": "Doe", "middle_name": "", "full_name": "John Doe"},
)
ticket_details = TicketNeedsAdjudicationDetailsFactory(
golden_records_individual=individuals_1[0],
is_multiple_duplicates_version=True,
selected_individual=None,
)
ticket_details.possible_duplicates.add(individuals_2[0])
ticket_details.save()

with pytest.raises(ValidationError) as e:
validate_all_individuals_before_close_needs_adjudication(ticket_details)
assert str(e.value) == "Close ticket is not possible when all Individuals are flagged as duplicates"

with pytest.raises(ValidationError) as e:
validate_all_individuals_before_close_needs_adjudication(ticket_details)
assert (
str(e.value)
== "Close ticket is possible when at least one individual is flagged as distinct or one of the individuals is withdrawn or duplicate"
)

with pytest.raises(ValidationError) as e:
ticket_details.selected_distinct.add(individuals_2[0])
ticket_details.save()
validate_all_individuals_before_close_needs_adjudication(ticket_details)
assert str(e.value) == "Close ticket is possible when all active Individuals are flagged"

0 comments on commit 73e23d0

Please sign in to comment.