Skip to content

Commit

Permalink
[Automated] Merged master into target k8s
Browse files Browse the repository at this point in the history
  • Loading branch information
va-vsp-bot authored Apr 10, 2024
2 parents 6a29db9 + 91793bb commit c1531d4
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ def target_veteran_is_current_user?
# @param poa_code [String] poa code to match to @current_user
#
# @return [Boolean] True if valid poa code, False if not
def valid_poa_code_for_current_user?(poa_code)
def valid_poa_code_for_current_user?(poa_code) # rubocop:disable Metrics/MethodLength
reps = ::Veteran::Service::Representative.all_for_user(first_name: @current_user.first_name,
last_name: @current_user.last_name)

return false if reps.blank?

if reps.count > 1
Expand All @@ -81,6 +82,12 @@ def valid_poa_code_for_current_user?(poa_code)
last_name: @current_user.last_name,
middle_initial:)

if reps.blank? || reps.count > 1
reps = ::Veteran::Service::Representative.all_for_user(first_name: @current_user.first_name,
last_name: @current_user.last_name,
poa_code:)
end

raise ::Common::Exceptions::Unauthorized, detail: 'VSO Representative Not Found' if reps.blank?
raise ::Common::Exceptions::Unauthorized, detail: 'Ambiguous VSO Representative Results' if reps.count > 1
end
Expand Down
103 changes: 103 additions & 0 deletions modules/claims_api/spec/concerns/claims_api/poa_verification_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# frozen_string_literal: true

require 'rails_helper'

class FakeController < ApplicationController
include ClaimsApi::PoaVerification

def initialize
super
@current_user = ClaimsApi::ClaimsUser.new('test')
@current_user.first_name_last_name('John', 'Doe')
@current_user.middle_name = 'Alexander'
end
end

describe FakeController do
context 'validating poa_code for current_user' do
let(:poa_code) { '091' }
let(:first_name) { 'John' }
let(:last_name) { 'Doe' }
let(:phone) { '123-456-7890' }

context 'when no rep is found' do
it 'returns false' do
ret = subject.valid_poa_code_for_current_user?(poa_code)
expect(ret).to eq(false)
end
end

context 'when a single match is found by first/last name' do
context 'when the poa_code matches' do
before do
create(:representative, representative_id: '12345', first_name:, last_name:,
poa_codes: [poa_code], phone:)
end

it 'returns true' do
ret = subject.valid_poa_code_for_current_user?(poa_code)
expect(ret).to eq(true)
end
end

context 'when the poa_code does not match' do
before do
create(:representative, representative_id: '12345', first_name:, last_name:,
poa_codes: ['ABC'], phone:)
end

it 'returns false' do
ret = subject.valid_poa_code_for_current_user?(poa_code)
expect(ret).to eq(false)
end
end
end

context 'when multiple matches are found by first/last name' do
before do
create(:representative, representative_id: '12345', first_name:, last_name:,
middle_initial: 'A', poa_codes: ['091'], phone:)
create(:representative, representative_id: '123456', first_name:, last_name:,
middle_initial: 'B', poa_codes: ['091'], phone:)
end

it 'searches with middle name' do
res = subject.valid_poa_code_for_current_user?(poa_code)
expect(res).to eq(true)
end
end

context 'when multiple matches are found by first/last/middle name' do
context 'when a single rep is found' do
before do
create(:representative, representative_id: '12345', first_name:, last_name:,
middle_initial: 'A', poa_codes: ['ABC'], phone:)
create(:representative, representative_id: '123456', first_name:, last_name:,
middle_initial: 'B', poa_codes: ['DEF'], phone:)
create(:representative, representative_id: '1234567', first_name:, last_name:,
middle_initial: 'A', poa_codes: ['091'], phone:)
end

it 'returns true' do
res = subject.valid_poa_code_for_current_user?(poa_code)
expect(res).to eq(true)
end
end

context 'when multiple reps are found' do
before do
create(:representative, representative_id: '12345', first_name:, last_name:,
middle_initial: 'A', poa_codes: ['091'], phone:)
create(:representative, representative_id: '123456', first_name:, last_name:,
middle_initial: 'B', poa_codes: ['091'], phone:)
create(:representative, representative_id: '1234567', first_name:, last_name:,
middle_initial: 'A', poa_codes: ['091'], phone:)
end

it 'raises "Ambiguous VSO Representative Results"' do
expect { subject.valid_poa_code_for_current_user?(poa_code) }.to raise_error(Common::Exceptions::Unauthorized)
end
end
end
end
end

0 comments on commit c1531d4

Please sign in to comment.