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

Break out PDF 526v2 test #18135

Merged
merged 13 commits into from
Sep 3, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def process_claim(auto_claim)

# Only value required by background jobs that is missing in headers is middle name
def veteran_middle_initial
@target_veteran.middle_name ? @target_veteran.middle_name[0].uppercase : ''
target_veteran.middle_name ? target_veteran.middle_name[0].upcase : ''
acovrig marked this conversation as resolved.
Show resolved Hide resolved
end

def flashes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,13 @@
context 'international address' do
it 'maps the address to overflow' do
form_attributes['veteranIdentification']['mailingAddress']['country'] = 'Afghanistan'
form_attributes['veteranIdentification']['mailingAddress']['internationalPostalCode'] = 'asdf1234'
form_attributes['veteranIdentification']['mailingAddress']['internationalPostalCode'] = '151-8557'
form_attributes['veteranIdentification']['mailingAddress']['zipFirstFive'] = nil
form_attributes['veteranIdentification']['mailingAddress']['zipLastFour'] = nil
mapper.map_claim
zip = pdf_data[:data][:attributes][:identificationInformation][:mailingAddress][:zip]

expect(zip).to eq('asdf1234')
expect(zip).to eq('151-8557')
end
end
end
Expand Down
275 changes: 76 additions & 199 deletions modules/claims_api/spec/requests/v2/veterans/526_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,12 @@
RSpec.describe 'ClaimsApi::V2::Veterans::526', type: :request do
let(:scopes) { %w[claim.write claim.read] }
let(:claim_date) { Time.find_zone!('Central Time (US & Canada)').today }
let(:no_first_name_target_veteran) do
OpenStruct.new(
icn: '1012832025V743496',
first_name: '',
last_name: 'Ford',
birth_date: '19630211',
loa: { current: 3, highest: 3 },
edipi: nil,
ssn: '796043735',
participant_id: '600061742',
mpi: OpenStruct.new(
icn: '1012832025V743496',
profile: OpenStruct.new(ssn: '796043735')
)
)
end

let(:no_last_name_target_veteran) do
let(:target_veteran) do
OpenStruct.new(
icn: '1012832025V743496',
first_name: 'Wesley',
last_name: '',
birth_date: '19630211',
loa: { current: 3, highest: 3 },
edipi: nil,
ssn: '796043735',
participant_id: '600061742',
mpi: OpenStruct.new(
icn: '1012832025V743496',
profile: OpenStruct.new(ssn: '796043735')
)
)
end

