Skip to content

Commit

Permalink
Revert to checking extra analytics keywords only
Browse files Browse the repository at this point in the history
  • Loading branch information
aduth committed May 9, 2024
1 parent ae8df0a commit 2f5ee92
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
require 'rails_helper'

RSpec.describe Idv::ByMail::RequestLetterController,
allowed_extra_analytics: [
:idv_gpo_address_letter_requested,
:idv_gpo_address_letter_enqueued,
] do
allowed_extra_analytics: [:sample_bucket1, :sample_bucket2] do
let(:user) { create(:user) }

let(:ab_test_args) do
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/idv/otp_verification_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'rails_helper'

RSpec.describe Idv::OtpVerificationController,
allowed_extra_analytics: [:idv_phone_confirmation_otp_submitted] do
allowed_extra_analytics: [:sample_bucket1, :sample_bucket2] do
let(:user) { create(:user) }

let(:phone) { '2255555000' }
Expand Down
3 changes: 2 additions & 1 deletion spec/controllers/idv/phone_errors_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'rails_helper'

RSpec.describe Idv::PhoneErrorsController, allowed_extra_analytics: [:idv_phone_error_visited] do
RSpec.describe Idv::PhoneErrorsController,
allowed_extra_analytics: [:sample_bucket1, :sample_bucket2] do
let(:ab_test_args) do
{ sample_bucket1: :sample_value1, sample_bucket2: :sample_value2 }
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
require 'rails_helper'

RSpec.describe(
Users::TwoFactorAuthenticationSetupController,
allowed_extra_analytics: [:user_registration_2fa_setup],
) do
RSpec.describe Users::TwoFactorAuthenticationSetupController, allowed_extra_analytics: [:*] do
describe 'GET index' do
let(:user) { create(:user) }

Expand Down
21 changes: 12 additions & 9 deletions spec/support/fake_analytics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ def track_event(event, original_attributes = {})
[](:method_name)&.
to_sym

@@checked_extra_analytics = checked_extra_analytics.to_a.push(method_name)

if method_name && (allowed_extra_analytics & [:*, method_name]).blank?
if method_name
analytics_method = AnalyticsEvents.instance_method(method_name)

param_names = analytics_method.
Expand All @@ -97,15 +95,20 @@ def track_event(event, original_attributes = {})

extra_keywords = original_attributes.keys \
- [:pii_like_keypaths, :user_id] \
- Array(allowed_extra_analytics) \
- param_names \
- option_param_names(analytics_method)

if extra_keywords.present?
raise UndocumentedParams, <<~ERROR
event :#{method_name} called with undocumented params #{extra_keywords.inspect}
(if these params are for specs only, use :allowed_extra_analytics metadata)
ERROR
@@checked_extra_analytics = checked_extra_analytics.to_a.concat(extra_keywords)

extra_keywords -= Array(allowed_extra_analytics)

if extra_keywords.present? && !allowed_extra_analytics.include?(:*)
raise UndocumentedParams, <<~ERROR
event :#{method_name} called with undocumented params #{extra_keywords.inspect}
(if these params are for specs only, use :allowed_extra_analytics metadata)
ERROR
end
end
end

Expand Down Expand Up @@ -208,7 +211,7 @@ def browser_attributes
unchecked_extra_analytics = allowed_extra_analytics - all_checked_extra_analytics
expect(unchecked_extra_analytics).to(
be_blank,
"Unnecessary allowed_extra_analytics method names on example group #{group}: " +
"Unnecessary allowed_extra_analytics keywords on example group #{group}: " +
unchecked_extra_analytics.to_s,
)
end
Expand Down

0 comments on commit 2f5ee92

Please sign in to comment.