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-39286-rename-poa-pdf #18259

Merged
merged 10 commits into from
Sep 5, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def upload
@power_of_attorney.reload

# If upload is successful, then the PoaUpater job is also called to update the code in BGS.
ClaimsApi::PoaVBMSUploadJob.perform_async(@power_of_attorney.id)
ClaimsApi::PoaVBMSUploadJob.perform_async(@power_of_attorney.id, action: 'put')

render json: ClaimsApi::PowerOfAttorneySerializer.new(@power_of_attorney)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ class PoaVBMSUploadJob < ClaimsApi::ServiceBase
# If successfully uploaded, it queues a job to update the POA code in BGS, as well.
#
# @param power_of_attorney_id [String] Unique identifier of the submitted POA
def perform(power_of_attorney_id)
def perform(power_of_attorney_id, action: 'post')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has approx 12 statements - TooManyStatements

power_of_attorney = ClaimsApi::PowerOfAttorney.find(power_of_attorney_id)
uploader = ClaimsApi::PowerOfAttorneyUploader.new(power_of_attorney_id)
uploader.retrieve_from_store!(power_of_attorney.file_data['filename'])
file_path = fetch_file_path(uploader)

if Flipper.enabled?(:lighthouse_claims_api_poa_use_bd)
benefits_doc_api.upload(claim: power_of_attorney, pdf_path: file_path, doc_type: 'L075')
benefits_doc_api.upload(claim: power_of_attorney, pdf_path: file_path, action:, doc_type: 'L075')
else
upload_to_vbms(power_of_attorney, file_path)
end
Expand Down
29 changes: 17 additions & 12 deletions modules/claims_api/lib/bd/bd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def search(claim_id, file_number)
# Upload document of mapped claim
#
# @return success or failure
def upload(claim:, pdf_path:, doc_type: 'L122', file_number: nil, original_filename: nil, # rubocop:disable Metrics/ParameterLists
def upload(claim:, pdf_path:, doc_type: 'L122', action: 'post', file_number: nil, original_filename: nil, # rubocop:disable Metrics/ParameterLists
rockwellwindsor-va marked this conversation as resolved.
Show resolved Hide resolved
rockwellwindsor-va marked this conversation as resolved.
Show resolved Hide resolved
pctpnt_vet_id: nil)
unless File.exist? pdf_path
ClaimsApi::Logger.log('benefits_documents', detail: "Error uploading doc to BD: #{pdf_path} doesn't exist,
Expand All @@ -46,7 +46,7 @@ def upload(claim:, pdf_path:, doc_type: 'L122', file_number: nil, original_filen
end

@multipart = true
body = generate_upload_body(claim:, doc_type:, pdf_path:, file_number:, original_filename:,
body = generate_upload_body(claim:, doc_type:, pdf_path:, action:, file_number:, original_filename:,
pctpnt_vet_id:)
res = client.post('documents', body)&.body

Expand Down Expand Up @@ -100,18 +100,17 @@ def get_claim_id(doc_type, claim)
#
# @return {parameters, file}
# rubocop:disable Metrics/ParameterLists
def generate_upload_body(claim:, doc_type:, pdf_path:, file_number: nil, original_filename: nil,
def generate_upload_body(claim:, doc_type:, pdf_path:, action:, file_number: nil, original_filename: nil,
rockwellwindsor-va marked this conversation as resolved.
Show resolved Hide resolved
pctpnt_vet_id: nil)
payload = {}
auth_headers = claim.auth_headers
veteran_name = compact_veteran_name(auth_headers['va_eauth_firstName'], auth_headers['va_eauth_lastName'])
birls_file_num = auth_headers['va_eauth_birlsfilenumber'] || file_number if doc_type != 'L705'
claim_id = get_claim_id(doc_type, claim)
file_name = generate_file_name(doc_type:, veteran_name:, claim_id:, original_filename:)
file_name = generate_file_name(doc_type:, veteran_name:, claim_id:, original_filename:, action:)
participant_id = pctpnt_vet_id if %w[L075 L190 L705].include?(doc_type)
system_name = 'Lighthouse' if %w[L075 L190].include?(doc_type)
tracked_item_ids = claim.tracked_items&.map(&:to_i) if claim&.has_attribute?(:tracked_items)

data = build_body(doc_type:, file_name:, participant_id:, claim_id:,
file_number: birls_file_num, system_name:, tracked_item_ids:)

Expand All @@ -123,16 +122,22 @@ def generate_upload_body(claim:, doc_type:, pdf_path:, file_number: nil, origina
end
# rubocop:enable Metrics/ParameterLists

def generate_file_name(doc_type:, veteran_name:, claim_id:, original_filename:)
def generate_file_name(doc_type:, veteran_name:, claim_id:, original_filename:, action:)
# https://confluence.devops.va.gov/display/VAExternal/Document+Types
doc_type_to_form_name = {
'L075' => '21-22a',
'L122' => '526EZ',
'L190' => '21-22',
'L705' => '5103'
doc_type_names = {
'put' => {
'L075' => 'representative',
'L190' => 'representative'
},
'post' => {
'L075' => '21-22a',
'L122' => '526EZ',
'L190' => '21-22',
'L705' => '5103'
}
}

form_name = doc_type_to_form_name[doc_type]
form_name = doc_type_names[action][doc_type]

if form_name
"#{[veteran_name, claim_id, form_name].compact_blank.join('_')}.pdf"
Expand Down
84 changes: 59 additions & 25 deletions modules/claims_api/spec/lib/claims_api/bd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
end

it 'uploads an attachment to BD for L023' do
result = subject.send(:generate_upload_body, claim:, doc_type: 'L023', pdf_path:,
result = subject.send(:generate_upload_body, claim:, doc_type: 'L023', pdf_path:, action: 'post',
original_filename: 'stuff.pdf')
js = JSON.parse(result[:parameters].read)
expect(js['data']['docType']).to eq 'L023'
Expand All @@ -42,7 +42,7 @@

it 'uploads an attachment to BD for L122' do
result = subject.send(:generate_upload_body, claim:, doc_type: 'L122', original_filename: '21-526EZ.pdf',
pdf_path:)
pdf_path:, action: 'post')
js = JSON.parse(result[:parameters].read)
expect(js['data']['docType']).to eq 'L122'
expect(js['data']['claimId']).to eq claim.evss_id
Expand Down Expand Up @@ -87,7 +87,7 @@
context 'when the doctype is L190' do
let(:pdf_path) { 'modules/claims_api/spec/fixtures/21-22/signed_filled_final.pdf' }
let(:json_body) do
res = subject.send(:generate_upload_body, claim: power_of_attorney, pdf_path:,
res = subject.send(:generate_upload_body, claim: power_of_attorney, pdf_path:, action: 'post',
doc_type: 'L190')
temp_io = res[:parameters].instance_variable_get(:@io).path
temp_io_contents = File.read(temp_io)
Expand All @@ -112,29 +112,63 @@
end

context 'when the doctype is L075' do
let(:pdf_path) { 'modules/claims_api/spec/fixtures/21-22A/signed_filled_final.pdf' }
let(:json_body) do
res = subject.send(:generate_upload_body, claim: power_of_attorney, pdf_path:,
doc_type: 'L075')
temp_io = res[:parameters].instance_variable_get(:@io).path
temp_io_contents = File.read(temp_io)
JSON.parse(temp_io_contents)
end

it 'the systemName is Lighthouse' do
expect(json_body['data']['systemName']).to eq('Lighthouse')
end

it 'the docType is L075' do
expect(json_body['data']['docType']).to eq('L075')
context 'when the api version is v2' do
let(:pdf_path) { 'modules/claims_api/spec/fixtures/21-22A/signed_filled_final.pdf' }
let(:json_body) do
res = subject.send(:generate_upload_body, claim: power_of_attorney, pdf_path:, action: 'post',
doc_type: 'L075')
temp_io = res[:parameters].instance_variable_get(:@io).path
temp_io_contents = File.read(temp_io)
JSON.parse(temp_io_contents)
end

it 'the systemName is Lighthouse' do
expect(json_body['data']['systemName']).to eq('Lighthouse')
end

it 'the docType is L075' do
expect(json_body['data']['docType']).to eq('L075')
end

it 'the fileName ends in 21-22a.pdf' do
expect(json_body['data']['fileName']).to end_with('21-22a.pdf')
end

it 'the claimId is not present' do
expect(json_body['data']).not_to have_key('claimId')
end
end

it 'the fileName ends in 21-22a.pdf' do
expect(json_body['data']['fileName']).to end_with('21-22a.pdf')
end

it 'the claimId is not present' do
expect(json_body['data']).not_to have_key('claimId')
context 'when the api version is v1' do
context 'the doc type is 21-22a' do
let(:pdf_path) { 'modules/claims_api/spec/fixtures/21-22A/signed_filled_final.pdf' }
let(:json_body) do
res = subject.send(:generate_upload_body, claim: power_of_attorney, pdf_path:, action: 'put',
doc_type: 'L075')
temp_io = res[:parameters].instance_variable_get(:@io).path
temp_io_contents = File.read(temp_io)
JSON.parse(temp_io_contents)
end

it 'the fileName ends in representative.pdf' do
expect(json_body['data']['fileName']).to end_with('_representative.pdf')
end
end

context 'the doc type is 21-22' do
let(:pdf_path) { 'modules/claims_api/spec/fixtures/21-22/signed_filled_final.pdf' }
let(:json_body) do
res = subject.send(:generate_upload_body, claim: power_of_attorney, pdf_path:, action: 'put',
doc_type: 'L190')
temp_io = res[:parameters].instance_variable_get(:@io).path
temp_io_contents = File.read(temp_io)
JSON.parse(temp_io_contents)
end

it 'the fileName ends in representative.pdf' do
expect(json_body['data']['fileName']).to end_with('_representative.pdf')
end
end
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not entirely sure this second test is needed since this scenario shouldn't happen. Wanted to include it just to be safe. If anyone feels strongly about removing it I am open to that but wanted to error on the side of playing it safe and making sure this would be handled.

end
end
end
Expand Down Expand Up @@ -162,7 +196,7 @@
describe '#generate_upload_body' do
it 'uploads an attachment to BD for L705' do
result = subject.send(:generate_upload_body, claim: ews, doc_type: 'L705', original_filename: '5103.pdf',
pdf_path:)
pdf_path:, action: 'post')
js = JSON.parse(result[:parameters].read)
expect(js['data']['docType']).to eq 'L705'
expect(js['data']['claimId']).to eq ews.claim_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@
expect_any_instance_of(ClaimsApi::BD).to receive(:upload).with(
claim: power_of_attorney,
pdf_path: anything,
doc_type: 'L075'
doc_type: 'L075',
action: 'post'
)
subject.new.perform(power_of_attorney.id)
end
Expand Down
Loading