let(:no_first_last_name_target_veteran) do
OpenStruct.new(
icn: '1012832025V743496',
first_name: '',
last_name: '',
last_name: 'Ford',
middle_name: 'John',
birth_date: '19630211',
loa: { current: 3, highest: 3 },
edipi: nil,
Expand Down Expand Up @@ -148,8 +115,9 @@
context 'without the first name present' do
it 'does not allow the submit to occur' do
mock_ccg(scopes) do |auth_header|
target_veteran.first_name = ''
allow_any_instance_of(ClaimsApi::V2::ApplicationController)
.to receive(:target_veteran).and_return(no_first_name_target_veteran)
.to receive(:target_veteran).and_return(target_veteran)
post submit_path, params: data, headers: auth_header
expect(response).to have_http_status(:unprocessable_entity)
expect(response.parsed_body['errors'][0]['detail']).to eq('Missing first name')
Expand All @@ -160,8 +128,9 @@
context 'without the last name present' do
it 'does not allow the submit to occur' do
mock_ccg(scopes) do |auth_header|
target_veteran.last_name = ''
allow_any_instance_of(ClaimsApi::V2::ApplicationController)
.to receive(:target_veteran).and_return(no_last_name_target_veteran)
.to receive(:target_veteran).and_return(target_veteran)
post submit_path, params: data, headers: auth_header
expect(response).to have_http_status(:unprocessable_entity)
expect(response.parsed_body['errors'][0]['detail']).to eq('Missing last name')
Expand Down Expand Up @@ -4498,167 +4467,54 @@ def update_json_and_submit(updated_json_lambda)
end
end
end
end

describe 'POST #submit not using md5 lookup' do
let(:anticipated_separation_date) { 2.days.from_now.strftime('%Y-%m-%d') }
let(:active_duty_end_date) { 2.days.from_now.strftime('%Y-%m-%d') }
let(:data) do
temp = Rails.root.join('modules', 'claims_api', 'spec', 'fixtures', 'v2', 'veterans', 'disability_compensation',
'form_526_json_api.json').read
temp = JSON.parse(temp)
attributes = temp['data']['attributes']
attributes['serviceInformation']['federalActivation']['anticipatedSeparationDate'] = anticipated_separation_date
attributes['serviceInformation']['servicePeriods'][-1]['activeDutyEndDate'] = active_duty_end_date

temp.to_json
end
let(:schema) { Rails.root.join('modules', 'claims_api', 'config', 'schemas', 'v2', '526.json').read }
let(:veteran_id) { '1013062086V794840' }
let(:submit_path) { "/services/claims/v2/veterans/#{veteran_id}/526" }

it 'creates a new claim if duplicate submit occurs (does not use md5 lookup)' do
mock_ccg(scopes) do |auth_header|
VCR.use_cassette('claims_api/disability_comp') do
json = JSON.parse(data)
post submit_path, params: json.to_json, headers: auth_header
expect(response).to have_http_status(:accepted)
first_submit_parsed = JSON.parse(response.body)
@original_id = first_submit_parsed['data']['id']
end
end
mock_ccg(scopes) do |auth_header|
VCR.use_cassette('claims_api/disability_comp') do
json = JSON.parse(data)
post submit_path, params: json.to_json, headers: auth_header
expect(response).to have_http_status(:accepted)
duplicate_submit_parsed = JSON.parse(response.body)
duplicate_id = duplicate_submit_parsed['data']['id']
expect(@original_id).not_to eq(duplicate_id)
end
end
end
end

describe 'POST #generatePDF/minimum-validations', vcr: 'claims_api/disability_comp' do
let(:anticipated_separation_date) { 2.days.from_now.strftime('%Y-%m-%d') }
let(:active_duty_end_date) { 2.days.from_now.strftime('%Y-%m-%d') }
let(:data) do
temp = Rails.root.join('modules', 'claims_api', 'spec', 'fixtures', 'v2', 'veterans',
'disability_compensation', 'form_526_generate_pdf_json_api.json').read
temp = JSON.parse(temp)
attributes = temp['data']['attributes']
attributes['serviceInformation']['federalActivation']['anticipatedSeparationDate'] = anticipated_separation_date
attributes['serviceInformation']['servicePeriods'][-1]['activeDutyEndDate'] = active_duty_end_date

temp.to_json
end

let(:schema) { Rails.root.join('modules', 'claims_api', 'config', 'schemas', 'v2', 'generate_pdf_526.json').read }
let(:veteran_id) { '1012832025V743496' }
let(:generate_pdf_scopes) { %w[system/526-pdf.override] }
let(:invalid_scopes) { %w[claim.write claim.read] }
let(:generate_pdf_path) { "/services/claims/v2/veterans/#{veteran_id}/526/generatePDF/minimum-validations" }
let(:special_issues) { ['POW'] }

context 'submission to generatePDF' do
it 'returns a 200 response when successful' do
mock_ccg_for_fine_grained_scope(generate_pdf_scopes) do |auth_header|
post generate_pdf_path, params: data, headers: auth_header
expect(response.header['Content-Disposition']).to include('filename')
expect(response).to have_http_status(:ok)
end
end

it 'returns a 200 response when specialIssues is present for a disability' do
json = JSON.parse data
json['data']['attributes']['disabilities'][0]['specialIssues'] = special_issues
data = json.to_json
mock_ccg_for_fine_grained_scope(generate_pdf_scopes) do |auth_header|
post generate_pdf_path, params: data, headers: auth_header
expect(response).to have_http_status(:ok)
end
end

it 'returns a 401 unauthorized with incorrect scopes' do
mock_ccg_for_fine_grained_scope(invalid_scopes) do |auth_header|
post generate_pdf_path, params: data, headers: auth_header
expect(response).to have_http_status(:unauthorized)
end
end
describe '#generate_pdf' do
let(:invalid_scopes) { %w[claim.write claim.read] }
let(:generate_pdf_scopes) { %w[system/526-pdf.override] }
let(:generate_pdf_path) { "/services/claims/v2/veterans/#{veteran_id}/526/generatePDF/minimum-validations" }

context 'when invalid JSON is submitted' do
it 'returns a 422 response' do
context 'valid data' do
it 'responds with a 200' do
mock_ccg_for_fine_grained_scope(generate_pdf_scopes) do |auth_header|
post generate_pdf_path, params: {}, headers: auth_header
expect(response).to have_http_status(:unprocessable_entity)
post generate_pdf_path, params: data, headers: auth_header
expect(response.header['Content-Disposition']).to include('filename')
expect(response).to have_http_status(:ok)
end
end
end

context 'handling for missing first and last name' do
context 'without the first and last name present' do
it 'does not allow the generatePDF call to occur' do
mock_ccg_for_fine_grained_scope(generate_pdf_scopes) do |auth_header|
allow_any_instance_of(ClaimsApi::V2::ApplicationController)
.to receive(:target_veteran).and_return(no_first_last_name_target_veteran)
allow_any_instance_of(ClaimsApi::V2::Veterans::DisabilityCompensationController)
.to receive(:veteran_middle_initial).and_return('')

post generate_pdf_path, params: data, headers: auth_header
expect(response).to have_http_status(:unprocessable_entity)
expect(response.parsed_body['errors'][0]['detail']).to eq('Must have either first or last name')
end
end
end

context 'without the first name present' do
it 'allows the generatePDF call to occur' do
mock_ccg_for_fine_grained_scope(generate_pdf_scopes) do |auth_header|
allow_any_instance_of(ClaimsApi::V2::ApplicationController)
.to receive(:target_veteran).and_return(no_first_name_target_veteran)
allow_any_instance_of(ClaimsApi::V2::Veterans::DisabilityCompensationController)
.to receive(:veteran_middle_initial).and_return('')

post generate_pdf_path, params: data, headers: auth_header
expect(response).to have_http_status(:ok)
end
context 'invalid scopes' do
it 'returns a 401 unauthorized' do
mock_ccg_for_fine_grained_scope(invalid_scopes) do |auth_header|
post generate_pdf_path, params: data, headers: auth_header
expect(response).to have_http_status(:unauthorized)
end
end
end

def set_international_address(json, address_type)
address_hash = address_type.reduce(json['data']['attributes']) { |acc, key| acc[key] }
address_hash.merge!(
'addressLine1' => '1-1',
'addressLine2' => 'Yoyogi Kamizono-cho',
'addressLine3' => 'Shibuya-ku',
'city' => 'Tokyo',
'internationalPostalCode' => '151-8557',
'country' => 'Japan'
)
address_hash.delete('state')
end

context 'when the mailing address is international' do
it 'returns a 200 response' do
context 'without the first and last name present' do
it 'does not allow the generatePDF call to occur' do
mock_ccg_for_fine_grained_scope(generate_pdf_scopes) do |auth_header|
json = JSON.parse(data)
set_international_address(json, %w[veteranIdentification mailingAddress])
data = json.to_json
post(generate_pdf_path, params: data, headers: auth_header)
expect(response).to have_http_status(:ok)
target_veteran.first_name = ''
target_veteran.last_name = ''
allow_any_instance_of(ClaimsApi::V2::ApplicationController)
.to receive(:target_veteran).and_return(target_veteran)

post generate_pdf_path, params: data, headers: auth_header
expect(response).to have_http_status(:unprocessable_entity)
expect(response.parsed_body['errors'][0]['detail']).to eq('Must have either first or last name')
end
end
end

context 'when the change of address is international' do
it 'returns a 200 response' do
context 'without the first name present' do
it 'allows the generatePDF call to occur' do
mock_ccg_for_fine_grained_scope(generate_pdf_scopes) do |auth_header|
json = JSON.parse(data)
set_international_address(json, ['changeOfAddress'])
data = json.to_json
post(generate_pdf_path, params: data, headers: auth_header)
target_veteran.first_name = ''
allow_any_instance_of(ClaimsApi::V2::ApplicationController)
.to receive(:target_veteran).and_return(target_veteran)

post generate_pdf_path, params: data, headers: auth_header
expect(response).to have_http_status(:ok)
end
end
Expand Down Expand Up @@ -4687,25 +4543,44 @@ def set_international_address(json, address_type)
end
end
end
end
end

context 'when overflow text is provided' do
it 'responds with a 200' do
mock_ccg_for_fine_grained_scope(generate_pdf_scopes) do |auth_header|
post generate_pdf_path, params: data, headers: auth_header
expect(response).to have_http_status(:ok)
end
describe 'POST #submit not using md5 lookup' do
let(:anticipated_separation_date) { 2.days.from_now.strftime('%Y-%m-%d') }
let(:active_duty_end_date) { 2.days.from_now.strftime('%Y-%m-%d') }
let(:data) do
temp = Rails.root.join('modules', 'claims_api', 'spec', 'fixtures', 'v2', 'veterans', 'disability_compensation',
'form_526_json_api.json').read
temp = JSON.parse(temp)
attributes = temp['data']['attributes']
attributes['serviceInformation']['federalActivation']['anticipatedSeparationDate'] = anticipated_separation_date
attributes['serviceInformation']['servicePeriods'][-1]['activeDutyEndDate'] = active_duty_end_date

temp.to_json
end
let(:schema) { Rails.root.join('modules', 'claims_api', 'config', 'schemas', 'v2', '526.json').read }
let(:veteran_id) { '1013062086V794840' }
let(:submit_path) { "/services/claims/v2/veterans/#{veteran_id}/526" }

it 'creates a new claim if duplicate submit occurs (does not use md5 lookup)' do
mock_ccg(scopes) do |auth_header|
VCR.use_cassette('claims_api/disability_comp') do
json = JSON.parse(data)
post submit_path, params: json.to_json, headers: auth_header
expect(response).to have_http_status(:accepted)
first_submit_parsed = JSON.parse(response.body)
@original_id = first_submit_parsed['data']['id']
end
end

context 'when overflow text is not provided' do
it 'responds with a 200' do
mock_ccg_for_fine_grained_scope(generate_pdf_scopes) do |auth_header|
json = JSON.parse(data)
json['data']['attributes']['claimNotes'] = nil
data = json.to_json
post generate_pdf_path, params: data, headers: auth_header
expect(response).to have_http_status(:ok)
end
mock_ccg(scopes) do |auth_header|
VCR.use_cassette('claims_api/disability_comp') do
json = JSON.parse(data)
post submit_path, params: json.to_json, headers: auth_header
expect(response).to have_http_status(:accepted)
duplicate_submit_parsed = JSON.parse(response.body)
duplicate_id = duplicate_submit_parsed['data']['id']
expect(@original_id).not_to eq(duplicate_id)
end
end
end
Expand Down Expand Up @@ -4814,8 +4689,10 @@ def set_international_address(json, address_type)
it 'does not allow the submit to occur' do
mock_ccg_for_fine_grained_scope(synchronous_scopes) do |auth_header|
VCR.use_cassette('claims_api/disability_comp') do
target_veteran.first_name = ''
target_veteran.last_name = ''
allow_any_instance_of(ClaimsApi::V2::ApplicationController)
.to receive(:target_veteran).and_return(no_first_last_name_target_veteran)
.to receive(:target_veteran).and_return(target_veteran)
post synchronous_path, params: data, headers: auth_header
expect(response).to have_http_status(:unprocessable_entity)
expect(response.parsed_body['errors'][0]['detail']).to eq('Missing first and last name')
Expand Down
Loading