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
5 changes: 5 additions & 0 deletions app/controllers/sign_up/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ def create
result = @register_user_email_form.submit(permitted_params)

analytics.user_registration_email(**result.to_h)
irs_attempts_api_tracker.user_registration_email_submitted(
email: permitted_params[:email],
success: result.success?,
failure_reason: result.to_h[:error_details],
)

if result.success?
process_successful_creation
Expand Down
5 changes: 5 additions & 0 deletions app/controllers/users/reset_passwords_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ def create_account_if_email_not_found
return unless result

analytics.user_registration_email(**result.to_h)
irs_attempts_api_tracker.user_registration_email_submitted(
email: email,
success: result.success?,
failure_reason: result.to_h[:error_details],
)
create_user_event(:account_created, user)
end

Expand Down
17 changes: 17 additions & 0 deletions app/services/irs_attempts_api/tracker_events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,22 @@ def user_registration_email_confirmation(
failure_reason: failure_reason,
)
end

# Tracks when user submits registration email
# @param [Boolean] success
# @param [String] email
# @param [Hash<Symbol,Array<Symbol>>] failure_reason
def user_registration_email_submitted(
success:,
email:,
failure_reason: nil
)
track_event(
:user_registration_email_submitted,
success: success,
email: email,
failure_reason: failure_reason,
)
end
end
end
26 changes: 26 additions & 0 deletions spec/controllers/sign_up/registrations_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@
context 'when registering with a new email' do
it 'tracks successful user registration' do
stub_analytics
stub_attempts_tracker

allow(@analytics).to receive(:track_event)
allow(@irs_attempts_api_tracker).to receive(:track_event)
allow(subject).to receive(:create_user_event)

post :create, params: { user: { email: 'new@example.com', terms_accepted: '1' } }
Expand All @@ -53,6 +55,13 @@
expect(@analytics).to have_received(:track_event).
with('User Registration: Email Submitted', analytics_hash)

expect(@irs_attempts_api_tracker).to have_received(:track_event).with(
:user_registration_email_submitted,
email: 'new@example.com',
success: true,
failure_reason: nil,
)

expect(subject).to have_received(:create_user_event).with(:account_created, user)
end

Expand Down Expand Up @@ -88,6 +97,7 @@
existing_user = create(:user, email: 'test@example.com')

stub_analytics
stub_attempts_tracker

analytics_hash = {
success: true,
Expand All @@ -100,13 +110,22 @@

expect(@analytics).to receive(:track_event).
with('User Registration: Email Submitted', analytics_hash)

expect(@irs_attempts_api_tracker).to receive(:track_event).with(
:user_registration_email_submitted,
email: 'TEST@example.com ',
success: true,
failure_reason: nil,
)

expect(subject).to_not receive(:create_user_event)

post :create, params: { user: { email: 'TEST@example.com ', terms_accepted: '1' } }
end

it 'tracks unsuccessful user registration' do
stub_analytics
stub_attempts_tracker

analytics_hash = {
success: false,
Expand All @@ -121,6 +140,13 @@
expect(@analytics).to receive(:track_event).
with('User Registration: Email Submitted', analytics_hash)

expect(@irs_attempts_api_tracker).to receive(:track_event).with(
:user_registration_email_submitted,
email: 'invalid@',
success: false,
failure_reason: { email: [:invalid] },
)

post :create, params: { user: { email: 'invalid@', request_id: '', terms_accepted: '1' } }
end

Expand Down
8 changes: 8 additions & 0 deletions spec/controllers/users/reset_passwords_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,8 @@
context 'no user matches email' do
it 'send an email to tell the user they do not have an account yet' do
stub_analytics
stub_attempts_tracker
allow(@irs_attempts_api_tracker).to receive(:track_event)
email = 'nonexistent@example.com'

expect do
Expand Down Expand Up @@ -342,6 +344,12 @@
'User Registration: Email Submitted',
analytics_hash,
)
expect(@irs_attempts_api_tracker).to have_received(:track_event).with(
:user_registration_email_submitted,
email: email,
success: true,
failure_reason: nil,
)

expect(response).to redirect_to forgot_password_path
end
Expand Down