Skip to content
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

LG-14389: Add analytics for consent screen email selection #11321

Merged
merged 2 commits into from
Oct 7, 2024
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
4 changes: 4 additions & 0 deletions app/controllers/sign_up/select_email_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@ def show
@user_emails = user_emails
@last_sign_in_email_address = last_email
@select_email_form = build_select_email_form
analytics.sp_select_email_visited(needs_completion_screen_reason:)
end

def create
@select_email_form = build_select_email_form

result = @select_email_form.submit(form_params)

analytics.sp_select_email_submitted(**result.to_h, needs_completion_screen_reason:)

if result.success?
user_session[:selected_email_id] = form_params[:selected_email_id]
redirect_to sign_up_completed_path
Expand Down
56 changes: 42 additions & 14 deletions spec/controllers/sign_up/select_email_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'rails_helper'

RSpec.describe SignUp::SelectEmailController do
let(:user) { create(:user) }
let(:user) { create(:user, :with_multiple_emails) }
let(:sp) { create(:service_provider) }

before do
Expand Down Expand Up @@ -29,6 +29,17 @@
describe '#show' do
subject(:response) { get :show }

it 'logs analytics event' do
stub_analytics

response

expect(@analytics).to have_logged_event(
:sp_select_email_visited,
needs_completion_screen_reason: :new_attributes,
)
end

it 'assigns view variables' do
response

Expand All @@ -51,32 +62,49 @@
end

describe '#create' do
let(:email) { '[email protected]' }
let(:email2) { '[email protected]' }
let(:email3) { '[email protected]' }
let(:params) { { selected_email_id: email2 } }
let(:selected_email) { user.confirmed_email_addresses.sample }
let(:params) { { select_email_form: { selected_email_id: selected_email.id } } }

subject(:response) { post :create, params: params }

before do
create(:email_address, user:, email: email)
create(:email_address, user:, email: email2)
it 'updates selected email address' do
response

expect(controller.user_session[:selected_email_id]).to eq(selected_email.id.to_s)
end

it 'updates selected email address' do
it 'logs analytics event' do
stub_analytics

response

expect(user.email_addresses.last.email).
to include('[email protected]')
expect(@analytics).to have_logged_event(
:sp_select_email_submitted,
success: true,
needs_completion_screen_reason: :new_attributes,
)
end

context 'with a corrupted email selected_email_id form' do
let(:params) { { selected_email_id: email3 } }
let(:other_user) { create(:user) }
let(:selected_email) { other_user.confirmed_email_addresses.sample }

it 'rejects email not belonging to the user' do
expect(response).to redirect_to(sign_up_select_email_path)
expect(user.email_addresses.last.email).
to include('[email protected]')
expect(controller.user_session[:selected_email_id]).to eq(nil)
end

it 'logs analytics event' do
stub_analytics

response

expect(@analytics).to have_logged_event(
:sp_select_email_submitted,
success: false,
error_details: { selected_email_id: { not_found: true } },
needs_completion_screen_reason: :new_attributes,
)
end
end

Expand Down