Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions spec/forms/recaptcha_enterprise_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,8 @@
end
end

context 'with extra analytics properties', allowed_extra_analytics: [:extra] do
let(:extra_analytics_properties) { { extra: true } }
context 'with extra analytics properties' do
let(:extra_analytics_properties) { { phone_country_code: true } }

it 'logs analytics of the body' do
result
Expand All @@ -409,7 +409,7 @@
score_threshold: score_threshold,
form_class: 'RecaptchaEnterpriseForm',
recaptcha_action:,
extra: true,
phone_country_code: true,
)
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/forms/recaptcha_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,8 @@
)
end

context 'with extra analytics properties', allowed_extra_analytics: [:extra] do
let(:extra_analytics_properties) { { extra: true } }
context 'with extra analytics properties' do
let(:extra_analytics_properties) { { phone_country_code: true } }

it 'logs analytics of the body' do
result
Expand All @@ -328,7 +328,7 @@
score_threshold: score_threshold,
form_class: 'RecaptchaForm',
recaptcha_action:,
extra: true,
phone_country_code: true,
)
end
end
Expand Down
34 changes: 3 additions & 31 deletions spec/support/fake_analytics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ def track_event(event, original_attributes = {})
UndocumentedParams = Class.new(StandardError).freeze

module UndocumentedParamsChecker
mattr_accessor :allowed_extra_analytics
mattr_accessor :checked_extra_analytics
mattr_accessor :asts
mattr_accessor :docstrings

Expand All @@ -98,16 +96,9 @@ def track_event(event, original_attributes = {})
- option_param_names(analytics_method)

if extra_keywords.present?
@@checked_extra_analytics = checked_extra_analytics.to_a.concat(extra_keywords)

extra_keywords -= Array(allowed_extra_analytics)

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
end
raise UndocumentedParams, <<~ERROR
event :#{method_name} called with undocumented params #{extra_keywords.inspect}
ERROR
end
end

Expand Down Expand Up @@ -176,22 +167,3 @@ def reset!
@events = Hash.new
end
end

RSpec.configure do |c|
groups = []

c.around do |ex|
keys = Array(ex.metadata[:allowed_extra_analytics])
FakeAnalytics::UndocumentedParamsChecker.allowed_extra_analytics = keys
ex.run

if keys.present?
group = ex.example_group
group = group.superclass until [nil, RSpec::Core::ExampleGroup].include?(group.superclass)
groups << [group, FakeAnalytics::UndocumentedParamsChecker.checked_extra_analytics.to_a]
end
ensure
FakeAnalytics::UndocumentedParamsChecker.allowed_extra_analytics = []
FakeAnalytics::UndocumentedParamsChecker.checked_extra_analytics = []
end
end
20 changes: 0 additions & 20 deletions spec/support/fake_analytics_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -585,26 +585,6 @@
end.to raise_error(FakeAnalytics::UndocumentedParams, /some_new_undocumented_keyword/)
end

it 'does not error when undocumented params are allowed',
allowed_extra_analytics: [:fun_level] do
analytics.idv_phone_confirmation_otp_submitted(
success: true,
errors: true,
code_expired: true,
code_matches: true,
otp_delivery_preference: :sms,
second_factor_attempts_count: true,
second_factor_locked_at: true,
proofing_components: true,
fun_level: 1000,
)

expect(analytics).to have_logged_event(
'IdV: phone confirmation otp submitted',
hash_including(:fun_level),
)
end

it 'does not error when string tags are documented as options' do
analytics.idv_doc_auth_submitted_image_upload_vendor(
success: nil,
Expand Down