Skip to content
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

Feat: analytics for multiple claims on a flow #2479

Merged
merged 3 commits into from
Oct 31, 2024

Conversation

lalver1
Copy link
Member

@lalver1 lalver1 commented Oct 28, 2024

Closes #2355
This PR is a follow-up to #2463. It includes the following changes:

  • Updating the returned enrollment analytics event to include the "extra claims" that came back as verified from IdG
  • Storing the error codes returned from IdG in a dictionary since multiple claims may be returned
  • Adding a column to EnrollmentEvent that holds the "extra claims"

Note that even though the coverage report for #2463 looked ok, this PR updates a few tests associated with #2463 because they felt a bit incomplete. For example

def test_authorize_success_with_claim_true(

and

def test_authorize_success_with_claim_false(

Reviewing

First run the database migrations since a new field was added to EnrollmentEvent. Since the changes involve the enrollment application and the claims that are returned from IdG, it's a bit tricky to review this PR. The tests seem to capture the behavior that has changed due to this PR, but you can also hard code a few lines to review the error code changes and EnrollmentEvent changes.

To review the error codes part, set claim_value = "10" in

claim_value = userinfo.get(claim)
and confirm that the error codes show up in the finished sign in event.

To see a new instance of an EnrollmentEvent that has multiple claims you can set, for example, extra_claims = "claim_1, claim_2" in

extra_claims = ", ".join(session.oauth_extra_claims(request))
to see how multiple claims are stored in the local database.

@lalver1 lalver1 self-assigned this Oct 28, 2024
@github-actions github-actions bot added back-end Django views, sessions, middleware, models, migrations etc. tests Related to automated testing (unit, UI, integration, etc.) deployment-dev [auto] Changes that will trigger a deploy if merged to dev and removed back-end Django views, sessions, middleware, models, migrations etc. labels Oct 28, 2024
@lalver1 lalver1 force-pushed the feat/analytics-multiple-claims branch 2 times, most recently from bac1407 to bcdafd9 Compare October 28, 2024 22:30
Copy link

github-actions bot commented Oct 28, 2024

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  benefits/core
  models.py
  session.py
  benefits/enrollment
  analytics.py
  views.py 79
  benefits/oauth
  views.py
Project Total  

This report was generated by python-coverage-comment-action

@lalver1 lalver1 force-pushed the feat/analytics-multiple-claims branch 2 times, most recently from d785ba8 to 727a4c1 Compare October 30, 2024 02:38
@lalver1 lalver1 marked this pull request as ready for review October 30, 2024 13:14
@lalver1 lalver1 requested a review from a team as a code owner October 30, 2024 13:14
@angela-tran
Copy link
Member

@lalver1 Thanks for the thorough notes in the PR description. I'm just now starting to review this PR and am a little confused by this note:

To see a new instance of an EnrollmentEvent in the local database, remove the EligibleSessionRequired decorator ...

Shouldn't we be able to just do a successful enrollment locally in order to see a new instance of an EnrollmentEvent in the local database? I'm not following why we need to do all these steps to fake it.

@lalver1
Copy link
Member Author

lalver1 commented Oct 30, 2024

Thanks for the review @angela-tran, yep, if you go through a successful enrollment you'll see the new instance of an EnrollmentEvent, but I think it only covers the case when IdG returns one claim. In the 'Reviewing' notes I was more thinking about being able to see how multiple claims would be shown on the local database in the new column since currently we don't really have a way to see this path when we go through a successful enrollment, so that's why I was faking it but there may be a cleaner way to test it out.

@angela-tran
Copy link
Member

@lalver1 Oh ok, I see. So in the steps for faking it, should there also be a step where we make it so the EnrollmentEvent will have some extra_claims? I see that it's around line 74 in enrollment.views.index that we read extra claims.

@lalver1
Copy link
Member Author

lalver1 commented Oct 30, 2024

Exactly! I'm re-reading the EnrollmentEvent section of 'Reviewing' and actually all that stuff isn't really necessary @angela-tran. Like you mentioned, you really you only need to overwrite line 74 and set, for example, extra_claims = "claim_1, claim_2" to see how multiple claims are stored in the local database. Thanks for the comment, I'll update the description.

@lalver1 lalver1 force-pushed the feat/analytics-multiple-claims branch 2 times, most recently from 9dd5b0e to 53dab30 Compare October 31, 2024 13:39
@lalver1
Copy link
Member Author

lalver1 commented Oct 31, 2024

Update on this PR:

  • Updated the function
    def oauth_extra_claims(request, eligibility_claim, oauth_claims):
    that returns only the "extra claims", now it checks for the claims_eligibility_claim instead of assuming it is the first element of the list (but after going back and forth writing this function, I'm realizing that this may not need to be in session.py since it's not using the first argument, request)
  • Used existing pattern of calling helper function to simplify this PR's original code in
    self.update_event_properties(status=status, error=error, extra_claims=extra_claims)

Currently addressing the missing coverage due to the new code in session.py

@lalver1 lalver1 force-pushed the feat/analytics-multiple-claims branch 2 times, most recently from ad8038f to c6fc4c3 Compare October 31, 2024 15:01
Copy link
Member

@thekaveman thekaveman left a comment

Choose a reason for hiding this comment

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

It's getting closer, but still could use a bit of code cleanup

benefits/core/session.py Show resolved Hide resolved
benefits/enrollment/views.py Outdated Show resolved Hide resolved
tests/pytest/enrollment/test_analytics.py Show resolved Hide resolved
@lalver1 lalver1 force-pushed the feat/analytics-multiple-claims branch from c6fc4c3 to 63a154b Compare October 31, 2024 16:51
@lalver1
Copy link
Member Author

lalver1 commented Oct 31, 2024

One more update on this PR, we worked with @thekaveman on cleaning up the code some more earlier today and I ran through older adult with the debugger (mostly to make sure types made sense when making calls to .remove() and .join() for example) one last time just to feel a bit more comfortable with the changes introduced.

@thekaveman
Copy link
Member

Nice job 🎉

@lalver1 lalver1 merged commit 82d6604 into main Oct 31, 2024
15 checks passed
@lalver1 lalver1 deleted the feat/analytics-multiple-claims branch October 31, 2024 18:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deployment-dev [auto] Changes that will trigger a deploy if merged to dev tests Related to automated testing (unit, UI, integration, etc.)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Medicare cardholder: distinguish between Older Adult and Disabled riders
3 participants