cal-itp / benefits

Transit benefits enrollment, minus the paperwork.
https://docs.calitp.org/benefits
GNU Affero General Public License v3.0
25 stars 9 forks source link

Feat: analytics for auth claims flow #2125

Closed lalver1 closed 1 month ago

lalver1 commented 1 month ago

Closes #2049

How to test

To test the error condition, insert something like claim_value = "20" after line 73 in benefits.oauth.views.authorize. Then check that "error_code": 20 appears as a property of "event_properties" in the log.

Notes

The behavior originally described in these notes was fixed by #2127.

When running the test test_authorize_success_without_verifier_claim, the oauth middleware VerifierUsesAuthVerificationSessionRequired that decorates the authorize view seems to behave differently compared to debugging the application.

Specifically, line 19 in benefits/oauth/middleware.py evaluates to a <Mock> object if running the test, but it evaluates to a boolean if debugging the application.

~~To see this behavior, debug the test and notice that line 19 evaluates to a<Mock> object, so the if condition evaluates to True and returns None instead of returning the user error page. However, when debugging the application and setting claim in AuthProvider to blank (to simulate a missing verifier claim in the database), line 19 will evaluate to False and the conditional will return the user error page.~~

Also, seems like verifier.auth_provider.claim = "" in the test only sets verifier_claim = verifier.auth_provider.claim (line 64 in the view). For a test closer to the behavior being tested, we may need to set the claim to blank in a fixture similar to model_AuthProvider_with_verification.

github-actions[bot] commented 1 month ago

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  benefits/oauth
  analytics.py 68
  views.py
Project Total  

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

lalver1 commented 1 month ago

I'm unsure what to do about missing tests for lines 68-71 in benefits.oauth.analytics.finished_sign_in since finished_sign_in doesn't return a value; I likely need a mocker. We addressed this during our dev workshop 👍