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 42322 extract org web service bean from local bgs #19796

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
4c221bd
Add OrgWebService
mchristiansonVA Dec 5, 2024
5a52488
Merge remote-tracking branch 'origin/master' into API-42322-Extract-O…
mchristiansonVA Dec 6, 2024
ff34c4b
Merge remote-tracking branch 'origin/master' into API-42322-Extract-O…
mchristiansonVA Dec 9, 2024
e4e22c2
Merge remote-tracking branch 'origin/master' into API-42322-Extract-O…
mchristiansonVA Dec 9, 2024
f1aa665
Initial commit, WIP
mchristiansonVA Dec 9, 2024
fe35be6
Add requires to resolve NameError
mchristiansonVA Dec 9, 2024
56ac76a
Remove byebug
mchristiansonVA Dec 9, 2024
a479352
Merge remote-tracking branch 'origin/master' into API-42322-Extract-O…
mchristiansonVA Dec 10, 2024
fe4dcb4
Update definitions and related spec
mchristiansonVA Dec 10, 2024
229218f
Remove find_by_ssn
mchristiansonVA Dec 10, 2024
66f4345
Rubocop adjustment
mchristiansonVA Dec 10, 2024
dd784a9
Remove commented code
mchristiansonVA Dec 10, 2024
13ba2af
Merge w/ master, resolve conflicts
mchristiansonVA Dec 10, 2024
97c5f8a
Revert change to ClaimantService method
mchristiansonVA Dec 11, 2024
3a1e4fb
Merge remote-tracking branch 'origin/master' into API-42322-Extract-O…
mchristiansonVA Dec 11, 2024
915a8d7
Merge branch 'master' into API-42322-Extract-OrgWebServiceBean-from-l…
mchristiansonVA Dec 11, 2024
b4ed3c4
Add back local_bgs_service for Claimant call
mchristiansonVA Dec 12, 2024
f8672ab
Merge remote-tracking branch 'origin/master' into API-42322-Extract-O…
mchristiansonVA Dec 12, 2024
36f0d7d
Merge w/ master
mchristiansonVA Dec 16, 2024
fa663a7
Reverts definitions file changes to skip WSDL calls
mchristiansonVA Dec 16, 2024
4735c99
Merge branch 'master' into API-42322-Extract-OrgWebServiceBean-from-l…
mchristiansonVA Dec 17, 2024
a478138
Merge remote-tracking branch 'origin/master' into API-42322-Extract-O…
mchristiansonVA Dec 19, 2024
bedb3bb
Use method instead of hardcoded text
mchristiansonVA Dec 20, 2024
509dd31
Merge branch 'master' into API-42322-Extract-OrgWebServiceBean-from-l…
mchristiansonVA Jan 2, 2025
3245b08
Merge branch 'master' into API-42322-Extract-OrgWebServiceBean-from-l…
mchristiansonVA Jan 3, 2025
3206358
Merge branch 'master' into API-42322-Extract-OrgWebServiceBean-from-l…
mchristiansonVA Jan 6, 2025
ffa2ba5
Merge branch 'master' into API-42322-Extract-OrgWebServiceBean-from-l…
mchristiansonVA Jan 6, 2025
b2c0130
Merge w/ master, resolve conflicts
mchristiansonVA Jan 7, 2025
f231368
Fix test for org web service
mchristiansonVA Jan 7, 2025
9914ee0
Merge branch 'master' into API-42322-Extract-OrgWebServiceBean-from-l…
mchristiansonVA Jan 7, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ module IntentToFileWebService
##
# OrgWebServiceBean
#
module OrgWebService
module OrgWebServiceBean
DEFINITION =
Bean.new(
path: 'OrgWebServiceBean',
Expand All @@ -155,6 +155,14 @@ module OrgWebService
)
end

module OrgWebService
DEFINITION =
Service.new(
bean: OrgWebServiceBean::DEFINITION,
path: 'OrgWebService'
)
end

##
# PersonWebServiceBean
#
Expand Down
13 changes: 0 additions & 13 deletions modules/claims_api/lib/bgs_service/local_bgs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,6 @@ def find_poa_by_participant_id(id)
key: 'return')
end

def find_poa_history_by_ptcpnt_id(id)
body = Nokogiri::XML::DocumentFragment.parse <<~EOXML
<ptcpntId />
EOXML

{ ptcpntId: id }.each do |k, v|
body.xpath("./*[local-name()='#{k}']")[0].content = v
end

make_request(endpoint: 'OrgWebServiceBean/OrgWebService', action: 'findPoaHistoryByPtcpntId', body:,
key: 'PoaHistory')
end

