Skip to content

Commit

Permalink
fix: attachment date in add records & update reqs (#3525)
Browse files Browse the repository at this point in the history
  • Loading branch information
rikuke authored Nov 11, 2024
1 parent 45095c5 commit af635c0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
23 changes: 16 additions & 7 deletions backend/benefit/applications/services/ahjo_payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,24 @@ class UpdateRecordsRecordTitle(AhjoTitle):
Attributes:
prefix (str): A default string ", täydennys," that is used in the title of update records.
attachment_created_at (datetime): The created_at date of the attachment that is being updated to Ahjo.
Methods:
__str__(): Returns the formatted string representation of the update record title.
"""

prefix: str = field(default=", täydennys,")
attachment_created_at: datetime = None

def __str__(self):
"""
Returns a formatted title string for an update record,
using the application's modification date and application number.
using the created_at date of the supplied attachment and application number.
Returns:
str: The formatted title string.
"""
modified_at = self.application.modified_at
formatted_date = modified_at.strftime("%d.%m.%Y")
formatted_date = self.attachment_created_at.strftime("%d.%m.%Y")
return self.format_title_string(
formatted_date, self.application.application_number
)
Expand All @@ -109,17 +110,19 @@ class AddRecordsRecordTitle(AhjoTitle):
"""
A class for creating the title of an additional record sent after the initial open case request.
Inherits from AhjoTitle. Uses the application's creation date and application number to format the title.
Inherits from AhjoTitle. Uses the attachment's creation date and application number to format the title.
The prefix is set to ", täydennys," by default.
Attributes:
prefix (str): A default string ", täydennys," that is used in the title of additional records.
attachment_created_at (datetime): The created_at date of the attachment that is being updated to Ahjo.
Methods:
__str__(): Returns the formatted string representation of the additional record title.
"""

prefix: str = field(default=", täydennys,")
attachment_created_at: datetime = None

def __str__(self):
"""
Expand All @@ -129,7 +132,7 @@ def __str__(self):
Returns:
str: The formatted title string.
"""
formatted_date = self.application.created_at.strftime("%d.%m.%Y")
formatted_date = self.attachment_created_at.strftime("%d.%m.%Y")
return self.format_title_string(
formatted_date, self.application.application_number
)
Expand Down Expand Up @@ -407,9 +410,12 @@ def prepare_attachment_records_payload(
attachment_list = []

for attachment in attachments:
title = AddRecordsRecordTitle(
application=application, attachment_created_at=attachment.created_at
)
attachment_list.append(
_prepare_record(
record_title=f"{AddRecordsRecordTitle(application)}",
record_title=f"{title}",
record_type=AhjoRecordType.ATTACHMENT,
acquired=attachment.created_at.isoformat("T", "seconds"),
documents=[_prepare_record_document_dict(attachment)],
Expand All @@ -431,10 +437,13 @@ def prepare_update_application_payload(
f"Attachment for {application.application_number} must have a ahjo_version_series_id for update."
)
language = resolve_payload_language(application)
title = UpdateRecordsRecordTitle(
application=application, attachment_created_at=pdf_summary.created_at
)
return {
"records": [
_prepare_record(
record_title=f"{UpdateRecordsRecordTitle(application)}",
record_title=f"{title}",
record_type=AhjoRecordType.APPLICATION,
acquired=pdf_summary.created_at.isoformat("T", "seconds"),
documents=[_prepare_record_document_dict(pdf_summary)],
Expand Down
20 changes: 15 additions & 5 deletions backend/benefit/applications/tests/test_ahjo_payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,13 @@ def test_open_case_record_title_str():
# Test UpdateRecordsRecordTitle class
def test_update_records_record_title_str():
mock_app = Mock(spec=Application)
mock_app.modified_at = datetime(2023, 2, 25)
mock_app.created_at = datetime(2023, 3, 10)
attachment_created_at = datetime(2023, 2, 25)
mock_app.application_number = "67890"

update_records_title = UpdateRecordsRecordTitle(application=mock_app)
update_records_title = UpdateRecordsRecordTitle(
application=mock_app, attachment_created_at=attachment_created_at
)
result = str(update_records_title)
expected = f"{AhjoRecordTitle.APPLICATION}, täydennys, 25.02.2023, 67890"
assert result == expected
Expand All @@ -80,9 +83,12 @@ def test_update_records_record_title_str():
def test_add_records_record_title_str():
mock_app = Mock(spec=Application)
mock_app.created_at = datetime(2023, 3, 10)
attachment_created_at = datetime(2023, 3, 10)
mock_app.application_number = "54321"

add_records_title = AddRecordsRecordTitle(application=mock_app)
add_records_title = AddRecordsRecordTitle(
application=mock_app, attachment_created_at=attachment_created_at
)
result = str(add_records_title)
expected = f"{AhjoRecordTitle.APPLICATION}, täydennys, 10.03.2023, 54321"
assert result == expected
Expand Down Expand Up @@ -211,6 +217,8 @@ def test_prepare_record_title(
and request_type == AhjoRequestType.OPEN_CASE
):
got = f"{title_class(application, current=part, total=total)}"
elif title_class in [UpdateRecordsRecordTitle, AddRecordsRecordTitle]:
got = f"{title_class(application=application, attachment_created_at=application.submitted_at)}"
else:
got = f"{title_class(application=application)}"
assert wanted_title == got
Expand Down Expand Up @@ -387,11 +395,13 @@ def test_prepare_update_application_payload(decided_application):
attachment_type=AttachmentType.PDF_SUMMARY,
ahjo_version_series_id=str(uuid.uuid4()),
)

title = UpdateRecordsRecordTitle(
application=application, attachment_created_at=fake_summary.created_at
)
want = {
"records": [
{
"Title": f"{UpdateRecordsRecordTitle(application=application,)}",
"Title": f"{title}",
"Type": AhjoRecordType.APPLICATION,
"Acquired": application.submitted_at.isoformat(),
"PublicityClass": "Salassa pidettävä",
Expand Down

0 comments on commit af635c0

Please sign in to comment.