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 @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -4575,167 +4575,56 @@ def update_json_and_submit(updated_json_lambda)
end
end
end
end

rockwellwindsor-va marked this conversation as resolved.
Show resolved Hide resolved
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
Copy link
Contributor

Choose a reason for hiding this comment

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

@acovrig I don't see a replacement for the minimum validations spec, nor do I see a dup in the whole file, I am curious as why you think we don't need this test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It got renamed, sorry for the confusion

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 'POST #generate_pdf' do
let(:veteran_id) { '1012832025V743496' }
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)
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 '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)
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
end
Expand Down Expand Up @@ -4764,25 +4653,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
Loading