Skip to content

Assert logged events using have_logged_event (simple cases)#11001

Merged
aduth merged 12 commits intomainfrom
aduth-track-event-have-logged-event
Jul 31, 2024
Merged

Assert logged events using have_logged_event (simple cases)#11001
aduth merged 12 commits intomainfrom
aduth-track-event-have-logged-event

Conversation

@aduth
Copy link
Contributor

@aduth aduth commented Jul 30, 2024

🛠 Summary of changes

Updates specs to replace expect(@analytics).to receive(:track_event).with with equivalent expect(@analytics).to have_logged_event.

This includes changes which can be ported over easily using simple pattern replacement (+ Rubocop autocorrection).

Pattern: receive\(:track_event\).(\n\s+)?with\((\n\s+)?('[^']+')
Replacement: have_logged_event($2$3

Remaining usage includes negated assertions, and assertions not including a specific event name being logged.

Why?

  • Because have_logged_event includes a number of additional helpers implemented through the FakeAnalytics class:
    • Accidental PII leak detection
    • Undocumented analytics method arguments checking
  • Facilitate work in Analytics: Compact event properties #10987

📜 Testing Plan

Verify build passes.

Copy link
Contributor

@zachmargolis zachmargolis left a comment

Choose a reason for hiding this comment

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

much easier to read as a separate PR, thanks! LGTM

@aduth
Copy link
Contributor Author

aduth commented Jul 30, 2024

Actually, I'll need to make some revisions here, since the order of assertions is different, i.e. have_logged_event has to happen after the event logging.

@aduth aduth marked this pull request as draft July 30, 2024 15:28
@aduth aduth force-pushed the aduth-track-event-have-logged-event branch from 73fb779 to 9ef2719 Compare July 31, 2024 12:41
@aduth aduth marked this pull request as ready for review July 31, 2024 12:58
@aduth aduth merged commit c951bb6 into main Jul 31, 2024
@aduth aduth deleted the aduth-track-event-have-logged-event branch July 31, 2024 12:59
mitchellhenke pushed a commit that referenced this pull request Jul 31, 2024
* Assert logged events using have_logged_event

changelog: Internal, Automated Testing, Assert logged events using have_logged_event

* Reshuffle have_logged_event after action that logs

* Remove unnecessary pii_like_keypaths stub expectatino

* Fix phone spec stub setup for NewPhoneForm

* Ensure event always created before running disavowal specs

Previously, the event only existed by the time the action was called since it was referenced in the stubs setup before the action call. Now the assertion happens after, so the event has to be created elsewise.

* Restore accidental action removal / shuffle

* Document missing analytics properties flagged by FakeAnalytics

* Remove redundant conflicting stub on Analytics#track_event

* Reshuffle have_logged_event after action that logs

* Remove unnecessary allowed_extra_analytics

* Remove redundant conflicting stub on Analytics#track_event

* Reshuffle have_logged_event after action that logs
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.

2 participants