-
Notifications
You must be signed in to change notification settings - Fork 166
Namespace platform authenticator params in analytics controller #2622
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| require 'rails_helper' | ||
|
|
||
| describe 'frontend analytics requests' do | ||
| describe 'platform authenticators' do | ||
| let(:analytics) { FakeAnalytics.new } | ||
|
|
||
| before do | ||
| allow(analytics).to receive(:track_event) | ||
| allow(Analytics).to receive(:new).and_return(analytics) | ||
| end | ||
|
|
||
| it 'does not log anything if the user is not authed' do | ||
| expect(analytics).to_not receive(:track_event). | ||
| with(Analytics::FRONTEND_BROWSER_CAPABILITIES, any_args) | ||
|
|
||
| post analytics_path, params: { platform_authenticator: { available: true } } | ||
| end | ||
|
|
||
| it 'logs true if the platform authenticator is available' do | ||
| sign_in_user | ||
|
|
||
| post analytics_path, params: { platform_authenticator: { available: true } } | ||
|
|
||
| expect(analytics).to have_received(:track_event). | ||
| with(Analytics::FRONTEND_BROWSER_CAPABILITIES, hash_including(platform_authenticator: true)) | ||
| end | ||
|
|
||
| it 'logs false if the platform authenticator is not available' do | ||
| sign_in_user | ||
|
|
||
| post analytics_path, params: { platform_authenticator: { available: false } } | ||
|
|
||
| expect(analytics).to have_received(:track_event). | ||
| with( | ||
| Analytics::FRONTEND_BROWSER_CAPABILITIES, | ||
| hash_including(platform_authenticator: false) | ||
| ) | ||
| end | ||
|
|
||
| it 'only logs 1 platform authenticator event per session' do | ||
| sign_in_user | ||
|
|
||
| post analytics_path, params: { platform_authenticator: { available: true } } | ||
| post analytics_path, params: { platform_authenticator: { available: true } } | ||
|
|
||
| expect(analytics).to have_received(:track_event). | ||
| with( | ||
| Analytics::FRONTEND_BROWSER_CAPABILITIES, | ||
| hash_including(platform_authenticator: true) | ||
| ). | ||
| once | ||
| end | ||
|
|
||
| it 'logs ignores garbage values' do | ||
| sign_in_user | ||
|
|
||
| post analytics_path, params: { platform_authenticator: { available: 'blah blah blah' } } | ||
|
|
||
| expect(analytics).to_not have_received(:track_event). | ||
| with(Analytics::FRONTEND_BROWSER_CAPABILITIES, any_args) | ||
| end | ||
|
|
||
| it 'supports the legacy API format' do | ||
| sign_in_user | ||
|
|
||
| post analytics_path, params: { available: true } | ||
|
|
||
| expect(analytics).to have_received(:track_event). | ||
| with(Analytics::FRONTEND_BROWSER_CAPABILITIES, hash_including(platform_authenticator: true)) | ||
| end | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| module RequestHelper | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are these changes just piggybacking on this PR?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I added a helper to authenticate a user in the specs. The analytics request specs require you be authed. |
||
| VALID_PASSWORD = 'Val!d Pass w0rd'.freeze | ||
|
|
||
| def user_with_2fa | ||
| create(:user, :signed_up, with: { phone: '+1 202-555-1212' }, password: VALID_PASSWORD) | ||
| end | ||
|
|
||
| def sign_in_user(user = user_with_2fa) | ||
| post new_user_session_path, params: { user: { email: user.email, password: user.password } } | ||
| get otp_send_path, params: { otp_delivery_selection_form: { otp_delivery_preference: 'sms' } } | ||
| follow_redirect! | ||
| post login_two_factor_path, params: { | ||
| otp_delivery_preference: 'sms', code: user.reload.direct_otp | ||
| } | ||
| end | ||
| end | ||
|
|
||
| RSpec.configure do |config| | ||
| config.include RequestHelper, type: :request | ||
| end | ||
Uh oh!
There was an error while loading. Please reload this page.