Skip to content

LG-14653 | Log state_id_type on doc auth result event#11328

Merged
n1zyy merged 6 commits intomainfrom
mattw/LG-14653_log_docauth_id_type
Oct 17, 2024
Merged

LG-14653 | Log state_id_type on doc auth result event#11328
n1zyy merged 6 commits intomainfrom
mattw/LG-14653_log_docauth_id_type

Conversation

@n1zyy
Copy link
Contributor

@n1zyy n1zyy commented Oct 9, 2024

🎫 Ticket

Link to the relevant ticket:
LG-14653

🛠 Summary of changes

After we began enforcing expiration_date on documents during proofing, I worked on a story to build reporting on the impact of those changes. A missing piece of data is the ID type: are non-DL type IDs being disproportionately impacted, for example? We know some states handle these differently.

This begins logging that data on the 'IdV: doc auth verify proofing results' event. It was previously logged on another event, but it's not practical to join them in Cloudwatch.

n1zyy added 2 commits October 9, 2024 10:58
changelog: Internal, Identity Proofing, Log state_id_type on doc auth verify proofing results event

event = @analytics.events["IdV: doc auth verify proofing results"].first
state_id = event[:proofing_results][:context][:stages][:state_id]
expect(state_id).to match(a_hash_including(state_id_type: 'drivers_license'))
Copy link
Contributor Author

@n1zyy n1zyy Oct 9, 2024

Choose a reason for hiding this comment

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

I couldn't find prior art for handling this situation...

I basically wanted:

  expect(@analytics).to have_logged_event(
    'IdV: doc auth verify proofing results',
    hash_including(
      {
        proofing_results => context => stages => state_id => { state_id_type: 'drivers_license' }
      },
    ),
  )

except that's not valid code. I started nesting hash_including but it got really unwieldy fast.

hash_including doesn't look deep in the hash, e.g., just doing hash_including(state_id_type: 'drivers_license') expects a top-level key named state_id_type; it doesn't dig down recursively until it finds a match.

The test above feels inelegant, except compared to every other option I tried.

Copy link
Contributor

Choose a reason for hiding this comment

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

we have one double-nested hash-including here:

success: true, errors: hash_including(message: nil), destination: :link_sent, flow_path: 'hybrid', step: 'hybrid_handoff', analytics_id: 'Doc Auth', telephony_response: hash_including(errors: {}, message_id: 'fake-message-id', request_id: 'fake-message-request-id', success: true), selfie_check_required: boolean

Copy link
Contributor

Choose a reason for hiding this comment

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

but I think that you're right, doing a point-check is clearer here

Copy link
Contributor

Choose a reason for hiding this comment

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

It's almost like we need have_logged_event to support a pattern like:

expect(@analytics).to have_logged_event(
    event_name, 
    hash_deeply_including(
        [:proofing_results, :context, :stages, :state_id],
        {state_id_type: 'drivers_license'},
    ),
)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lmgeorge Something like this came up in the #rspec-league channel when I asked about this, even with some example code. I'm reluctant to add it, though. I feel like it would normalize having deeply-nested hashes for important things, but I feel like it's an antipattern.

I think I agree more with the comment in that thread that something being clunky to test is often a smell that the code (or here, data structure) is too convoluted. That's not an easy fix in this PR, though.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed. This is one of those do you fix "all the things" or just try to make your current need work. Either way, adding a custom matcher or dramatically restructuring the analytics event is beyond the scope of this PR.

@n1zyy n1zyy requested a review from a team October 9, 2024 15:37
n1zyy and others added 3 commits October 9, 2024 12:48
@lmgeorge
Copy link
Contributor

LGTM!

@n1zyy n1zyy merged commit 0466036 into main Oct 17, 2024
@n1zyy n1zyy deleted the mattw/LG-14653_log_docauth_id_type branch October 17, 2024 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants