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
15 changes: 14 additions & 1 deletion app/controllers/sign_up/completions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def sign_user_out_and_instruct_to_go_back_to_mobile_app
end

def analytics_attributes(page_occurence)
{
attributes = {
ial2: sp_session[:ial2],
ialmax: sp_session[:ialmax],
service_provider_name: decorated_sp_session.sp_name,
Expand All @@ -91,6 +91,19 @@ def analytics_attributes(page_occurence)
in_account_creation_flow: user_session[:in_account_creation_flow] || false,
needs_completion_screen_reason: needs_completion_screen_reason,
}

if page_occurence.present? && DisposableDomain.disposable?(email_domain)
attributes[:disposable_email_domain] = email_domain
end

attributes
end

def email_domain
@email_domain ||= begin
email_address = current_user.email_addresses.take.email
Mail::Address.new(email_address).domain
end
end

def track_completion_event(last_page)
Expand Down
7 changes: 7 additions & 0 deletions app/models/disposable_domain.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
class DisposableDomain < ApplicationRecord
class << self
def disposable?(domain)
return false if !domain.is_a?(String) || domain.empty?

exists?(name: domain)
end
end
end
45 changes: 43 additions & 2 deletions spec/controllers/sign_up/completions_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require 'rails_helper'

RSpec.describe SignUp::CompletionsController do
let(:temporary_email) { 'name@temporary.com' }

describe '#show' do
let(:current_sp) { create(:service_provider) }

Expand All @@ -22,8 +24,10 @@
end

context 'IAL1' do
let(:user) { create(:user, :fully_registered) }
let(:user) { create(:user, :fully_registered, email: temporary_email) }

before do
DisposableDomain.create(name: 'temporary.com')
stub_sign_in(user)
subject.session[:sp] = {
issuer: current_sp.issuer,
Expand Down Expand Up @@ -255,11 +259,47 @@
patch :update
expect(response).to redirect_to account_path
end

context 'with a disposable email address' do
let(:user) { create(:user, :fully_registered, email: temporary_email) }

it 'logs disposable domain' do
DisposableDomain.create(name: 'temporary.com')
stub_sign_in(user)
subject.session[:sp] = {
ial2: false,
issuer: 'foo',
request_url: 'http://example.com',
}
subject.user_session[:in_account_creation_flow] = true

patch :update

expect(@analytics).to have_received(:track_event).with(
'User registration: complete',
ial2: false,
ialmax: nil,
service_provider_name: subject.decorated_sp_session.sp_name,
page_occurence: 'agency-page',
needs_completion_screen_reason: :new_sp,
sp_request_requested_attributes: nil,
sp_session_requested_attributes: nil,
in_account_creation_flow: true,
disposable_email_domain: 'temporary.com',
)
end
end
end

context 'IAL2' do
it 'tracks analytics' do
user = create(:user, :fully_registered, profiles: [create(:profile, :verified, :active)])
DisposableDomain.create(name: 'temporary.com')
user = create(
:user,
:fully_registered,
profiles: [create(:profile, :verified, :active)],
email: temporary_email,
)
stub_sign_in(user)
sp = create(:service_provider, issuer: 'https://awesome')
subject.session[:sp] = {
Expand All @@ -282,6 +322,7 @@
sp_request_requested_attributes: nil,
sp_session_requested_attributes: ['email'],
in_account_creation_flow: true,
disposable_email_domain: 'temporary.com',
)
end

Expand Down
31 changes: 31 additions & 0 deletions spec/models/disposable_domain_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require 'rails_helper'

RSpec.describe DisposableDomain do
let(:domain) { 'temporary.com' }

describe '.disposable?' do
before do
DisposableDomain.create(name: domain)
end

context 'when the domain exists' do
it 'returns true' do
expect(DisposableDomain.disposable?(domain)).to eq true
end
end

context 'when the domain does not exist' do
it 'returns false' do
expect(DisposableDomain.disposable?('example.com')).to eq false
end
end

context 'with bad data' do
it 'returns false' do
expect(DisposableDomain.disposable?('')).to eq false
expect(DisposableDomain.disposable?(nil)).to eq false
expect(DisposableDomain.disposable?({})).to eq false
end
end
end
end