def header # rubocop:disable Metrics/MethodLength
# Stock XML structure {{{
header = Nokogiri::XML::DocumentFragment.parse <<~EOXML
Expand Down
22 changes: 22 additions & 0 deletions modules/claims_api/lib/bgs_service/org_web_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

module ClaimsApi
class OrgWebService < ClaimsApi::LocalBGS
def bean_name
'OrgWebServiceBean/OrgWebService'
end

def find_poa_history_by_ptcpnt_id(id)
body = Nokogiri::XML::DocumentFragment.parse <<~EOXML
<ptcpntId />
EOXML

{ ptcpntId: id }.each do |k, v|
body.xpath("./*[local-name()='#{k}']")[0].content = v
end

make_request(endpoint: bean_name, action: 'findPoaHistoryByPtcpntId', body:,
key: 'PoaHistory')
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
expected_instance_methods = {
convert_nil_values: %i[options],
find_poa_by_participant_id: %i[id],
find_poa_history_by_ptcpnt_id: %i[id],
healthcheck: %i[endpoint],
jrn: %i[],
make_request: [endpoint: nil, action: nil, body: nil],
Expand Down
9 changes: 5 additions & 4 deletions modules/claims_api/spec/models/veteran/service/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
end

let(:ows) { ClaimsApi::LocalBGS }
let(:org_web_service) { ClaimsApi::OrgWebService }

it 'initializes from a user' do
VCR.use_cassette('claims_api/bgs/claimant_web_service/find_poa_by_participant_id') do
allow_any_instance_of(ows).to receive(:find_poa_history_by_ptcpnt_id)
allow_any_instance_of(org_web_service).to receive(:find_poa_history_by_ptcpnt_id)
.and_return({ person_poa_history: { person_poa: [{ begin_dt: Time.zone.now, legacy_poa_cd: '033' }] } })
veteran = Veteran::User.new(user)
expect(veteran.power_of_attorney.code).to eq('074')
Expand All @@ -29,7 +30,7 @@

it 'does not bomb out if poa is missing' do
VCR.use_cassette('claims_api/bgs/claimant_web_service/not_find_poa_by_participant_id') do
allow_any_instance_of(ows).to receive(:find_poa_history_by_ptcpnt_id)
allow_any_instance_of(org_web_service).to receive(:find_poa_history_by_ptcpnt_id)
.and_return({ person_poa_history: nil })
veteran = Veteran::User.new(user)
expect(veteran.power_of_attorney).to eq(nil)
Expand All @@ -39,7 +40,7 @@

it 'provides most recent previous poa' do
VCR.use_cassette('claims_api/bgs/claimant_web_service/find_poa_by_participant_id') do
allow_any_instance_of(ows).to receive(:find_poa_history_by_ptcpnt_id)
allow_any_instance_of(org_web_service).to receive(:find_poa_history_by_ptcpnt_id)
.and_return({
person_poa_history: {
person_poa: [
Expand All @@ -56,7 +57,7 @@

it 'does not bomb out if poa history contains a single record' do
VCR.use_cassette('claims_api/bgs/claimant_web_service/find_poa_by_participant_id') do
allow_any_instance_of(ows).to receive(:find_poa_history_by_ptcpnt_id)
allow_any_instance_of(org_web_service).to receive(:find_poa_history_by_ptcpnt_id)
.and_return({ person_poa_history: { person_poa: { begin_dt: Time.zone.now, legacy_poa_cd: '033' } } })
veteran = Veteran::User.new(user)
expect(veteran.power_of_attorney.code).to eq('074')
Expand Down
4 changes: 0 additions & 4 deletions modules/claims_api/spec/requests/metadata_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,6 @@
end

it 'returns the correct status when bgs org service is not healthy' do
allow_any_instance_of(ClaimsApi::LocalBGS).to receive(
:find_poa_history_by_ptcpnt_id
)
.and_return(Struct.new(:healthy?).new(false))
get "/services/claims/#{version}/upstream_healthcheck"
result = JSON.parse(response.body)
expect(result['org_web_service']['success']).to eq(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require_relative '../../../../rails_helper'
require 'token_validation/v2/client'
require 'bgs_service/local_bgs'
require 'bgs_service/org_web_service'

RSpec.describe 'ClaimsApi::V1::PowerOfAttorney::2122', type: :request do
let(:veteran_id) { '1013062086V794840' }
Expand All @@ -14,6 +15,7 @@
let(:organization_poa_code) { '083' }
let(:bgs_poa) { { person_org_name: "#{individual_poa_code} name-here" } }
let(:local_bgs) { ClaimsApi::LocalBGS }
let(:org_web_service) { ClaimsApi::OrgWebService }

describe 'PowerOfAttorney' do
before do
Expand Down Expand Up @@ -55,7 +57,7 @@
mock_ccg(scopes) do |auth_header|
expect_any_instance_of(local_bgs).to receive(:find_poa_by_participant_id)
.and_return(bgs_poa)
allow_any_instance_of(local_bgs).to receive(:find_poa_history_by_ptcpnt_id)
allow_any_instance_of(org_web_service).to receive(:find_poa_history_by_ptcpnt_id)
.and_return({ person_poa_history: nil })

post appoint_organization_path, params: data.to_json, headers: auth_header
Expand Down Expand Up @@ -86,7 +88,7 @@
it 'returns a 422 when no zipCode is included in the veteran data' do
VCR.use_cassette('claims_api/mpi/find_candidate/valid_icn_full') do
mock_ccg(scopes) do |auth_header|
allow_any_instance_of(local_bgs).to receive(:find_poa_history_by_ptcpnt_id)
allow_any_instance_of(org_web_service).to receive(:find_poa_history_by_ptcpnt_id)
.and_return({ person_poa_history: nil })

json = JSON.parse(request_body)
Expand All @@ -112,7 +114,7 @@
mock_ccg(scopes) do |auth_header|
expect_any_instance_of(local_bgs).to receive(:find_poa_by_participant_id)
.and_return(bgs_poa)
allow_any_instance_of(local_bgs).to receive(:find_poa_history_by_ptcpnt_id)
allow_any_instance_of(org_web_service).to receive(:find_poa_history_by_ptcpnt_id)
.and_return({ person_poa_history: nil })

json = JSON.parse(request_body)
Expand Down Expand Up @@ -284,7 +286,7 @@
mock_ccg(scopes) do |auth_header|
expect_any_instance_of(local_bgs).to receive(:find_poa_by_participant_id)
.and_return(bgs_poa)
allow_any_instance_of(local_bgs).to receive(:find_poa_history_by_ptcpnt_id)
allow_any_instance_of(org_web_service).to receive(:find_poa_history_by_ptcpnt_id)
.and_return({ person_poa_history: nil })
allow_any_instance_of(ClaimsApi::V2::ApplicationController)
.to receive(:target_veteran).and_return(no_first_name_target_veteran)
Expand Down Expand Up @@ -316,7 +318,7 @@

it 'returns a 422' do
mock_ccg(scopes) do |auth_header|
allow_any_instance_of(local_bgs).to receive(:find_poa_history_by_ptcpnt_id)
allow_any_instance_of(org_web_service).to receive(:find_poa_history_by_ptcpnt_id)
.and_return({ person_poa_history: nil })
allow_any_instance_of(ClaimsApi::V2::ApplicationController)
.to receive(:target_veteran).and_return(no_first_last_name_target_veteran)
Expand Down Expand Up @@ -356,7 +358,7 @@
it 'returns a 422 with no zipCode' do
VCR.use_cassette('claims_api/mpi/find_candidate/valid_icn_full') do
mock_ccg(scopes) do |auth_header|
allow_any_instance_of(local_bgs).to receive(:find_poa_history_by_ptcpnt_id)
allow_any_instance_of(org_web_service).to receive(:find_poa_history_by_ptcpnt_id)
.and_return({ person_poa_history: nil })

json = JSON.parse(request_body)
Expand Down Expand Up @@ -395,7 +397,7 @@
mock_ccg(scopes) do |auth_header|
expect_any_instance_of(local_bgs).to receive(:find_poa_by_participant_id)
.and_return(bgs_poa)
allow_any_instance_of(local_bgs).to receive(:find_poa_history_by_ptcpnt_id)
allow_any_instance_of(org_web_service).to receive(:find_poa_history_by_ptcpnt_id)
.and_return({ person_poa_history: nil })

json = JSON.parse(request_body)
Expand All @@ -418,7 +420,7 @@
mock_ccg(scopes) do |auth_header|
expect_any_instance_of(local_bgs).to receive(:find_poa_by_participant_id)
.and_return(bgs_poa)
allow_any_instance_of(local_bgs).to receive(:find_poa_history_by_ptcpnt_id)
allow_any_instance_of(org_web_service).to receive(:find_poa_history_by_ptcpnt_id)
.and_return({ person_poa_history: nil })

post appoint_organization_path, params: data.to_json, headers: auth_header
Expand All @@ -432,7 +434,7 @@
mock_ccg(scopes) do |auth_header|
expect_any_instance_of(local_bgs).to receive(:find_poa_by_participant_id)
.and_return(bgs_poa)
allow_any_instance_of(local_bgs).to receive(:find_poa_history_by_ptcpnt_id)
allow_any_instance_of(org_web_service).to receive(:find_poa_history_by_ptcpnt_id)
.and_return({ person_poa_history: nil })

post appoint_organization_path, params: data.to_json, headers: auth_header
Expand Down Expand Up @@ -490,7 +492,7 @@
mock_ccg_for_fine_grained_scope(poa_scopes) do |auth_header|
expect_any_instance_of(local_bgs).to receive(:find_poa_by_participant_id)
.and_return(bgs_poa)
allow_any_instance_of(local_bgs).to receive(:find_poa_history_by_ptcpnt_id)
allow_any_instance_of(org_web_service).to receive(:find_poa_history_by_ptcpnt_id)
.and_return({ person_poa_history: nil })

post appoint_organization_path, params: data.to_json, headers: auth_header
Expand Down Expand Up @@ -519,7 +521,7 @@
mock_ccg(scopes) do |auth_header|
expect_any_instance_of(local_bgs).to receive(:find_poa_by_participant_id)
.and_return(bgs_poa)
allow_any_instance_of(local_bgs).to receive(:find_poa_history_by_ptcpnt_id)
allow_any_instance_of(org_web_service).to receive(:find_poa_history_by_ptcpnt_id)
.and_return({ person_poa_history: nil })
expect(ClaimsApi::V2::PoaFormBuilderJob).to receive(:perform_async) do |*args|
expect(args[2]).to eq(rep_id)
Expand Down Expand Up @@ -605,7 +607,7 @@

it 'returns an error response' do
mock_ccg(scopes) do |auth_header|
allow_any_instance_of(local_bgs).to receive(:find_poa_history_by_ptcpnt_id)
allow_any_instance_of(org_web_service).to receive(:find_poa_history_by_ptcpnt_id)
.and_return({ person_poa_history: nil })
allow_any_instance_of(ClaimsApi::V2::ApplicationController)
.to receive(:target_veteran).and_return(no_first_last_name_target_veteran)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require_relative '../../../../rails_helper'
require 'token_validation/v2/client'
require 'bgs_service/local_bgs'
require 'bgs_service/org_web_service'

RSpec.describe 'ClaimsApi::V2::PowerOfAttorney::2122a', type: :request do
let(:veteran_id) { '1013062086V794840' }
Expand All @@ -14,6 +15,7 @@
let(:organization_poa_code) { '067' }
let(:bgs_poa) { { person_org_name: "#{individual_poa_code} name-here" } }
let(:local_bgs) { ClaimsApi::LocalBGS }
let(:org_web_service) { ClaimsApi::OrgWebService }

describe 'PowerOfAttorney' do
before do
Expand Down Expand Up @@ -113,7 +115,7 @@
mock_ccg(scopes) do |auth_header|
expect_any_instance_of(local_bgs).to receive(:find_poa_by_participant_id)
.and_return(bgs_poa)
allow_any_instance_of(local_bgs).to receive(:find_poa_history_by_ptcpnt_id)
allow_any_instance_of(org_web_service).to receive(:find_poa_history_by_ptcpnt_id)
.and_return({ person_poa_history: nil })

post appoint_individual_path, params: data.to_json, headers: auth_header
Expand Down Expand Up @@ -312,7 +314,7 @@
claimant_data[:data][:attributes][:representative][:address][:zipCode] = ''
claimant_data[:data][:attributes][:representative][:address][:countryCode] = 'AL'
allow_any_instance_of(local_bgs).to receive(:find_poa_by_participant_id).and_return(bgs_poa)
allow_any_instance_of(local_bgs)
allow_any_instance_of(org_web_service)
.to receive(:find_poa_history_by_ptcpnt_id).and_return({ person_poa_history: nil })
VCR.use_cassette('claims_api/mpi/find_candidate/valid_icn_full') do
post appoint_individual_path, params: claimant_data.to_json, headers: auth_header
Expand All @@ -327,7 +329,7 @@
shared_context 'claimant data setup' do
before do
allow_any_instance_of(local_bgs).to receive(:find_poa_by_participant_id).and_return(bgs_poa)
allow_any_instance_of(local_bgs)
allow_any_instance_of(org_web_service)
.to receive(:find_poa_history_by_ptcpnt_id).and_return({ person_poa_history: nil })
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
require_relative '../../../rails_helper'
require_relative '../../../support/swagger_shared_components/v2'
require 'bgs_service/local_bgs'
require 'bgs_service/org_web_service'

describe 'PowerOfAttorney',
openapi_spec: Rswag::TextHelpers.new.claims_api_docs do
let(:local_bgs) { ClaimsApi::LocalBGS }
let(:org_web_service) { ClaimsApi::OrgWebService }

claimant_data = {
'claimantId' => '1013093331V548481',
Expand Down Expand Up @@ -61,7 +63,7 @@

before do |example|
expect_any_instance_of(local_bgs).to receive(:find_poa_by_participant_id).and_return(bgs_poa)
allow_any_instance_of(local_bgs).to receive(:find_poa_history_by_ptcpnt_id)
allow_any_instance_of(org_web_service).to receive(:find_poa_history_by_ptcpnt_id)
.and_return({ person_poa_history: nil })
FactoryBot.create(:veteran_representative, representative_id: '12345',
poa_codes: [poa_code],
Expand Down Expand Up @@ -119,7 +121,7 @@

before do |example|
expect_any_instance_of(local_bgs).to receive(:find_poa_by_participant_id).and_return(bgs_poa)
allow_any_instance_of(local_bgs).to receive(:find_poa_history_by_ptcpnt_id)
allow_any_instance_of(org_web_service).to receive(:find_poa_history_by_ptcpnt_id)
.and_return({ person_poa_history: nil })

FactoryBot.create(:veteran_representative, representative_id: '12345',
Expand Down Expand Up @@ -153,7 +155,7 @@

before do |example|
expect_any_instance_of(local_bgs).to receive(:find_poa_by_participant_id).and_return(bgs_poa)
allow_any_instance_of(local_bgs).to receive(:find_poa_history_by_ptcpnt_id)
allow_any_instance_of(org_web_service).to receive(:find_poa_history_by_ptcpnt_id)
.and_return({ person_poa_history: nil })
FactoryBot.create(:veteran_representative, representative_id: '12345',
poa_codes: [poa_code],
Expand Down Expand Up @@ -262,7 +264,7 @@

before do |example|
expect_any_instance_of(local_bgs).to receive(:find_poa_by_participant_id).and_return(bgs_poa)
allow_any_instance_of(local_bgs).to receive(:find_poa_history_by_ptcpnt_id)
allow_any_instance_of(org_web_service).to receive(:find_poa_history_by_ptcpnt_id)
.and_return({ person_poa_history: nil })
FactoryBot.create(:veteran_representative, representative_id: '999999999999',
poa_codes: [poa_code],
Expand Down Expand Up @@ -459,7 +461,7 @@

before do |example|
expect_any_instance_of(local_bgs).to receive(:find_poa_by_participant_id).and_return(bgs_poa)
allow_any_instance_of(local_bgs).to receive(:find_poa_history_by_ptcpnt_id)
allow_any_instance_of(org_web_service).to receive(:find_poa_history_by_ptcpnt_id)
.and_return({ person_poa_history: nil })
FactoryBot.create(:veteran_organization, poa: organization_poa_code,
name: "#{organization_poa_code} - DISABLED AMERICAN VETERANS",
Expand Down Expand Up @@ -528,7 +530,7 @@

before do |example|
mock_ccg(scopes) do
allow_any_instance_of(local_bgs).to receive(:find_poa_history_by_ptcpnt_id)
allow_any_instance_of(org_web_service).to receive(:find_poa_history_by_ptcpnt_id)
.and_return({ person_poa_history: nil })
submit_request(example.metadata)
end
Expand Down
7 changes: 4 additions & 3 deletions modules/veteran/app/models/veteran/user.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require 'bgs_service/local_bgs'
require 'bgs_service/org_web_service'

# Veteran model
module Veteran
Expand Down Expand Up @@ -32,7 +33,7 @@ def current_poa_information
def previous_poa_code
return @previous_poa_code if @previous_poa_code.present?

poa_history = local_bgs_service.find_poa_history_by_ptcpnt_id(@user.participant_id)
poa_history = bgs_org_service.find_poa_history_by_ptcpnt_id(@user.participant_id)
return nil if poa_history[:person_poa_history].blank?

# Sorts previous power of attorneys by begin date
Expand All @@ -44,9 +45,9 @@ def previous_poa_code
@previous_poa_code = poa_codes.delete_if { |poa_code| poa_code == current_poa_code }.first
end

def bgs_service
def bgs_org_service
external_key = "#{@user.first_name} #{@user.last_name}"
@bgs_service ||= BGS::Services.new(
@bgs_itf_service ||= ClaimsApi::OrgWebService.new(
external_uid: @user.mpi_icn,
external_key: external_key.presence || @user.mpi_icn
)
Expand Down
Loading
Loading