Skip to content

Commit

Permalink
[DPC-4229] Removed given name and phone matching on cd invite (#2285)
Browse files Browse the repository at this point in the history
## 🎫 Ticket

https://jira.cms.gov/browse/DPC-4229

## 🛠 Changes

In the CD invitation flow we no longer match on given name and phone
number.

## ℹ️ Context

These changes were made in an attempt to streamline the CD invitation
process.

## 🧪 Validation

Tests updated to verify that first name and phone number are no longer
required to match.

**Note**: We still require that the invitation has a given name and
phone number, we just don't match on them.
  • Loading branch information
MEspositoE14s authored Oct 9, 2024
1 parent f720795 commit 73a09f5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 50 deletions.
20 changes: 1 addition & 19 deletions dpc-portal/app/models/invitation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,7 @@ def expires_in

def cd_match?(user_info)
cd_info_present?(user_info)

return false unless invited_given_name.downcase == user_info['given_name'].downcase &&
invited_family_name.downcase == user_info['family_name'].downcase

phone_match(user_info)
invited_family_name.downcase == user_info['family_name'].downcase
end

def email_match?(user_info)
Expand All @@ -135,20 +131,6 @@ def check_missing_user_info(user_info, key)
raise UserInfoServiceError, 'missing_info'
end

# rubocop:disable Metrics/AbcSize
# Go ahead and pass if one or the other starts with US country code (1)
def phone_match(user_info)
user_phone = user_info['phone'].tr('^0-9', '')
if user_phone.length == invited_phone.length
user_phone == invited_phone
elsif user_phone.length > invited_phone.length && user_phone[0] == '1'
user_phone[1..] == invited_phone
elsif user_phone.length < invited_phone.length && invited_phone[0] == '1'
user_phone == invited_phone[1..]
end
end
# rubocop:enable Metrics/AbcSize

def cannot_cancel_accepted
return unless status_was == 'accepted' && cancelled?

Expand Down
27 changes: 9 additions & 18 deletions dpc-portal/spec/models/invitation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,32 +185,27 @@
'family_name' => 'Hodges',
'phone' => '+111-111-1111' }
end
it 'should match user if names, email, and phone correct' do
it 'should match user if last name and email correct' do
expect(cd_invite.cd_match?(user_info)).to eq true
expect(cd_invite.email_match?(user_info)).to eq true
end
it 'should match user if names and email different case' do
cd_invite.invited_given_name.upcase!
cd_invite.invited_family_name.downcase!
cd_invite.invited_email = cd_invite.invited_email.upcase_first
expect(cd_invite.cd_match?(user_info)).to eq true
expect(cd_invite.email_match?(user_info)).to eq true
end
it 'should match if invited email eq email' do
cd_invite.invited_email = user_info['email']
expect(cd_invite.email_match?(user_info)).to eq true
end
it 'should match if user info phone starts with 1' do
plus_phone = user_info.merge('phone' => '+1-111-111-1111')
expect(cd_invite.cd_match?(plus_phone)).to eq true
it 'should match user if given name different' do
cd_invite.invited_given_name = 'fake'
expect(cd_invite.cd_match?(user_info)).to eq true
end
it 'should match if invited phone starts with 1' do
cd_invite.phone_raw = '+1-111-111-1111'
it 'should match user if phone different' do
cd_invite.invited_phone = '11234567890'
expect(cd_invite.cd_match?(user_info)).to eq true
end
it 'should not match user if given name not correct' do
cd_invite.invited_given_name = "not #{cd_invite.invited_given_name}"
expect(cd_invite.cd_match?(user_info)).to eq false
it 'should match if invited email eq email' do
cd_invite.invited_email = user_info['email']
expect(cd_invite.email_match?(user_info)).to eq true
end
it 'should not match user if family name not correct' do
cd_invite.invited_family_name = "not #{cd_invite.invited_family_name}"
Expand All @@ -220,10 +215,6 @@
cd_invite.invited_email = "not #{cd_invite.invited_email}"
expect(cd_invite.email_match?(user_info)).to eq false
end
it 'should not match user if phone not correct' do
cd_invite.invited_phone = 'not number'
expect(cd_invite.cd_match?(user_info)).to eq false
end
it 'should raise error if user_info missing given name' do
missing_info = user_info.merge({ 'given_name' => '' })
expect do
Expand Down
21 changes: 8 additions & 13 deletions dpc-portal/spec/requests/invitations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -521,15 +521,22 @@
before { post "/organizations/#{org.id}/invitations/#{cd_invite.id}/verify_code", params: success_params }

context :success do
before { stub_user_info }
it 'should show register' do
stub_user_info
get "/organizations/#{org.id}/invitations/#{cd_invite.id}/confirm_cd"
expect(response.body).to include(register_organization_invitation_path(org, cd_invite))
end
it 'should set verification complete' do
stub_user_info
get "/organizations/#{org.id}/invitations/#{cd_invite.id}/confirm_cd"
expect(request.session["invitation_status_#{cd_invite.id}"]).to eq 'verification_complete'
end
it 'should ignore given name and phone' do
stub_user_info(overrides: { 'given_name' => 'Something Else', 'phone' => '9999999999' })
get "/organizations/#{org.id}/invitations/#{cd_invite.id}/confirm_cd"
expect(response.body).to include(register_organization_invitation_path(org, cd_invite))
expect(request.session["invitation_status_#{cd_invite.id}"]).to eq 'verification_complete'
end
end
context :failure do
it 'should render error page if email not match' do
Expand All @@ -539,24 +546,12 @@
expect(response.body).to include(CGI.escapeHTML(I18n.t('verification.email_mismatch_status')))
expect(response.body).to_not include(confirm_organization_invitation_path(org, cd_invite))
end
it 'should render error page if given_name not match' do
stub_user_info(overrides: { 'given_name' => 'Something Else' })
get "/organizations/#{org.id}/invitations/#{cd_invite.id}/confirm_cd"
expect(response).to be_forbidden
expect(response.body).to_not include(confirm_organization_invitation_path(org, cd_invite))
end
it 'should render error page if family_name not match' do
stub_user_info(overrides: { 'family_name' => 'Something Else' })
get "/organizations/#{org.id}/invitations/#{cd_invite.id}/confirm_cd"
expect(response).to be_forbidden
expect(response.body).to_not include(confirm_organization_invitation_path(org, cd_invite))
end
it 'should render error page if phone not match' do
stub_user_info(overrides: { 'phone' => '9999999999' })
get "/organizations/#{org.id}/invitations/#{cd_invite.id}/confirm_cd"
expect(response).to be_forbidden
expect(response.body).to_not include(confirm_organization_invitation_path(org, cd_invite))
end
it 'should not show step navigation' do
user_service_class = class_double(UserInfoService).as_stubbed_const
allow(user_service_class).to receive(:new).and_raise(UserInfoServiceError, 'server_error')
Expand Down

0 comments on commit 73a09f5

Please sign in to comment.