Skip to content

Update ImageUploadsController spec to use have_logged_event#10258

Merged
matthinz merged 4 commits intomainfrom
matthinz/image-uploads-have-logged-event
Mar 18, 2024
Merged

Update ImageUploadsController spec to use have_logged_event#10258
matthinz merged 4 commits intomainfrom
matthinz/image-uploads-have-logged-event

Conversation

@matthinz
Copy link
Contributor

🎫 Ticket

Related to work underway for LG-12657

🛠 Summary of changes

Over on #10230 I am doing some work that involves touching a lot of analytics-related specs. I noticed that the spec for Idv::ImageUploadsController was using syntax like:

expect(@analytics).to receive(:track_event).with('event name', { big list of args })

This PR updates the spec to use the have_logged_event matcher, which will make some of my changes a little easier.

The biggest thing here is that have_logged_event needs to be called after the action, rather than before, so this meant moving some code around.

have_logged_event doesn't support this, so we shouldn't use it here.

Also, it seems like all the event detail isn't required here--this event is only logged if the form submission succeeds
remaining_submit_attempts: IdentityConfig.store.doc_auth_max_attempts - 1,
pii_like_keypaths: pii_like_keypaths,
flow_path: 'standard',
).exactly(0).times
Copy link
Contributor Author

@matthinz matthinz Mar 15, 2024

Choose a reason for hiding this comment

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

This struck me as slightly odd--"make sure we receive this extremely specific method call exactly 0 times". Also there was a comma in the event name. I think what this is checking is that if the form validation fails, we are not logging IdV: doc auth image upload vendor submitted, so I updated it to that.

@matthinz matthinz requested review from a team and dawei-nava and removed request for a team March 15, 2024 22:38
Comment on lines -75 to +66
expect(@analytics).not_to receive(:track_event).with(
'IdV: doc auth image upload vendor submitted',
any_args,
)

expect(@irs_attempts_api_tracker).to receive(:track_event).with(
:idv_document_upload_submitted,
any_args,
)

action

expect(@analytics).not_to have_logged_event(
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you mind clarifying why have_logged_event is better or more useful than to receive(:track_event).with(...)? Mostly curious and would be good to know for future tests.

Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure it's Matt's reason, but one reason to prefer it is that receive(:track_event) may override our custom PII alerting and documentation enforcing helpers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it is mostly those things. Also consistent use of have_logged_event gives us some freedom to make changes to how we test events in a single place rather than updating every single callsite

Copy link
Contributor

@night-jellyfish night-jellyfish left a comment

Choose a reason for hiding this comment

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

This looks good to me and I'm approving, but it might be good to have one more Timnit engineer take a look on Monday.

(Also looks like CI is failing due to missing changelog).

Thanks for tagging us!

Copy link
Contributor

@dawei-nava dawei-nava left a comment

Choose a reason for hiding this comment

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

LGTM.

stub_attempts_tracker

expect(@analytics).to receive(:track_event).with(
expect(@irs_attempts_api_tracker).to receive(:track_event).with(
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious, is the irs attempts thing still needed?

@matthinz matthinz merged commit cecba48 into main Mar 18, 2024
@matthinz matthinz deleted the matthinz/image-uploads-have-logged-event branch March 18, 2024 17:15
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