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

API-41234-rep-validation-include-suffix #19017

Merged
merged 12 commits into from
Oct 24, 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
32 changes: 28 additions & 4 deletions modules/veteran/app/models/veteran/service/representative.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ class Representative < ApplicationRecord
def self.all_for_user(first_name:, last_name:, middle_initial: nil, poa_code: nil)
return [] if first_name.nil? || last_name.nil?

representatives = where('lower(first_name) = ? AND lower(last_name) = ?', first_name&.downcase,
last_name&.downcase)
representatives = representatives.where('? = ANY(poa_codes)', poa_code) if poa_code
representatives.select { |rep| matching_middle_initial(rep, middle_initial) }
representatives = get_representatives(first_name, last_name)

representatives = representatives&.where('? = ANY(poa_codes)', poa_code) if poa_code

representatives&.select { |rep| matching_middle_initial(rep, middle_initial) }
end

#
Expand Down Expand Up @@ -111,6 +112,29 @@ def diff(rep_data)
end
end

def self.get_suffixes(first_name, last_name)
first_suffix = first_name.split.last if first_name.split.count > 1
last_suffix = last_name.split.last if last_name.split.count > 1
[first_suffix, last_suffix]
end

def self.get_representatives(first_name, last_name)
suffixes = get_suffixes(first_name, last_name)

representatives = where('lower(first_name) = ? AND lower(last_name) = ?', first_name&.downcase,
last_name&.downcase)

if representatives.blank? && suffixes.any?
# check without suffix
first_name = first_name.delete(suffixes[0]).strip if suffixes[0].present?
last_name = last_name.delete(suffixes[1]).strip if suffixes[1].present?

stiehlrod marked this conversation as resolved.
Show resolved Hide resolved
representatives = where('lower(first_name) = ? AND lower(last_name) = ?', first_name&.downcase,
last_name&.downcase)
end
representatives
end

private

#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,22 @@ def basic_attributes
poa_code: '016'
)).to eq([])
end

it 'can find a user with a suffix' do
expect(Veteran::Service::Representative.all_for_user(
first_name: identity.first_name,
last_name: "#{identity.last_name} III",
poa_code: 'A1Q'
).first.poa_codes).to include('A1Q')
end

it 'can find a user with a suffix on the first name' do
expect(Veteran::Service::Representative.all_for_user(
first_name: "#{identity.first_name} Esq",
last_name: identity.last_name,
poa_code: 'A1Q'
).first.poa_codes).to include('A1Q')
end
end
end

Expand Down
Loading