Skip to content

Serialize CompletedWork flags in CompletedWorkSerializer #553

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 17, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion commcare_connect/opportunity/tests/test_api_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,12 @@ def test_delivery_progress_endpoint(
status=VisitValidationStatus.pending,
opportunity_access=access,
completed_work=completed_work,
flag_reason={"flags": [("duration", "The form was completed too quickly.")]},
flag_reason={
"flags": [
["duration", "The form was completed too quickly."],
["attachment_missing", "Form was submitted without attachments."],
]
},
)
api_client.force_authenticate(mobile_user_with_connect_link)
response = api_client.get(f"/api/opportunity/{opportunity.id}/delivery_progress")
Expand All @@ -237,6 +242,10 @@ def test_delivery_progress_endpoint(
assert len(response.data["deliveries"]) == 1
assert len(response.data["payments"]) == 0
assert response.data["deliveries"][0].keys() == CompletedWorkSerializer().get_fields().keys()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good catch. It was orginally like that because we switched serializers and wanted to ensure compatibility, but I agree that now that we are making additions, we should use the correct one. That said, I am not sure this assertion is buying us much, and would prefer the test to check expected values of keys we care about in the fields rather than just the presence of the keys.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True true. I'll update!

assert response.data["deliveries"][0]["flags"] == [
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that I think about it, is this the expected format? Would it not make more sense to have it like this:

[
    {
        "duration": "The form was completed too quickly.",
        "attachment_missing": "Form was submitted without attachments.",
    },
]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@calellowitz Actually, I'm going to update it as above. Feel free to let me know if that's not in fact what was envisioned. So now a single visit's flags will be consolidated into this one dictionary structure.

See c384c9e

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops yes. This is definitely what was intended. Thanks for the fix (and one more benefit of tests, making this stuff explicit).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, shouldn't this not be a list at all. If this is always a list with a single dict, I think it can just be a dict.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{"duration": "The form was completed too quickly."},
{"attachment_missing": "Form was submitted without attachments."},
]

Payment.objects.create(amount=10, date_paid=datetime.date.today(), opportunity_access=access)
response = api_client.get(f"/api/opportunity/{opportunity.id}/delivery_progress")
Expand Down