Skip to content

Commit

Permalink
Hl 1361 missing full application (#3089)
Browse files Browse the repository at this point in the history
* fix: include full application in ahjo queries

* chore: print application number if error in update
  • Loading branch information
rikuke committed Jun 14, 2024
1 parent 8a4c215 commit 6ba69ab
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 4 deletions.
1 change: 0 additions & 1 deletion backend/benefit/applications/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ def get_by_statuses(
# Excluded attachment types
excluded_types = [
AttachmentType.PDF_SUMMARY,
AttachmentType.FULL_APPLICATION,
AttachmentType.DECISION_TEXT_XML,
AttachmentType.DECISION_TEXT_SECRET_XML,
]
Expand Down
4 changes: 3 additions & 1 deletion backend/benefit/applications/services/ahjo_payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,9 @@ def prepare_update_application_payload(
"""Prepare the payload that is sent to Ahjo when an application is updated, \
in this case it only contains a Records dict"""
if not pdf_summary.ahjo_version_series_id:
raise ValueError("Attachment must have an ahjo_version_series_id for update.")
raise ValueError(
f"Attachment for {application.application_number} must have a ahjo_version_series_id for update."
)
language = resolve_payload_language(application)
return {
"records": [
Expand Down
24 changes: 22 additions & 2 deletions backend/benefit/applications/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,11 +492,31 @@ def pytest_sessionfinish(session, exitstatus):

@pytest.fixture
def application_with_ahjo_case_id(decided_application):
decided_application.ahjo_case_id = "HEL 2024 12345"
decided_application.save()
decided_application.ahjo_case_id = generate_ahjo_case_id()
return decided_application


@pytest.fixture
def multiple_applications_with_ahjo_case_id(
mock_get_organisation_roles_and_create_company,
):
with factory.Faker.override_default_locale("fi_FI"):
applications = DecidedApplicationFactory.create_batch(
5, company=mock_get_organisation_roles_and_create_company
)

for a in applications:
a.ahjo_case_id = generate_ahjo_case_id()
a.save()
return applications


def generate_ahjo_case_id():
year = random.randint(2000, 2099)
case_id = random.randint(10000, 99999)
return f"HEL {year} {case_id}"


@pytest.fixture
def application_with_ahjo_decision(application_with_ahjo_case_id):
template = AcceptedDecisionProposalFactory()
Expand Down
47 changes: 47 additions & 0 deletions backend/benefit/applications/tests/test_ahjo_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,30 @@ def test_generate_ahjo_secret_decision_text_xml(decided_application):
os.remove(attachment.attachment_file.path)


@pytest.mark.django_db
def test_get_applications_for_ahjo_update(
multiple_applications_with_ahjo_case_id,
):
for a in multiple_applications_with_ahjo_case_id:
AhjoStatus.objects.create(
application=a,
status=AhjoStatusEnum.DECISION_PROPOSAL_ACCEPTED,
)

applications_for_ahjo_update = Application.objects.get_by_statuses(
[
ApplicationStatus.ACCEPTED,
ApplicationStatus.REJECTED,
],
AhjoStatusEnum.DECISION_PROPOSAL_ACCEPTED,
False,
)

assert applications_for_ahjo_update.count() == len(
multiple_applications_with_ahjo_case_id
)


@pytest.mark.django_db
def test_get_applications_for_open_case(
multiple_decided_applications,
Expand Down Expand Up @@ -745,6 +769,23 @@ def test_get_applications_for_open_case(
ahjo_status.created_at = now + timedelta(days=index)
ahjo_status.save()

wanted_open_case_attachments = [
AttachmentType.EMPLOYMENT_CONTRACT,
AttachmentType.PAY_SUBSIDY_DECISION,
AttachmentType.COMMISSION_CONTRACT,
AttachmentType.EDUCATION_CONTRACT,
AttachmentType.HELSINKI_BENEFIT_VOUCHER,
AttachmentType.EMPLOYEE_CONSENT,
AttachmentType.OTHER_ATTACHMENT,
AttachmentType.FULL_APPLICATION,
]

unwanted_open_case_attachments = [
AttachmentType.PDF_SUMMARY,
AttachmentType.DECISION_TEXT_XML,
AttachmentType.DECISION_TEXT_SECRET_XML,
]

applications_for_open_case = Application.objects.get_by_statuses(
[
ApplicationStatus.HANDLING,
Expand All @@ -754,6 +795,12 @@ def test_get_applications_for_open_case(
AhjoStatusEnum.SUBMITTED_BUT_NOT_SENT_TO_AHJO,
True,
)

for app in applications_for_open_case:
attachments = app.attachments.all()
for a in attachments:
assert a.attachment_type in wanted_open_case_attachments
assert a.attachment_type not in unwanted_open_case_attachments
# only handled_applications should be returned as their last AhjoStatus is SUBMITTED_BUT_NOT_SENT_TO_AHJO
# and their application status is HANDLING
assert applications_for_open_case.count() == len(wanted_applications_for_open_case)
Expand Down

0 comments on commit 6ba69ab

Please sign in to comment.