From 6666219af8ddd9d9a87ed13ec92800eb63760008 Mon Sep 17 00:00:00 2001 From: Tyler Fink Date: Tue, 16 Apr 2024 11:28:01 -0600 Subject: [PATCH 01/28] RES Library file copied from VRE and updated --- lib/res/ch31_form.rb | 158 ++++++++++++++++++++++++++++++++++ lib/res/configuration.rb | 30 +++++++ lib/res/errors/ch31_errors.rb | 4 + lib/res/service.rb | 50 +++++++++++ 4 files changed, 242 insertions(+) create mode 100644 lib/res/ch31_form.rb create mode 100644 lib/res/configuration.rb create mode 100644 lib/res/errors/ch31_errors.rb create mode 100644 lib/res/service.rb diff --git a/lib/res/ch31_form.rb b/lib/res/ch31_form.rb new file mode 100644 index 00000000000..91f45140a05 --- /dev/null +++ b/lib/res/ch31_form.rb @@ -0,0 +1,158 @@ +# frozen_string_literal: true + +require_relative 'service' +require_relative 'errors/ch31_errors' +require 'sentry_logging' + +# Modified VRE code to new RES service +module RES + class Ch31Form < RES::Service + include SentryLogging + configuration RES::Configuration + STATSD_KEY_PREFIX = 'api.res' + SENTRY_TAG = { team: 'vfs-ebenefits' }.freeze + + def initialize(user:, claim:) + super + @user = user + @claim = claim + end + + # Submits prepared data derived from VeteranReadinessEmploymentClaim#form + # + # @return [Hash] the student's address + # + def submit + raise Ch31NilClaimError if @claim.nil? + + response = send_to_res(payload: format_payload_for_res) + response_body = response.body + + raise Ch31Error if response_body['error_occurred'] == true + + log_message_to_sentry( + 'Temp message for testing', + :warn, + { application_intake_id: response_body['application_intake'] }, + SENTRY_TAG + ) + response_body + rescue Ch31Error => e + process_ch_31_error(e, response_body) + + response_body + rescue Ch31NilClaimError => e + process_nil_claim_error(e) + end + + private + + def format_payload_for_res + form_data = claim_form_hash + + res_payload = { + useEva: form_data['useEva'], + useTelecounseling: form_data['useTelecounseling'], + appointmentTimePreferences: form_data['appointmentTimePreferences'], + yearsOfEducation: form_data['yearsOfEducation'], + isMoving: form_data['isMoving'], + mainPhone: form_data['mainPhone'], + cellNumber: form_data['cellPhone'], + # internationalNumber: form_data['internationalNumber'], + email: form_data['email'], + documentId: form_data.dig('supportingDocuments', 0, 'documentId'), # or @claim.guid + receivedDate: @claim.created_at + } + + res_payload[:data].merge!(veteran_address(form_data)) + res_payload[:data].merge!({ veteranInformation: adjusted_veteran_information }) + res_payload[:data].merge!(new_address) if form_data['newAddress'].present? + + res_payload.to_json + end + + def veteran_address(form_data) + vet_address = mapped_address_hash(form_data['veteranAddress']) + + adjusted_address = { + veteranAddress: vet_address + } + + return adjusted_address if adjusted_address.dig(:veteranAddress, :isForeign) == false + + # RES/CMSA expects different keys for postal and state for foreign addresses + # internationPostalCode misspelling is correct + international_address = adjusted_address[:veteranAddress] + international_address[:internationPostalCode] = international_address.delete(:zipCode) + international_address[:province] = international_address.delete(:stateCode) + + adjusted_address + end + + def claim_form_hash + @claim.parsed_form + end + + def adjusted_veteran_information + vet_info = claim_form_hash['veteranInformation'] + + vet_info['VAFileNumber'] = vet_info.delete('vaFileNumber') if vet_info.key?('vaFileNumber') + + vet_info + end + + def new_address + new_address = mapped_address_hash(claim_form_hash['newAddress']) + + adjusted_new_address = { + newAddress: new_address + } + + return adjusted_new_address unless new_address[:isForeign] + + # RES/CMSA expects different keys for postal and state for foreign addresses + new_address[:internationalPostalCode] = new_address.delete(:zipCode) + new_address[:province] = new_address.delete(:stateCode) + + adjusted_new_address + end + + def mapped_address_hash(client_hash) + { + # isForeign: client_hash['country'] != 'USA', + # isMilitary: client_hash['isMilitary'] || false, + country: client_hash['country'], + street: client_hash['street'], + # addressLine1: client_hash['street'], + # addressLine2: client_hash['street2'], + # addressLine3: client_hash['street3'], + city: client_hash['city'], + state: client_hash['state'], + postalCode: client_hash['postalCode'] + } + end + + def process_ch_31_error(e, response_body) + log_exception_to_sentry( + e, + { + intake_id: response_body['ApplicationIntake'], + error_message: response_body['ErrorMessage'] + }, + SENTRY_TAG + ) + end + + def process_nil_claim_error(e) + log_exception_to_sentry( + e, + { + icn: @user.icn + }, + SENTRY_TAG + ) + + { 'error_occurred' => true, 'error_message' => 'Claim cannot be null' } + end + end +end diff --git a/lib/res/configuration.rb b/lib/res/configuration.rb new file mode 100644 index 00000000000..53ecc2f2fdf --- /dev/null +++ b/lib/res/configuration.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +require 'common/client/configuration/rest' + +module RES + class Configuration < Common::Client::Configuration::REST + def connection + @conn ||= Faraday.new(base_path, headers: base_request_headers, request: request_options) do |faraday| + faraday.use :breakers + faraday.use Faraday::Response::RaiseError + faraday.response :betamocks if mock_enabled? + faraday.response :snakecase, symbolize: false + faraday.response :json, content_type: /\bjson/ + faraday.adapter Faraday.default_adapter + end + end + + def mock_enabled? + Settings.readiness_and_employment_system.mock_ch_31 || false + end + + def base_path + Settings.readiness_and_employment_system.base_url + end + + def service_name + 'ReadinessAndEmployementSystem' + end + end +end diff --git a/lib/res/errors/ch31_errors.rb b/lib/res/errors/ch31_errors.rb new file mode 100644 index 00000000000..d0bd7c792b0 --- /dev/null +++ b/lib/res/errors/ch31_errors.rb @@ -0,0 +1,4 @@ +# frozen_string_literal: true + +class Ch31Error < StandardError; end +class Ch31NilClaimError < StandardError; end diff --git a/lib/res/service.rb b/lib/res/service.rb new file mode 100644 index 00000000000..414309ffe17 --- /dev/null +++ b/lib/res/service.rb @@ -0,0 +1,50 @@ +# frozen_string_literal: true + +require 'vre/configuration' +require 'common/client/base' + +# The RES::Service class is where we keep RES related endpoint calls and common methods +module RES + class Service < Common::Client::Base + include Common::Client::Concerns::Monitoring + + # Makes call to RES and retrieves a token. Token is valid for 3 minutes so we just fire this on every api call + # + # @return [Hash] the student's address + # + def get_token + with_monitoring do + conn = Faraday.new( + Settings.readiness_and_employment_system.auth_endpoint, + headers: { 'Authorization' => "Basic #{Settings.readiness_and_employment_system.credentials}" } + ) + + request = conn.post + JSON.parse(request.body)['access_token'] + end + end + + def send_to_res(payload:) + with_monitoring do + perform( + :post, + end_point, + payload, + request_headers + ) # see lib/common/client/base.rb#L94 + end + end + + def request_headers + { + Authorization: "Bearer #{get_token}" + } + end + + private + + def end_point + "#{Settings.veteran_readiness_and_employment.base_url}/api/endpoints/vaGov/new_application" + end + end +end From 1f6d31239dae576a9ab827ad8bba4f9ace25b803 Mon Sep 17 00:00:00 2001 From: Tyler Fink Date: Wed, 17 Apr 2024 11:43:36 -0600 Subject: [PATCH 02/28] Update to use proper api access --- lib/res/service.rb | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/lib/res/service.rb b/lib/res/service.rb index 414309ffe17..07277f1fb1e 100644 --- a/lib/res/service.rb +++ b/lib/res/service.rb @@ -8,22 +8,6 @@ module RES class Service < Common::Client::Base include Common::Client::Concerns::Monitoring - # Makes call to RES and retrieves a token. Token is valid for 3 minutes so we just fire this on every api call - # - # @return [Hash] the student's address - # - def get_token - with_monitoring do - conn = Faraday.new( - Settings.readiness_and_employment_system.auth_endpoint, - headers: { 'Authorization' => "Basic #{Settings.readiness_and_employment_system.credentials}" } - ) - - request = conn.post - JSON.parse(request.body)['access_token'] - end - end - def send_to_res(payload:) with_monitoring do perform( @@ -37,14 +21,14 @@ def send_to_res(payload:) def request_headers { - Authorization: "Bearer #{get_token}" + 'Appian-API-Key': Settings.readiness_and_employment_system.api_key } end private def end_point - "#{Settings.veteran_readiness_and_employment.base_url}/api/endpoints/vaGov/new_application" + "#{Settings.veteran_readiness_and_employment.base_url}/suite/webapi/form281900" end end end From 5fa497de97b9629f8ad00d2db4b24a1ca7b08e73 Mon Sep 17 00:00:00 2001 From: Tyler Fink Date: Wed, 24 Apr 2024 13:14:03 -0600 Subject: [PATCH 03/28] Update key names --- lib/res/configuration.rb | 4 ++-- lib/res/service.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/res/configuration.rb b/lib/res/configuration.rb index 53ecc2f2fdf..ee4932d2ae1 100644 --- a/lib/res/configuration.rb +++ b/lib/res/configuration.rb @@ -16,11 +16,11 @@ def connection end def mock_enabled? - Settings.readiness_and_employment_system.mock_ch_31 || false + Settings.res.mock_ch_31 || false end def base_path - Settings.readiness_and_employment_system.base_url + Settings.res.base_url end def service_name diff --git a/lib/res/service.rb b/lib/res/service.rb index 07277f1fb1e..2d6d4e478bc 100644 --- a/lib/res/service.rb +++ b/lib/res/service.rb @@ -21,14 +21,14 @@ def send_to_res(payload:) def request_headers { - 'Appian-API-Key': Settings.readiness_and_employment_system.api_key + 'Appian-API-Key': Settings.res.api_key } end private def end_point - "#{Settings.veteran_readiness_and_employment.base_url}/suite/webapi/form281900" + "#{Settings.res.base_url}/suite/webapi/form281900" end end end From 84ae59d0d7c484fc7b29b3e6ab5ace348d41e417 Mon Sep 17 00:00:00 2001 From: Tyler Fink Date: Wed, 24 Apr 2024 17:12:47 -0600 Subject: [PATCH 04/28] Update codeowners, slight fixes, empty spec --- config/settings.yml | 4 ++++ config/settings/test.yml | 4 ++++ lib/res/ch31_form.rb | 13 +++++++------ lib/res/service.rb | 2 +- spec/lib/res/ch31_form_spec.rb | 7 +++++++ 5 files changed, 23 insertions(+), 7 deletions(-) create mode 100644 spec/lib/res/ch31_form_spec.rb diff --git a/config/settings.yml b/config/settings.yml index 6658613b94d..75715f9a77d 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -1341,6 +1341,10 @@ vetext_push: user: vets-api-username pass: secret +res: + base_url: ~ + api_key: ~ + veteran_readiness_and_employment: base_url: ~ credentials: ~ diff --git a/config/settings/test.yml b/config/settings/test.yml index 989de93e139..7d296232ead 100644 --- a/config/settings/test.yml +++ b/config/settings/test.yml @@ -145,6 +145,10 @@ vanotify: claim_submission_duplicate_text: oh_fake_duplicate_template_id claim_submission_error_text: oh_fake_error_template_id +res: + base_url: https://fake_url.com + api_key: fake_auth + veteran_readiness_and_employment: base_url: https://fake_url.com credentials: fake_auth diff --git a/lib/res/ch31_form.rb b/lib/res/ch31_form.rb index 91f45140a05..872f6ed8b36 100644 --- a/lib/res/ch31_form.rb +++ b/lib/res/ch31_form.rb @@ -13,7 +13,7 @@ class Ch31Form < RES::Service SENTRY_TAG = { team: 'vfs-ebenefits' }.freeze def initialize(user:, claim:) - super + super() @user = user @claim = claim end @@ -58,19 +58,20 @@ def format_payload_for_res isMoving: form_data['isMoving'], mainPhone: form_data['mainPhone'], cellNumber: form_data['cellPhone'], - # internationalNumber: form_data['internationalNumber'], + internationalNumber: form_data['internationalNumber'], email: form_data['email'], documentId: form_data.dig('supportingDocuments', 0, 'documentId'), # or @claim.guid - receivedDate: @claim.created_at + receivedDate: @claim.created_at, + veteranAddress: mapped_address_hash(form_data['veteranAddress']) } - res_payload[:data].merge!(veteran_address(form_data)) - res_payload[:data].merge!({ veteranInformation: adjusted_veteran_information }) - res_payload[:data].merge!(new_address) if form_data['newAddress'].present? + res_payload.merge!({ veteranInformation: adjusted_veteran_information }) + res_payload.merge!(new_address) if form_data['newAddress'].present? res_payload.to_json end + # TODO: determine need def veteran_address(form_data) vet_address = mapped_address_hash(form_data['veteranAddress']) diff --git a/lib/res/service.rb b/lib/res/service.rb index 2d6d4e478bc..593a247c3b2 100644 --- a/lib/res/service.rb +++ b/lib/res/service.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'vre/configuration' +require 'res/configuration' require 'common/client/base' # The RES::Service class is where we keep RES related endpoint calls and common methods diff --git a/spec/lib/res/ch31_form_spec.rb b/spec/lib/res/ch31_form_spec.rb new file mode 100644 index 00000000000..5cb449f28be --- /dev/null +++ b/spec/lib/res/ch31_form_spec.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +require 'rails_helper' +require 'res/ch31_form' + +RSpec.describe RES::Ch31Form do +end From 233a03007d3c68949e934f67422e5cca8d3ee900 Mon Sep 17 00:00:00 2001 From: Tyler Fink Date: Thu, 25 Apr 2024 11:42:43 -0600 Subject: [PATCH 05/28] Codeowners change --- .github/CODEOWNERS | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 76122d3c070..6640acdad97 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -926,6 +926,7 @@ lib/vetext @department-of-veterans-affairs/mobile-api-team lib/vic @department-of-veterans-affairs/octo-identity lib/virtual_regional_office @department-of-veterans-affairs/Benefits-Team-1 @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group lib/vre @department-of-veterans-affairs/benefits-non-disability @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group +lib/res @department-of-veterans-affairs/benefits-non-disability @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group lib/webhooks @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group modules/accredited_representatives @department-of-veterans-affairs/accredited-representation-management modules/appeals_api @department-of-veterans-affairs/lighthouse-banana-peels @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group @@ -1381,6 +1382,7 @@ spec/lib/vbs @department-of-veterans-affairs/vsa-debt-resolution @department-of- spec/lib/vetext @department-of-veterans-affairs/mobile-api-team spec/lib/virtual_regional_office @department-of-veterans-affairs/Benefits-Team-1 @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group spec/lib/vre/ch31_form_spec.rb @department-of-veterans-affairs/benefits-non-disability @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group +spec/lib/res/ch31_form_spec.rb @department-of-veterans-affairs/benefits-non-disability @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group spec/lib/webhooks/utilities_spec.rb @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group spec/mailers/ch31_submissions_report_mailer_spec.rb @department-of-veterans-affairs/benefits-non-disability @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group spec/mailers/create_daily_spool_files_mailer_spec.rb @department-of-veterans-affairs/my-education-benefits @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group From 3f68448debd2385039ca4beca702de32933dd0c9 Mon Sep 17 00:00:00 2001 From: Tyler Fink Date: Thu, 9 May 2024 12:31:26 -0600 Subject: [PATCH 06/28] Split regional office --- lib/res/ch31_form.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/res/ch31_form.rb b/lib/res/ch31_form.rb index 872f6ed8b36..8fde8b274c4 100644 --- a/lib/res/ch31_form.rb +++ b/lib/res/ch31_form.rb @@ -4,7 +4,6 @@ require_relative 'errors/ch31_errors' require 'sentry_logging' -# Modified VRE code to new RES service module RES class Ch31Form < RES::Service include SentryLogging @@ -98,6 +97,7 @@ def adjusted_veteran_information vet_info = claim_form_hash['veteranInformation'] vet_info['VAFileNumber'] = vet_info.delete('vaFileNumber') if vet_info.key?('vaFileNumber') + vet_info['stationID'], vet_info['regionalOffice'] = vet_info['regionalOffice'].split(' - ') vet_info end From d8e6acf7af2c5fdd005c1a8aca26979e35c94874 Mon Sep 17 00:00:00 2001 From: Tyler Fink Date: Tue, 14 May 2024 10:58:39 -0600 Subject: [PATCH 07/28] Actually use new service --- .../veteran_readiness_employment_claim.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app/models/saved_claim/veteran_readiness_employment_claim.rb b/app/models/saved_claim/veteran_readiness_employment_claim.rb index e6ce564465b..f3b3dcbda1b 100644 --- a/app/models/saved_claim/veteran_readiness_employment_claim.rb +++ b/app/models/saved_claim/veteran_readiness_employment_claim.rb @@ -131,7 +131,7 @@ def send_to_vre(user) send_to_central_mail!(user) end - send_vre_email_form(user) + send_to_res(user) end def upload_to_vbms(doc_type: '1167') @@ -165,6 +165,18 @@ def send_to_central_mail!(user) send_central_mail_confirmation_email(user) end + def send_to_res(user) + email_addr = REGIONAL_OFFICE_EMAILS[@office_location] || 'VRE.VBACO@va.gov' + + log_message_to_sentry("VRE claim email: #{email_addr}, sent to cmp: #{@sent_to_cmp} #{user.present?}", + :info, { uuid: user.uuid }) + + VeteranReadinessEmploymentMailer.build(user.participant_id, email_addr, @sent_to_cmp).deliver_later if user.present? + + service = RES::Ch31Form.new(user:, claim: self) + service.submit + end + def send_vre_email_form(user) @office_location = check_office_location[0] if @office_location.nil? From a84e19089995c6c749ca46f380af886fbe908fe6 Mon Sep 17 00:00:00 2001 From: Tyler Fink Date: Wed, 15 May 2024 13:08:06 -0600 Subject: [PATCH 08/28] Final fixes --- .../veteran_readiness_employment_claim.rb | 11 +++- app/sidekiq/vre/submit1900_job.rb | 2 +- lib/res/ch31_form.rb | 3 +- spec/lib/res/ch31_form_spec.rb | 66 +++++++++++++++++++ spec/sidekiq/vre/submit1900_job_spec.rb | 1 + 5 files changed, 79 insertions(+), 4 deletions(-) diff --git a/app/models/saved_claim/veteran_readiness_employment_claim.rb b/app/models/saved_claim/veteran_readiness_employment_claim.rb index 6f07c356304..1d8d401277f 100644 --- a/app/models/saved_claim/veteran_readiness_employment_claim.rb +++ b/app/models/saved_claim/veteran_readiness_employment_claim.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require 'sentry_logging' -require 'vre/ch31_form' +require 'res/ch31_form' class SavedClaim::VeteranReadinessEmploymentClaim < SavedClaim include SentryLogging @@ -135,6 +135,7 @@ def send_to_vre(user) end def upload_to_vbms(doc_type: '1167') + add_claimant_info(user) form_path = PdfFill::Filler.fill_form(self, nil, { created_at: }) uploader = ClaimsApi::VBMSUploader.new( @@ -144,7 +145,13 @@ def upload_to_vbms(doc_type: '1167') ) log_to_statsd('vbms') do - uploader.upload! + response = uploader.upload! + + if response[:vbms_document_series_ref_id].present? + updated_form = parsed_form + updated_form['documentId'] = response[:vbms_document_series_ref_id] + update!(form: updated_form.to_json) + end end end diff --git a/app/sidekiq/vre/submit1900_job.rb b/app/sidekiq/vre/submit1900_job.rb index 77da5d5d91e..1c0a49f89a2 100644 --- a/app/sidekiq/vre/submit1900_job.rb +++ b/app/sidekiq/vre/submit1900_job.rb @@ -24,7 +24,7 @@ def perform(claim_id, user_uuid) claim.send_to_vre(user) rescue => e log_message_to_sentry( - 'VRE::Submit1900Job failed, retrying...', :warn, generate_sentry_details(e) + 'VRE::Submit1900Job failed, retrying...', :warn, e.message ) raise end diff --git a/lib/res/ch31_form.rb b/lib/res/ch31_form.rb index 8fde8b274c4..fec65116da0 100644 --- a/lib/res/ch31_form.rb +++ b/lib/res/ch31_form.rb @@ -51,6 +51,7 @@ def format_payload_for_res res_payload = { useEva: form_data['useEva'], + receiveElectronicCommunication: form_data['receiveElectronicCommunication'], useTelecounseling: form_data['useTelecounseling'], appointmentTimePreferences: form_data['appointmentTimePreferences'], yearsOfEducation: form_data['yearsOfEducation'], @@ -59,7 +60,7 @@ def format_payload_for_res cellNumber: form_data['cellPhone'], internationalNumber: form_data['internationalNumber'], email: form_data['email'], - documentId: form_data.dig('supportingDocuments', 0, 'documentId'), # or @claim.guid + documentId: form_data['documentId'], receivedDate: @claim.created_at, veteranAddress: mapped_address_hash(form_data['veteranAddress']) } diff --git a/spec/lib/res/ch31_form_spec.rb b/spec/lib/res/ch31_form_spec.rb index 5cb449f28be..3fe5ea5f56f 100644 --- a/spec/lib/res/ch31_form_spec.rb +++ b/spec/lib/res/ch31_form_spec.rb @@ -4,4 +4,70 @@ require 'res/ch31_form' RSpec.describe RES::Ch31Form do + let(:claim) { create(:veteran_readiness_employment_claim) } + let(:user) { FactoryBot.create(:evss_user, :loa3) } + let(:service) { RES::Ch31Form.new(user:, claim:) } + let(:new_address_hash) do + { + newAddress: { + isForeign: false, + isMilitary: nil, + countryName: 'USA', + addressLine1: '1019 Robin Cir', + addressLine2: nil, + addressLine3: nil, + city: 'Arroyo Grande', + province: 'CA', + internationalPostalCode: '93420' + } + } + end + + describe '#submit' do + let(:faraday_response) { double('faraday_connection') } + + before do + allow(faraday_response).to receive(:env) + end + + context 'with a successful submission' do + it 'successfully sends to RES' do + VCR.use_cassette 'veteran_readiness_employment/send_to_res' do + response = service.submit + expect(response['error_occurred']).to eq(false) + end + end + + it 'adds a new address if the user is moving within 30 days' do + VCR.use_cassette 'veteran_readiness_employment/send_to_res' do + expect(service).to receive(:new_address) { new_address_hash } + + service.submit + end + end + end + + context 'with an unsuccessful submission' do + it 'does not successfully send to RES' do + VCR.use_cassette 'veteran_readiness_employment/failed_send_to_res' do + expect(service).to receive(:log_exception_to_sentry) + + response = service.submit + + expect(response['error_occurred']).to eq(true) + end + end + + it 'handles nil claim' do + VCR.use_cassette 'veteran_readiness_employment/failed_send_to_res' do + nil_claim_service = RES::Ch31Form.new(user:, claim: nil) + expect(nil_claim_service).to receive(:log_exception_to_sentry) + + response = nil_claim_service.submit + + expect(response['error_occurred']).to eq(true) + end + end + end + end end diff --git a/spec/sidekiq/vre/submit1900_job_spec.rb b/spec/sidekiq/vre/submit1900_job_spec.rb index b47778a4507..7e2025e7d85 100644 --- a/spec/sidekiq/vre/submit1900_job_spec.rb +++ b/spec/sidekiq/vre/submit1900_job_spec.rb @@ -20,6 +20,7 @@ it 'calls claim.add_claimant_info' do allow(claim).to receive(:send_to_central_mail!) + allow(claim).to receive(:send_to_res) expect(claim).to receive(:add_claimant_info).with(user) end From 7eb270ecd554eb3600d046b3709fbd0e21db29f2 Mon Sep 17 00:00:00 2001 From: Tyler Fink Date: Wed, 15 May 2024 15:05:30 -0600 Subject: [PATCH 09/28] Ignore spec for now --- spec/lib/res/ch31_form_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/lib/res/ch31_form_spec.rb b/spec/lib/res/ch31_form_spec.rb index 3fe5ea5f56f..a59f324e6b2 100644 --- a/spec/lib/res/ch31_form_spec.rb +++ b/spec/lib/res/ch31_form_spec.rb @@ -31,14 +31,14 @@ end context 'with a successful submission' do - it 'successfully sends to RES' do + pending 'successfully sends to RES' do VCR.use_cassette 'veteran_readiness_employment/send_to_res' do response = service.submit expect(response['error_occurred']).to eq(false) end end - it 'adds a new address if the user is moving within 30 days' do + pending 'adds a new address if the user is moving within 30 days' do VCR.use_cassette 'veteran_readiness_employment/send_to_res' do expect(service).to receive(:new_address) { new_address_hash } @@ -48,7 +48,7 @@ end context 'with an unsuccessful submission' do - it 'does not successfully send to RES' do + pending 'does not successfully send to RES' do VCR.use_cassette 'veteran_readiness_employment/failed_send_to_res' do expect(service).to receive(:log_exception_to_sentry) From 353a19e351dbdd864d676801d08e8f5a40af918c Mon Sep 17 00:00:00 2001 From: Tyler Fink Date: Wed, 15 May 2024 16:10:22 -0600 Subject: [PATCH 10/28] Fix rubocop lint --- spec/lib/res/ch31_form_spec.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/spec/lib/res/ch31_form_spec.rb b/spec/lib/res/ch31_form_spec.rb index a59f324e6b2..7d6694c44fe 100644 --- a/spec/lib/res/ch31_form_spec.rb +++ b/spec/lib/res/ch31_form_spec.rb @@ -31,14 +31,16 @@ end context 'with a successful submission' do - pending 'successfully sends to RES' do + it 'successfully sends to RES' do + pending 'needs VCR request from dev/staging' VCR.use_cassette 'veteran_readiness_employment/send_to_res' do response = service.submit expect(response['error_occurred']).to eq(false) end end - pending 'adds a new address if the user is moving within 30 days' do + it 'adds a new address if the user is moving within 30 days' do + pending 'needs VCR request from dev/staging' VCR.use_cassette 'veteran_readiness_employment/send_to_res' do expect(service).to receive(:new_address) { new_address_hash } @@ -48,7 +50,8 @@ end context 'with an unsuccessful submission' do - pending 'does not successfully send to RES' do + it 'does not successfully send to RES' do + pending 'needs VCR request from dev/staging' VCR.use_cassette 'veteran_readiness_employment/failed_send_to_res' do expect(service).to receive(:log_exception_to_sentry) From c5adb8f78de101be4143a265200099f2259a5ac9 Mon Sep 17 00:00:00 2001 From: Tyler Fink Date: Fri, 17 May 2024 11:11:02 -0600 Subject: [PATCH 11/28] More failed tests --- .../saved_claim/veteran_readiness_employment_claim.rb | 5 +++++ .../veteran_readiness_employment_claim_spec.rb | 11 +++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/models/saved_claim/veteran_readiness_employment_claim.rb b/app/models/saved_claim/veteran_readiness_employment_claim.rb index 1d8d401277f..da9942110d1 100644 --- a/app/models/saved_claim/veteran_readiness_employment_claim.rb +++ b/app/models/saved_claim/veteran_readiness_employment_claim.rb @@ -177,6 +177,11 @@ def send_to_central_mail!(user) end def send_to_res(user) + @office_location = check_office_location[0] if @office_location.nil? + + log_message_to_sentry("VRE claim office location: #{@office_location}", + :info, { uuid: user.uuid }) + email_addr = REGIONAL_OFFICE_EMAILS[@office_location] || 'VRE.VBACO@va.gov' log_message_to_sentry("VRE claim email: #{email_addr}, sent to cmp: #{@sent_to_cmp} #{user.present?}", diff --git a/spec/models/saved_claim/veteran_readiness_employment_claim_spec.rb b/spec/models/saved_claim/veteran_readiness_employment_claim_spec.rb index 1f362f42502..fc1fd17c6fe 100644 --- a/spec/models/saved_claim/veteran_readiness_employment_claim_spec.rb +++ b/spec/models/saved_claim/veteran_readiness_employment_claim_spec.rb @@ -68,14 +68,16 @@ end it 'calls #send_to_central_mail!' do - VCR.use_cassette('vbms/document_upload_417') do + pending 'need vcr records' + VCR.use_cassette('vbms/document_upload_417') do expect(claim).to receive(:send_to_central_mail!) subject end end it 'does not raise an error' do - VCR.use_cassette('vbms/document_upload_417') do + pending 'need vcr records' + VCR.use_cassette('vbms/document_upload_417') do allow(claim).to receive(:send_to_central_mail!) expect { subject }.not_to raise_error end @@ -97,6 +99,7 @@ end it 'successfully sends to VRE' do + pending 'need vcr records' VCR.use_cassette 'veteran_readiness_employment/send_to_vre' do claim.add_claimant_info(user_object) response = claim.send_to_vre(user_object) @@ -109,6 +112,7 @@ end it 'does not successfully send to VRE' do + pending 'need vcr records' VCR.use_cassette 'veteran_readiness_employment/failed_send_to_vre' do claim.add_claimant_info(user_object) response = claim.send_to_vre(user_object) @@ -121,6 +125,7 @@ end it 'sends confirmation email' do + pending 'need vcr records' VCR.use_cassette 'veteran_readiness_employment/send_to_vre' do expect(claim).to receive(:send_vbms_confirmation_email).with(user_object) @@ -132,6 +137,7 @@ context 'non-submission to VRE' do it 'stops submission if location is not in list' do + pending 'need vcr records' VCR.use_cassette 'veteran_readiness_employment/send_to_vre' do expect_any_instance_of(BGS::RORoutingService).to receive(:get_regional_office_by_zip_code).and_return( { regional_office: { number: '310' } } @@ -150,6 +156,7 @@ let(:user_object) { create(:unauthorized_evss_user) } it 'PDF is sent to Central Mail and not VBMS' do + pending 'need vcr records' expect(claim).to receive(:send_to_central_mail!).with(user_object).once.and_call_original expect(claim).to receive(:process_attachments!) expect(claim).to receive(:send_central_mail_confirmation_email) From b46fbd6ebcba2cc42e4fa3173519a0e7ac6f77d5 Mon Sep 17 00:00:00 2001 From: Tyler Fink Date: Fri, 17 May 2024 11:35:55 -0600 Subject: [PATCH 12/28] Fix lint --- .../veteran_readiness_employment_claim_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/models/saved_claim/veteran_readiness_employment_claim_spec.rb b/spec/models/saved_claim/veteran_readiness_employment_claim_spec.rb index fc1fd17c6fe..9df20dbf1e9 100644 --- a/spec/models/saved_claim/veteran_readiness_employment_claim_spec.rb +++ b/spec/models/saved_claim/veteran_readiness_employment_claim_spec.rb @@ -68,16 +68,16 @@ end it 'calls #send_to_central_mail!' do - pending 'need vcr records' - VCR.use_cassette('vbms/document_upload_417') do + pending 'need vcr records' + VCR.use_cassette('vbms/document_upload_417') do expect(claim).to receive(:send_to_central_mail!) subject end end it 'does not raise an error' do - pending 'need vcr records' - VCR.use_cassette('vbms/document_upload_417') do + pending 'need vcr records' + VCR.use_cassette('vbms/document_upload_417') do allow(claim).to receive(:send_to_central_mail!) expect { subject }.not_to raise_error end From 5ab6c1aded8cd7679bc44a05a8435057c2ec885d Mon Sep 17 00:00:00 2001 From: Tyler Fink Date: Fri, 17 May 2024 15:07:25 -0600 Subject: [PATCH 13/28] Fix specs --- .../veteran_readiness_employment_claim.rb | 20 +-- app/sidekiq/vre/submit1900_job.rb | 1 - lib/res/ch31_form.rb | 45 +++---- spec/lib/res/ch31_form_spec.rb | 38 ++---- ...veteran_readiness_employment_claim_spec.rb | 127 ++++++------------ 5 files changed, 82 insertions(+), 149 deletions(-) diff --git a/app/models/saved_claim/veteran_readiness_employment_claim.rb b/app/models/saved_claim/veteran_readiness_employment_claim.rb index da9942110d1..1d585802ef0 100644 --- a/app/models/saved_claim/veteran_readiness_employment_claim.rb +++ b/app/models/saved_claim/veteran_readiness_employment_claim.rb @@ -111,10 +111,11 @@ def add_office_location(updated_form) end def send_to_vre(user) + add_claimant_info(user) + if user&.participant_id begin - upload_to_vbms - send_vbms_confirmation_email(user) + upload_to_vbms(user:) rescue log_message_to_sentry('Error uploading VRE claim to VBMS. Now attempting to upload claim to central mail...', :warn, { uuid: user.uuid }) @@ -134,8 +135,7 @@ def send_to_vre(user) send_to_res(user) end - def upload_to_vbms(doc_type: '1167') - add_claimant_info(user) + def upload_to_vbms(doc_type: '1167', user:) form_path = PdfFill::Filler.fill_form(self, nil, { created_at: }) uploader = ClaimsApi::VBMSUploader.new( @@ -153,6 +153,8 @@ def upload_to_vbms(doc_type: '1167') update!(form: updated_form.to_json) end end + + send_vbms_confirmation_email(user) end def to_pdf(file_name = nil) @@ -177,11 +179,6 @@ def send_to_central_mail!(user) end def send_to_res(user) - @office_location = check_office_location[0] if @office_location.nil? - - log_message_to_sentry("VRE claim office location: #{@office_location}", - :info, { uuid: user.uuid }) - email_addr = REGIONAL_OFFICE_EMAILS[@office_location] || 'VRE.VBACO@va.gov' log_message_to_sentry("VRE claim email: #{email_addr}, sent to cmp: #{@sent_to_cmp} #{user.present?}", @@ -194,11 +191,6 @@ def send_to_res(user) end def send_vre_email_form(user) - @office_location = check_office_location[0] if @office_location.nil? - - log_message_to_sentry("VRE claim office location: #{@office_location}", - :info, { uuid: user.uuid }) - email_addr = REGIONAL_OFFICE_EMAILS[@office_location] || 'VRE.VBACO@va.gov' log_message_to_sentry("VRE claim email: #{email_addr}, sent to cmp: #{@sent_to_cmp} #{user.present?}", diff --git a/app/sidekiq/vre/submit1900_job.rb b/app/sidekiq/vre/submit1900_job.rb index 1c0a49f89a2..1c69d9a6832 100644 --- a/app/sidekiq/vre/submit1900_job.rb +++ b/app/sidekiq/vre/submit1900_job.rb @@ -20,7 +20,6 @@ class Submit1900Job def perform(claim_id, user_uuid) claim = SavedClaim::VeteranReadinessEmploymentClaim.find claim_id user = User.find user_uuid - claim.add_claimant_info(user) claim.send_to_vre(user) rescue => e log_message_to_sentry( diff --git a/lib/res/ch31_form.rb b/lib/res/ch31_form.rb index fec65116da0..c0c2414285d 100644 --- a/lib/res/ch31_form.rb +++ b/lib/res/ch31_form.rb @@ -27,7 +27,7 @@ def submit response = send_to_res(payload: format_payload_for_res) response_body = response.body - raise Ch31Error if response_body['error_occurred'] == true + raise Ch31Error if response_body['success_message'].blank? log_message_to_sentry( 'Temp message for testing', @@ -37,11 +37,25 @@ def submit ) response_body rescue Ch31Error => e - process_ch_31_error(e, response_body) + log_exception_to_sentry( + e, + { + intake_id: response_body['ApplicationIntake'], + error_message: response_body['ErrorMessage'] + }, + SENTRY_TAG + ) - response_body + raise rescue Ch31NilClaimError => e - process_nil_claim_error(e) + log_exception_to_sentry( + e, + { + icn: @user.icn + }, + SENTRY_TAG + ) + raise end private @@ -133,28 +147,5 @@ def mapped_address_hash(client_hash) postalCode: client_hash['postalCode'] } end - - def process_ch_31_error(e, response_body) - log_exception_to_sentry( - e, - { - intake_id: response_body['ApplicationIntake'], - error_message: response_body['ErrorMessage'] - }, - SENTRY_TAG - ) - end - - def process_nil_claim_error(e) - log_exception_to_sentry( - e, - { - icn: @user.icn - }, - SENTRY_TAG - ) - - { 'error_occurred' => true, 'error_message' => 'Claim cannot be null' } - end end end diff --git a/spec/lib/res/ch31_form_spec.rb b/spec/lib/res/ch31_form_spec.rb index 7d6694c44fe..f74de161cfd 100644 --- a/spec/lib/res/ch31_form_spec.rb +++ b/spec/lib/res/ch31_form_spec.rb @@ -22,6 +22,7 @@ } } end + let(:success_message) { OpenStruct.new(body:{ 'success_message' => 'RES has successfully received the request'}) } describe '#submit' do let(:faraday_response) { double('faraday_connection') } @@ -31,45 +32,34 @@ end context 'with a successful submission' do + before do + allow(service).to receive(:send_to_res).and_return(success_message) + end + it 'successfully sends to RES' do - pending 'needs VCR request from dev/staging' - VCR.use_cassette 'veteran_readiness_employment/send_to_res' do - response = service.submit - expect(response['error_occurred']).to eq(false) - end + service.submit end it 'adds a new address if the user is moving within 30 days' do - pending 'needs VCR request from dev/staging' - VCR.use_cassette 'veteran_readiness_employment/send_to_res' do - expect(service).to receive(:new_address) { new_address_hash } + expect(service).to receive(:new_address) { new_address_hash } - service.submit - end + service.submit end end context 'with an unsuccessful submission' do it 'does not successfully send to RES' do - pending 'needs VCR request from dev/staging' - VCR.use_cassette 'veteran_readiness_employment/failed_send_to_res' do - expect(service).to receive(:log_exception_to_sentry) + expect(service).to receive(:log_exception_to_sentry) + allow(service).to receive(:send_to_res).and_return(OpenStruct.new(body: { 'error' => 'Error' })) - response = service.submit - - expect(response['error_occurred']).to eq(true) - end + expect { service.submit }.to raise_error(Ch31Error) end it 'handles nil claim' do - VCR.use_cassette 'veteran_readiness_employment/failed_send_to_res' do - nil_claim_service = RES::Ch31Form.new(user:, claim: nil) - expect(nil_claim_service).to receive(:log_exception_to_sentry) - - response = nil_claim_service.submit + nil_claim_service = RES::Ch31Form.new(user:, claim: nil) + expect(nil_claim_service).to receive(:log_exception_to_sentry) - expect(response['error_occurred']).to eq(true) - end + expect { nil_claim_service.submit }.to raise_error(Ch31NilClaimError) end end end diff --git a/spec/models/saved_claim/veteran_readiness_employment_claim_spec.rb b/spec/models/saved_claim/veteran_readiness_employment_claim_spec.rb index 9df20dbf1e9..2b8a4afbed8 100644 --- a/spec/models/saved_claim/veteran_readiness_employment_claim_spec.rb +++ b/spec/models/saved_claim/veteran_readiness_employment_claim_spec.rb @@ -23,37 +23,37 @@ } end + before do + allow_any_instance_of(RES::Ch31Form).to receive(:submit).and_return(true) + end + describe '#add_claimant_info' do it 'adds veteran information' do - VCR.use_cassette 'veteran_readiness_employment/add_claimant_info' do - claim.add_claimant_info(user_object) - claimant_keys = %w[fullName dob pid edipi vet360ID regionalOffice VAFileNumber ssn] - expect(claim.parsed_form['veteranInformation']).to include( - { - 'fullName' => { - 'first' => 'Homer', - 'middle' => 'John', - 'last' => 'Simpson' - }, - 'dob' => '1986-05-06' - } - ) - - expect( - claim.parsed_form['veteranInformation'].keys - ).to eq(claimant_keys) - end + claim.add_claimant_info(user_object) + claimant_keys = %w[fullName dob pid edipi vet360ID regionalOffice VAFileNumber ssn] + expect(claim.parsed_form['veteranInformation']).to include( + { + 'fullName' => { + 'first' => 'Homer', + 'middle' => 'John', + 'last' => 'Simpson' + }, + 'dob' => '1986-05-06' + } + ) + + expect( + claim.parsed_form['veteranInformation'].keys + ).to eq(claimant_keys) end it 'does not obtain va_file_number' do - VCR.use_cassette 'veteran_readiness_employment/add_claimant_info' do - people_service_object = double('people_service') - allow(people_service_object).to receive(:find_person_by_participant_id) - allow(BGS::People::Request).to receive(:new) { people_service_object } + people_service_object = double('people_service') + allow(people_service_object).to receive(:find_person_by_participant_id) + allow(BGS::People::Request).to receive(:new) { people_service_object } - claim.add_claimant_info(user_object) - expect(claim.parsed_form['veteranInformation']).to include('VAFileNumber' => nil) - end + claim.add_claimant_info(user_object) + expect(claim.parsed_form['veteranInformation']).to include('VAFileNumber' => nil) end end @@ -68,26 +68,20 @@ end it 'calls #send_to_central_mail!' do - pending 'need vcr records' - VCR.use_cassette('vbms/document_upload_417') do - expect(claim).to receive(:send_to_central_mail!) - subject - end + expect(claim).to receive(:send_to_central_mail!) + subject end it 'does not raise an error' do - pending 'need vcr records' - VCR.use_cassette('vbms/document_upload_417') do - allow(claim).to receive(:send_to_central_mail!) - expect { subject }.not_to raise_error - end + allow(claim).to receive(:send_to_central_mail!) + expect { subject }.not_to raise_error end end context 'when VBMS upload is successful' do - before { expect(ClaimsApi::VBMSUploader).to receive(:new) { OpenStruct.new(upload!: true) } } + before { expect(ClaimsApi::VBMSUploader).to receive(:new) { OpenStruct.new(upload!: {}) } } - context 'submission to VRE' do + context 'submission to RES' do before do # As the PERMITTED_OFFICE_LOCATIONS constant at # the top of: app/models/saved_claim/veteran_readiness_employment_claim.rb gets changed, you @@ -98,65 +92,32 @@ ) end - it 'successfully sends to VRE' do - pending 'need vcr records' - VCR.use_cassette 'veteran_readiness_employment/send_to_vre' do - claim.add_claimant_info(user_object) - response = claim.send_to_vre(user_object) - - # the business has asked us to put a pause on submissions - # so this is just a temporary change but will be put back - # expect(response['error_occurred']).to eq(false) - expect(response).to eq(nil) - end - end - - it 'does not successfully send to VRE' do - pending 'need vcr records' - VCR.use_cassette 'veteran_readiness_employment/failed_send_to_vre' do - claim.add_claimant_info(user_object) - response = claim.send_to_vre(user_object) - - # the business has asked us to put a pause on submissions - # so this is just a temporary change but will be put back - # expect(response['error_occurred']).to eq(true) - expect(response).to eq(nil) - end - end - it 'sends confirmation email' do - pending 'need vcr records' - VCR.use_cassette 'veteran_readiness_employment/send_to_vre' do - expect(claim).to receive(:send_vbms_confirmation_email).with(user_object) + expect(claim).to receive(:send_vbms_confirmation_email).with(user_object) - claim.add_claimant_info(user_object) - claim.send_to_vre(user_object) - end + claim.send_to_vre(user_object) end end - context 'non-submission to VRE' do - it 'stops submission if location is not in list' do - pending 'need vcr records' - VCR.use_cassette 'veteran_readiness_employment/send_to_vre' do - expect_any_instance_of(BGS::RORoutingService).to receive(:get_regional_office_by_zip_code).and_return( - { regional_office: { number: '310' } } - ) + # We want all submission to go through with RES + # context 'non-submission to RES' do + # it 'stops submission if location is not in list' do + # expect_any_instance_of(BGS::RORoutingService).to receive(:get_regional_office_by_zip_code).and_return( + # { regional_office: { number: '310' } } + # ) - expect(VRE::Ch31Form).not_to receive(:new) - claim.add_claimant_info(user_object) + # expect(RES::Ch31Form).not_to receive(:new) + # claim.add_claimant_info(user_object) - claim.send_to_vre(user_object) - end - end - end + # claim.send_to_vre(user_object) + # end + # end end context 'when user has no PID' do let(:user_object) { create(:unauthorized_evss_user) } it 'PDF is sent to Central Mail and not VBMS' do - pending 'need vcr records' expect(claim).to receive(:send_to_central_mail!).with(user_object).once.and_call_original expect(claim).to receive(:process_attachments!) expect(claim).to receive(:send_central_mail_confirmation_email) From 1eb487c5fea44bb0482458609c8faa5ffeaaea01 Mon Sep 17 00:00:00 2001 From: Tyler Fink Date: Fri, 17 May 2024 17:29:33 -0600 Subject: [PATCH 14/28] Fix lints --- lib/res/ch31_form.rb | 46 ++++++++++++++++------------------ spec/lib/res/ch31_form_spec.rb | 6 +---- 2 files changed, 23 insertions(+), 29 deletions(-) diff --git a/lib/res/ch31_form.rb b/lib/res/ch31_form.rb index c0c2414285d..829d3bb841f 100644 --- a/lib/res/ch31_form.rb +++ b/lib/res/ch31_form.rb @@ -22,39 +22,26 @@ def initialize(user:, claim:) # @return [Hash] the student's address # def submit - raise Ch31NilClaimError if @claim.nil? + if @claim.nil? + log_exception_to_sentry( + 'Ch31NilClaimError', + { + icn: @user.icn + }, + SENTRY_TAG + ) + raise Ch31NilClaimError + end response = send_to_res(payload: format_payload_for_res) response_body = response.body raise Ch31Error if response_body['success_message'].blank? - log_message_to_sentry( - 'Temp message for testing', - :warn, - { application_intake_id: response_body['application_intake'] }, - SENTRY_TAG - ) response_body rescue Ch31Error => e - log_exception_to_sentry( - e, - { - intake_id: response_body['ApplicationIntake'], - error_message: response_body['ErrorMessage'] - }, - SENTRY_TAG - ) + process_ch_31_error(e, response_body) - raise - rescue Ch31NilClaimError => e - log_exception_to_sentry( - e, - { - icn: @user.icn - }, - SENTRY_TAG - ) raise end @@ -147,5 +134,16 @@ def mapped_address_hash(client_hash) postalCode: client_hash['postalCode'] } end + + def process_ch_31_error(e, response_body) + log_exception_to_sentry( + e, + { + intake_id: response_body['ApplicationIntake'], + error_message: response_body['ErrorMessage'] + }, + SENTRY_TAG + ) + end end end diff --git a/spec/lib/res/ch31_form_spec.rb b/spec/lib/res/ch31_form_spec.rb index f74de161cfd..a33d1071594 100644 --- a/spec/lib/res/ch31_form_spec.rb +++ b/spec/lib/res/ch31_form_spec.rb @@ -22,7 +22,7 @@ } } end - let(:success_message) { OpenStruct.new(body:{ 'success_message' => 'RES has successfully received the request'}) } + let(:success_message) { OpenStruct.new(body: { 'success_message' => 'RES has successfully received the request' }) } describe '#submit' do let(:faraday_response) { double('faraday_connection') } @@ -36,10 +36,6 @@ allow(service).to receive(:send_to_res).and_return(success_message) end - it 'successfully sends to RES' do - service.submit - end - it 'adds a new address if the user is moving within 30 days' do expect(service).to receive(:new_address) { new_address_hash } From bd705d5be850f659ede4e09c67673b8bb208e0cc Mon Sep 17 00:00:00 2001 From: Tyler Fink Date: Mon, 20 May 2024 11:05:59 -0600 Subject: [PATCH 15/28] move params --- app/models/saved_claim/veteran_readiness_employment_claim.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/saved_claim/veteran_readiness_employment_claim.rb b/app/models/saved_claim/veteran_readiness_employment_claim.rb index 1d585802ef0..7f91513486d 100644 --- a/app/models/saved_claim/veteran_readiness_employment_claim.rb +++ b/app/models/saved_claim/veteran_readiness_employment_claim.rb @@ -135,7 +135,7 @@ def send_to_vre(user) send_to_res(user) end - def upload_to_vbms(doc_type: '1167', user:) + def upload_to_vbms(user:, doc_type: '1167') form_path = PdfFill::Filler.fill_form(self, nil, { created_at: }) uploader = ClaimsApi::VBMSUploader.new( From 2ad49a6d5509f96354e6b25942f326beff0ad97f Mon Sep 17 00:00:00 2001 From: Tyler Fink Date: Wed, 22 May 2024 13:17:27 -0600 Subject: [PATCH 16/28] remove process attachments --- .../veteran_readiness_employment_claim.rb | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/app/models/saved_claim/veteran_readiness_employment_claim.rb b/app/models/saved_claim/veteran_readiness_employment_claim.rb index 7f91513486d..fa712e98e49 100644 --- a/app/models/saved_claim/veteran_readiness_employment_claim.rb +++ b/app/models/saved_claim/veteran_readiness_employment_claim.rb @@ -170,12 +170,9 @@ def send_to_central_mail!(user) update!(form: form_copy.to_json) log_message_to_sentry(guid, :warn, { attachment_id: guid }, { team: 'vfs-ebenefits' }) - @sent_to_cmp = true - log_to_statsd('cmp') do - process_attachments! - end send_central_mail_confirmation_email(user) + @sent_to_cmp = true end def send_to_res(user) @@ -237,14 +234,6 @@ def send_central_mail_confirmation_email(user) ) end - def process_attachments! - refs = attachment_keys.map { |key| Array(open_struct_form.send(key)) }.flatten - files = PersistentAttachment.where(guid: refs.map(&:confirmationCode)) - files.find_each { |f| f.update(saved_claim_id: id) } - - Lighthouse::SubmitBenefitsIntakeClaim.new.perform(id) - end - def business_line 'VRE' end From 879551c4db27e8314e34292a211a8c7d548af3f6 Mon Sep 17 00:00:00 2001 From: Tyler Fink Date: Tue, 28 May 2024 13:18:59 -0600 Subject: [PATCH 17/28] Update receivedDate value and stationId field --- lib/res/ch31_form.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/res/ch31_form.rb b/lib/res/ch31_form.rb index 829d3bb841f..aa0ad61e3f1 100644 --- a/lib/res/ch31_form.rb +++ b/lib/res/ch31_form.rb @@ -62,7 +62,7 @@ def format_payload_for_res internationalNumber: form_data['internationalNumber'], email: form_data['email'], documentId: form_data['documentId'], - receivedDate: @claim.created_at, + receivedDate: @claim.created_at.to_date.to_s, veteranAddress: mapped_address_hash(form_data['veteranAddress']) } @@ -99,7 +99,7 @@ def adjusted_veteran_information vet_info = claim_form_hash['veteranInformation'] vet_info['VAFileNumber'] = vet_info.delete('vaFileNumber') if vet_info.key?('vaFileNumber') - vet_info['stationID'], vet_info['regionalOffice'] = vet_info['regionalOffice'].split(' - ') + vet_info['stationId'], vet_info['regionalOffice'] = vet_info['regionalOffice'].split(' - ') vet_info end From a84a697ce4cae1a480fd3b5de850793032998108 Mon Sep 17 00:00:00 2001 From: Tyler Fink Date: Tue, 28 May 2024 14:17:02 -0600 Subject: [PATCH 18/28] Use flipper for res v vre submission --- .../veteran_readiness_employment_claim.rb | 31 ++++++++++--------- config/features.yml | 4 +++ 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/app/models/saved_claim/veteran_readiness_employment_claim.rb b/app/models/saved_claim/veteran_readiness_employment_claim.rb index fa712e98e49..4b7f559bf36 100644 --- a/app/models/saved_claim/veteran_readiness_employment_claim.rb +++ b/app/models/saved_claim/veteran_readiness_employment_claim.rb @@ -2,6 +2,7 @@ require 'sentry_logging' require 'res/ch31_form' +require 'vre/ch31_form' class SavedClaim::VeteranReadinessEmploymentClaim < SavedClaim include SentryLogging @@ -84,7 +85,6 @@ def add_claimant_info(user) updated_form = parsed_form add_veteran_info(updated_form, user) if user&.loa3? - add_office_location(updated_form) if updated_form['veteranInformation'].present? update!(form: updated_form.to_json) end @@ -112,27 +112,20 @@ def add_office_location(updated_form) def send_to_vre(user) add_claimant_info(user) + add_office_location(updated_form) if updated_form['veteranInformation'].present? if user&.participant_id - begin - upload_to_vbms(user:) - rescue - log_message_to_sentry('Error uploading VRE claim to VBMS. Now attempting to upload claim to central mail...', - :warn, { uuid: user.uuid }) - begin - send_to_central_mail!(user) - rescue => e - log_message_to_sentry('Error uploading VRE claim to central mail after failure uploading claim to vbms', - :error, { uuid: user.uuid }) - log_exception_to_sentry(e, { uuid: user.uuid }) - end - end + upload_to_vbms(user:) else log_message_to_sentry('Participant id is blank when submitting VRE claim', :warn) send_to_central_mail!(user) end - send_to_res(user) + if Flipper.enabled?(:veteran_readiness_employment_to_res) + send_to_res(user) + else + send_vre_email_form(user) + end end def upload_to_vbms(user:, doc_type: '1167') @@ -155,6 +148,10 @@ def upload_to_vbms(user:, doc_type: '1167') end send_vbms_confirmation_email(user) + rescue + log_message_to_sentry('Error uploading VRE claim to VBMS', + :warn, { uuid: user.uuid }) + send_to_central_mail!(user) end def to_pdf(file_name = nil) @@ -173,6 +170,10 @@ def send_to_central_mail!(user) send_central_mail_confirmation_email(user) @sent_to_cmp = true + rescue => e + log_message_to_sentry('Error uploading VRE claim to central mail', + :error, { uuid: user.uuid }) + log_exception_to_sentry(e, { uuid: user.uuid }) end def send_to_res(user) diff --git a/config/features.yml b/config/features.yml index 1583993b35d..22e30edde11 100644 --- a/config/features.yml +++ b/config/features.yml @@ -1462,3 +1462,7 @@ features: toggle_vye_adress_direct_deposit_forms: actor_type: user description: Enable mailing address and direct deposit for VYE + veteran_readiness_employment_to_res: + actor_type: user + description: Enable RES platform for Veteran Readiness & Employment form submissions, disabled will use VRE email + enable_in_development: true From 86b7baa3458c5c600ca9638a112c9d770cc4119b Mon Sep 17 00:00:00 2001 From: Tyler Fink Date: Wed, 29 May 2024 12:33:38 -0600 Subject: [PATCH 19/28] Update code and add specs for flipper --- .../veteran_readiness_employment_claim.rb | 9 +++- lib/res/ch31_form.rb | 3 +- ...veteran_readiness_employment_claim_spec.rb | 43 +++++++++++-------- 3 files changed, 35 insertions(+), 20 deletions(-) diff --git a/app/models/saved_claim/veteran_readiness_employment_claim.rb b/app/models/saved_claim/veteran_readiness_employment_claim.rb index 4b7f559bf36..17a8566bbd1 100644 --- a/app/models/saved_claim/veteran_readiness_employment_claim.rb +++ b/app/models/saved_claim/veteran_readiness_employment_claim.rb @@ -85,6 +85,7 @@ def add_claimant_info(user) updated_form = parsed_form add_veteran_info(updated_form, user) if user&.loa3? + add_office_location(updated_form) if updated_form['veteranInformation'].present? update!(form: updated_form.to_json) end @@ -107,12 +108,16 @@ def add_office_location(updated_form) @office_location = regional_office[0] office_name = regional_office[1] - updated_form['veteranInformation']&.merge!({ 'regionalOffice' => "#{@office_location} - #{office_name}" }) + updated_form['veteranInformation']&.merge!({ + 'regionalOffice' => "#{@office_location} - #{office_name}", + 'regionalOfficeName' => office_name, + 'stationId' => @office_location + }) + end def send_to_vre(user) add_claimant_info(user) - add_office_location(updated_form) if updated_form['veteranInformation'].present? if user&.participant_id upload_to_vbms(user:) diff --git a/lib/res/ch31_form.rb b/lib/res/ch31_form.rb index aa0ad61e3f1..d0d55248d5a 100644 --- a/lib/res/ch31_form.rb +++ b/lib/res/ch31_form.rb @@ -99,7 +99,8 @@ def adjusted_veteran_information vet_info = claim_form_hash['veteranInformation'] vet_info['VAFileNumber'] = vet_info.delete('vaFileNumber') if vet_info.key?('vaFileNumber') - vet_info['stationId'], vet_info['regionalOffice'] = vet_info['regionalOffice'].split(' - ') + vet_info['regionalOffice'] = vet_info['regionalOfficeName'] + vet_info.delete(:regionalOfficeName) vet_info end diff --git a/spec/models/saved_claim/veteran_readiness_employment_claim_spec.rb b/spec/models/saved_claim/veteran_readiness_employment_claim_spec.rb index 2b8a4afbed8..77841960f1f 100644 --- a/spec/models/saved_claim/veteran_readiness_employment_claim_spec.rb +++ b/spec/models/saved_claim/veteran_readiness_employment_claim_spec.rb @@ -25,12 +25,13 @@ before do allow_any_instance_of(RES::Ch31Form).to receive(:submit).and_return(true) + Flipper.enable(:veteran_readiness_employment_to_res) end describe '#add_claimant_info' do it 'adds veteran information' do claim.add_claimant_info(user_object) - claimant_keys = %w[fullName dob pid edipi vet360ID regionalOffice VAFileNumber ssn] + claimant_keys = %w[fullName dob pid edipi vet360ID regionalOffice regionalOfficeName stationId VAFileNumber ssn] expect(claim.parsed_form['veteranInformation']).to include( { 'fullName' => { @@ -42,9 +43,7 @@ } ) - expect( - claim.parsed_form['veteranInformation'].keys - ).to eq(claimant_keys) + expect(claim.parsed_form['veteranInformation']).to include(*claimant_keys) end it 'does not obtain va_file_number' do @@ -81,7 +80,7 @@ context 'when VBMS upload is successful' do before { expect(ClaimsApi::VBMSUploader).to receive(:new) { OpenStruct.new(upload!: {}) } } - context 'submission to RES' do + context 'submission to VRE' do before do # As the PERMITTED_OFFICE_LOCATIONS constant at # the top of: app/models/saved_claim/veteran_readiness_employment_claim.rb gets changed, you @@ -99,19 +98,30 @@ end end - # We want all submission to go through with RES - # context 'non-submission to RES' do - # it 'stops submission if location is not in list' do - # expect_any_instance_of(BGS::RORoutingService).to receive(:get_regional_office_by_zip_code).and_return( - # { regional_office: { number: '310' } } - # ) + # We want all submission to go through with RES + context 'non-submission to VRE' do + context 'flipper enabled' do + it 'stops submission if location is not in list' do + expect_any_instance_of(RES::Ch31Form).to receive(:submit) + claim.add_claimant_info(user_object) - # expect(RES::Ch31Form).not_to receive(:new) - # claim.add_claimant_info(user_object) + claim.send_to_vre(user_object) + end + end + + context 'flipper disabled' do + before do + Flipper.disable(:veteran_readiness_employment_to_res) + end + + it 'stops submission if location is not in list' do + expect(VRE::Ch31Form).not_to receive(:new) + claim.add_claimant_info(user_object) - # claim.send_to_vre(user_object) - # end - # end + claim.send_to_vre(user_object) + end + end + end end context 'when user has no PID' do @@ -119,7 +129,6 @@ it 'PDF is sent to Central Mail and not VBMS' do expect(claim).to receive(:send_to_central_mail!).with(user_object).once.and_call_original - expect(claim).to receive(:process_attachments!) expect(claim).to receive(:send_central_mail_confirmation_email) expect(claim).not_to receive(:upload_to_vbms) expect(VeteranReadinessEmploymentMailer).to receive(:build).with( From f35d6d852e49b9cbe778003d9ccb797067958a58 Mon Sep 17 00:00:00 2001 From: Tyler Fink Date: Wed, 29 May 2024 13:19:49 -0600 Subject: [PATCH 20/28] lint --- .../saved_claim/veteran_readiness_employment_claim.rb | 11 +++++------ .../veteran_readiness_employment_claim_spec.rb | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/app/models/saved_claim/veteran_readiness_employment_claim.rb b/app/models/saved_claim/veteran_readiness_employment_claim.rb index 17a8566bbd1..bbb7a520893 100644 --- a/app/models/saved_claim/veteran_readiness_employment_claim.rb +++ b/app/models/saved_claim/veteran_readiness_employment_claim.rb @@ -108,12 +108,11 @@ def add_office_location(updated_form) @office_location = regional_office[0] office_name = regional_office[1] - updated_form['veteranInformation']&.merge!({ - 'regionalOffice' => "#{@office_location} - #{office_name}", - 'regionalOfficeName' => office_name, - 'stationId' => @office_location - }) - + updated_form['veteranInformation']&.merge!({ + 'regionalOffice' => "#{@office_location} - #{office_name}", + 'regionalOfficeName' => office_name, + 'stationId' => @office_location + }) end def send_to_vre(user) diff --git a/spec/models/saved_claim/veteran_readiness_employment_claim_spec.rb b/spec/models/saved_claim/veteran_readiness_employment_claim_spec.rb index 77841960f1f..744a625df16 100644 --- a/spec/models/saved_claim/veteran_readiness_employment_claim_spec.rb +++ b/spec/models/saved_claim/veteran_readiness_employment_claim_spec.rb @@ -98,7 +98,7 @@ end end - # We want all submission to go through with RES + # We want all submission to go through with RES context 'non-submission to VRE' do context 'flipper enabled' do it 'stops submission if location is not in list' do From 6208e37abbbb1c928c3d57041a8873a34336cf0e Mon Sep 17 00:00:00 2001 From: Tyler Fink Date: Wed, 29 May 2024 14:13:05 -0600 Subject: [PATCH 21/28] Remove sentry logging, readd lighthouse submission --- .../veteran_readiness_employment_claim.rb | 32 +++++++++++-------- lib/res/ch31_form.rb | 22 ++++--------- ...veteran_readiness_employment_claim_spec.rb | 1 + 3 files changed, 26 insertions(+), 29 deletions(-) diff --git a/app/models/saved_claim/veteran_readiness_employment_claim.rb b/app/models/saved_claim/veteran_readiness_employment_claim.rb index bbb7a520893..f355113459c 100644 --- a/app/models/saved_claim/veteran_readiness_employment_claim.rb +++ b/app/models/saved_claim/veteran_readiness_employment_claim.rb @@ -121,7 +121,7 @@ def send_to_vre(user) if user&.participant_id upload_to_vbms(user:) else - log_message_to_sentry('Participant id is blank when submitting VRE claim', :warn) + Rails.logger.warn('Participane.messaget id is blank when submitting VRE claim') send_to_central_mail!(user) end @@ -153,8 +153,7 @@ def upload_to_vbms(user:, doc_type: '1167') send_vbms_confirmation_email(user) rescue - log_message_to_sentry('Error uploading VRE claim to VBMS', - :warn, { uuid: user.uuid }) + Rails.logger.error("Error uploading VRE claim to VBMS. user uuid: #{user.uuid}") send_to_central_mail!(user) end @@ -170,21 +169,20 @@ def send_to_central_mail!(user) form_copy['vaFileNumber'] = parsed_form.dig('veteranInformation', 'VAFileNumber') update!(form: form_copy.to_json) - log_message_to_sentry(guid, :warn, { attachment_id: guid }, { team: 'vfs-ebenefits' }) - send_central_mail_confirmation_email(user) + process_attachments! @sent_to_cmp = true + + send_central_mail_confirmation_email(user) rescue => e - log_message_to_sentry('Error uploading VRE claim to central mail', - :error, { uuid: user.uuid }) - log_exception_to_sentry(e, { uuid: user.uuid }) + Rails.logger.error("Error uploading VRE claim to central mail. user uuid: #{user.uuid}. #{e}") end def send_to_res(user) email_addr = REGIONAL_OFFICE_EMAILS[@office_location] || 'VRE.VBACO@va.gov' - log_message_to_sentry("VRE claim email: #{email_addr}, sent to cmp: #{@sent_to_cmp} #{user.present?}", - :info, { uuid: user.uuid }) + Rails.logger.info("VRE claim email: #{email_addr}. user uuid: #{user.uuid}.\ + sent to cmp: #{@sent_to_cmp} #{user.present?}") VeteranReadinessEmploymentMailer.build(user.participant_id, email_addr, @sent_to_cmp).deliver_later if user.present? @@ -195,8 +193,8 @@ def send_to_res(user) def send_vre_email_form(user) email_addr = REGIONAL_OFFICE_EMAILS[@office_location] || 'VRE.VBACO@va.gov' - log_message_to_sentry("VRE claim email: #{email_addr}, sent to cmp: #{@sent_to_cmp} #{user.present?}", - :info, { uuid: user.uuid }) + Rails.logger.info("VRE claim email: #{email_addr}. user uuid: #{user.uuid}.\ + sent to cmp: #{@sent_to_cmp} #{user.present?}") VeteranReadinessEmploymentMailer.build(user.participant_id, email_addr, @sent_to_cmp).deliver_later if user.present? @@ -239,6 +237,14 @@ def send_central_mail_confirmation_email(user) ) end + def process_attachments! + refs = attachment_keys.map { |key| Array(open_struct_form.send(key)) }.flatten + files = PersistentAttachment.where(guid: refs.map(&:confirmationCode)) + files.find_each { |f| f.update(saved_claim_id: id) } + + Lighthouse::SubmitBenefitsIntakeClaim.new.perform(id) + end + def business_line 'VRE' end @@ -258,7 +264,7 @@ def check_office_location regional_office_response[:regional_office][:name] ] rescue => e - log_message_to_sentry(e.message, :warn, {}, { team: 'vfs-ebenefits' }) + Rails.logger.warn(e.message) ['000', 'Not Found'] end diff --git a/lib/res/ch31_form.rb b/lib/res/ch31_form.rb index d0d55248d5a..38404f05be0 100644 --- a/lib/res/ch31_form.rb +++ b/lib/res/ch31_form.rb @@ -9,7 +9,6 @@ class Ch31Form < RES::Service include SentryLogging configuration RES::Configuration STATSD_KEY_PREFIX = 'api.res' - SENTRY_TAG = { team: 'vfs-ebenefits' }.freeze def initialize(user:, claim:) super() @@ -23,13 +22,7 @@ def initialize(user:, claim:) # def submit if @claim.nil? - log_exception_to_sentry( - 'Ch31NilClaimError', - { - icn: @user.icn - }, - SENTRY_TAG - ) + Rails.logger.error("Ch31NilClaimError. user icn: #{@user.icn}") raise Ch31NilClaimError end @@ -137,14 +130,11 @@ def mapped_address_hash(client_hash) end def process_ch_31_error(e, response_body) - log_exception_to_sentry( - e, - { - intake_id: response_body['ApplicationIntake'], - error_message: response_body['ErrorMessage'] - }, - SENTRY_TAG - ) + Rails.logger.error(e) + Rails.logger.error({ + intake_id: response_body['ApplicationIntake'], + error_message: response_body['ErrorMessage'] + }) end end end diff --git a/spec/models/saved_claim/veteran_readiness_employment_claim_spec.rb b/spec/models/saved_claim/veteran_readiness_employment_claim_spec.rb index 744a625df16..b82426dd530 100644 --- a/spec/models/saved_claim/veteran_readiness_employment_claim_spec.rb +++ b/spec/models/saved_claim/veteran_readiness_employment_claim_spec.rb @@ -128,6 +128,7 @@ let(:user_object) { create(:unauthorized_evss_user) } it 'PDF is sent to Central Mail and not VBMS' do + expect(claim).to receive(:process_attachments!) expect(claim).to receive(:send_to_central_mail!).with(user_object).once.and_call_original expect(claim).to receive(:send_central_mail_confirmation_email) expect(claim).not_to receive(:upload_to_vbms) From 86c6d4956ae051e95dd934ea7a8200ff5ce6efb8 Mon Sep 17 00:00:00 2001 From: Tyler Fink Date: Wed, 29 May 2024 14:16:51 -0600 Subject: [PATCH 22/28] Rename central mail method to refer lighthouse --- .../veteran_readiness_employment_claim.rb | 10 +++++----- .../veteran_readiness_employment_claim_spec.rb | 14 +++++++------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/models/saved_claim/veteran_readiness_employment_claim.rb b/app/models/saved_claim/veteran_readiness_employment_claim.rb index f355113459c..793eb73ab8b 100644 --- a/app/models/saved_claim/veteran_readiness_employment_claim.rb +++ b/app/models/saved_claim/veteran_readiness_employment_claim.rb @@ -122,7 +122,7 @@ def send_to_vre(user) upload_to_vbms(user:) else Rails.logger.warn('Participane.messaget id is blank when submitting VRE claim') - send_to_central_mail!(user) + send_to_lighthouse!(user) end if Flipper.enabled?(:veteran_readiness_employment_to_res) @@ -154,14 +154,14 @@ def upload_to_vbms(user:, doc_type: '1167') send_vbms_confirmation_email(user) rescue Rails.logger.error("Error uploading VRE claim to VBMS. user uuid: #{user.uuid}") - send_to_central_mail!(user) + send_to_lighthouse!(user) end def to_pdf(file_name = nil) PdfFill::Filler.fill_form(self, file_name, { created_at: }) end - def send_to_central_mail!(user) + def send_to_lighthouse!(user) form_copy = parsed_form.clone form_copy['veteranSocialSecurityNumber'] = parsed_form.dig('veteranInformation', 'ssn') @@ -173,7 +173,7 @@ def send_to_central_mail!(user) process_attachments! @sent_to_cmp = true - send_central_mail_confirmation_email(user) + send_lighthouse_confirmation_email(user) rescue => e Rails.logger.error("Error uploading VRE claim to central mail. user uuid: #{user.uuid}. #{e}") end @@ -224,7 +224,7 @@ def send_vbms_confirmation_email(user) ) end - def send_central_mail_confirmation_email(user) + def send_lighthouse_confirmation_email(user) return if user.va_profile_email.blank? VANotify::EmailJob.perform_async( diff --git a/spec/models/saved_claim/veteran_readiness_employment_claim_spec.rb b/spec/models/saved_claim/veteran_readiness_employment_claim_spec.rb index b82426dd530..f821c315c7d 100644 --- a/spec/models/saved_claim/veteran_readiness_employment_claim_spec.rb +++ b/spec/models/saved_claim/veteran_readiness_employment_claim_spec.rb @@ -66,13 +66,13 @@ allow(VBMS::Client).to receive(:from_env_vars).and_return(@vbms_client) end - it 'calls #send_to_central_mail!' do - expect(claim).to receive(:send_to_central_mail!) + it 'calls #send_to_lighthouse!' do + expect(claim).to receive(:send_to_lighthouse!) subject end it 'does not raise an error' do - allow(claim).to receive(:send_to_central_mail!) + allow(claim).to receive(:send_to_lighthouse!) expect { subject }.not_to raise_error end end @@ -129,8 +129,8 @@ it 'PDF is sent to Central Mail and not VBMS' do expect(claim).to receive(:process_attachments!) - expect(claim).to receive(:send_to_central_mail!).with(user_object).once.and_call_original - expect(claim).to receive(:send_central_mail_confirmation_email) + expect(claim).to receive(:send_to_lighthouse!).with(user_object).once.and_call_original + expect(claim).to receive(:send_lighthouse_confirmation_email) expect(claim).not_to receive(:upload_to_vbms) expect(VeteranReadinessEmploymentMailer).to receive(:build).with( user_object.participant_id, 'VRE.VBAPIT@va.gov', true @@ -163,8 +163,8 @@ end end - describe '#send_central_mail_confirmation_email' do - subject { claim.send_central_mail_confirmation_email(user_object) } + describe '#send_lighthouse_confirmation_email' do + subject { claim.send_lighthouse_confirmation_email(user_object) } it 'calls the VA notify email job' do expect(VANotify::EmailJob).to receive(:perform_async).with( From b3086a1bab5f3cb6732c72be4d64763abc78a0d7 Mon Sep 17 00:00:00 2001 From: Tyler Fink Date: Wed, 29 May 2024 14:24:36 -0600 Subject: [PATCH 23/28] Fix message --- app/models/saved_claim/veteran_readiness_employment_claim.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/saved_claim/veteran_readiness_employment_claim.rb b/app/models/saved_claim/veteran_readiness_employment_claim.rb index 793eb73ab8b..1d43c9218ce 100644 --- a/app/models/saved_claim/veteran_readiness_employment_claim.rb +++ b/app/models/saved_claim/veteran_readiness_employment_claim.rb @@ -121,7 +121,7 @@ def send_to_vre(user) if user&.participant_id upload_to_vbms(user:) else - Rails.logger.warn('Participane.messaget id is blank when submitting VRE claim') + Rails.logger.warn('Participant id is blank when submitting VRE claim') send_to_lighthouse!(user) end From ccb9d8f72c97b99aeccaa60f2149f8c8592b07d0 Mon Sep 17 00:00:00 2001 From: Tyler Fink Date: Wed, 29 May 2024 15:14:27 -0600 Subject: [PATCH 24/28] Remove checks for sentry logging --- spec/lib/res/ch31_form_spec.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/spec/lib/res/ch31_form_spec.rb b/spec/lib/res/ch31_form_spec.rb index a33d1071594..871f81e01a9 100644 --- a/spec/lib/res/ch31_form_spec.rb +++ b/spec/lib/res/ch31_form_spec.rb @@ -45,7 +45,6 @@ context 'with an unsuccessful submission' do it 'does not successfully send to RES' do - expect(service).to receive(:log_exception_to_sentry) allow(service).to receive(:send_to_res).and_return(OpenStruct.new(body: { 'error' => 'Error' })) expect { service.submit }.to raise_error(Ch31Error) @@ -53,7 +52,6 @@ it 'handles nil claim' do nil_claim_service = RES::Ch31Form.new(user:, claim: nil) - expect(nil_claim_service).to receive(:log_exception_to_sentry) expect { nil_claim_service.submit }.to raise_error(Ch31NilClaimError) end From bc33b0268666af75526fccea2974af810b6064e4 Mon Sep 17 00:00:00 2001 From: Tyler Fink Date: Wed, 29 May 2024 15:32:09 -0600 Subject: [PATCH 25/28] Fix spec --- spec/sidekiq/vre/submit1900_job_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/sidekiq/vre/submit1900_job_spec.rb b/spec/sidekiq/vre/submit1900_job_spec.rb index 7e2025e7d85..de75d36101b 100644 --- a/spec/sidekiq/vre/submit1900_job_spec.rb +++ b/spec/sidekiq/vre/submit1900_job_spec.rb @@ -19,7 +19,7 @@ end it 'calls claim.add_claimant_info' do - allow(claim).to receive(:send_to_central_mail!) + allow(claim).to receive(:send_to_lighthouse!) allow(claim).to receive(:send_to_res) expect(claim).to receive(:add_claimant_info).with(user) From d52ea750f581fb8e4fce5392aa97411f7506e4ee Mon Sep 17 00:00:00 2001 From: Tyler Fink Date: Thu, 30 May 2024 11:14:44 -0600 Subject: [PATCH 26/28] change logger method syntax, rename boolean --- .../veteran_readiness_employment_claim.rb | 38 ++++++++++++++----- lib/res/ch31_form.rb | 2 +- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/app/models/saved_claim/veteran_readiness_employment_claim.rb b/app/models/saved_claim/veteran_readiness_employment_claim.rb index 1d43c9218ce..7182aee0d4f 100644 --- a/app/models/saved_claim/veteran_readiness_employment_claim.rb +++ b/app/models/saved_claim/veteran_readiness_employment_claim.rb @@ -75,7 +75,7 @@ class SavedClaim::VeteranReadinessEmploymentClaim < SavedClaim }.freeze def initialize(args) - @sent_to_cmp = false + @sent_to_lighthouse = false super end @@ -171,7 +171,7 @@ def send_to_lighthouse!(user) update!(form: form_copy.to_json) process_attachments! - @sent_to_cmp = true + @sent_to_lighthouse = true send_lighthouse_confirmation_email(user) rescue => e @@ -181,10 +181,19 @@ def send_to_lighthouse!(user) def send_to_res(user) email_addr = REGIONAL_OFFICE_EMAILS[@office_location] || 'VRE.VBACO@va.gov' - Rails.logger.info("VRE claim email: #{email_addr}. user uuid: #{user.uuid}.\ - sent to cmp: #{@sent_to_cmp} #{user.present?}") - - VeteranReadinessEmploymentMailer.build(user.participant_id, email_addr, @sent_to_cmp).deliver_later if user.present? + Rails.logger.info('VRE claim email: ', + email_addr, + '. user uuid: ', + user.uuid, + '. sent to lighthouse: ', + @sent_to_lighthouse, + '. user present: ', + user.present?) + + if user.present? + VeteranReadinessEmploymentMailer.build(user.participant_id, email_addr, + @sent_to_lighthouse).deliver_later + end service = RES::Ch31Form.new(user:, claim: self) service.submit @@ -193,10 +202,19 @@ def send_to_res(user) def send_vre_email_form(user) email_addr = REGIONAL_OFFICE_EMAILS[@office_location] || 'VRE.VBACO@va.gov' - Rails.logger.info("VRE claim email: #{email_addr}. user uuid: #{user.uuid}.\ - sent to cmp: #{@sent_to_cmp} #{user.present?}") - - VeteranReadinessEmploymentMailer.build(user.participant_id, email_addr, @sent_to_cmp).deliver_later if user.present? + Rails.logger.info('VRE claim email: ', + email_addr, + '. user uuid: ', + user.uuid, + '. sent to lighthouse: ', + @sent_to_lighthouse, + '. user present: ', + user.present?) + + if user.present? + VeteranReadinessEmploymentMailer.build(user.participant_id, email_addr, + @sent_to_lighthouse).deliver_later + end # During Roll out our partners ask that we check vet location and if within proximity to specific offices, # send the data to them. We always send a pdf to VBMS diff --git a/lib/res/ch31_form.rb b/lib/res/ch31_form.rb index 38404f05be0..6cc692f608b 100644 --- a/lib/res/ch31_form.rb +++ b/lib/res/ch31_form.rb @@ -22,7 +22,7 @@ def initialize(user:, claim:) # def submit if @claim.nil? - Rails.logger.error("Ch31NilClaimError. user icn: #{@user.icn}") + Rails.logger.error('Ch31NilClaimError. user icn:', @user.icn) raise Ch31NilClaimError end From 5474e8e7d6b78ed6a608f1995fc8128e11f92f32 Mon Sep 17 00:00:00 2001 From: Tyler Fink Date: Thu, 30 May 2024 11:22:15 -0600 Subject: [PATCH 27/28] Reupdate logger message --- .../veteran_readiness_employment_claim.rb | 30 +++++++++---------- lib/res/ch31_form.rb | 5 ---- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/app/models/saved_claim/veteran_readiness_employment_claim.rb b/app/models/saved_claim/veteran_readiness_employment_claim.rb index 7182aee0d4f..ef7128f0f3a 100644 --- a/app/models/saved_claim/veteran_readiness_employment_claim.rb +++ b/app/models/saved_claim/veteran_readiness_employment_claim.rb @@ -181,14 +181,13 @@ def send_to_lighthouse!(user) def send_to_res(user) email_addr = REGIONAL_OFFICE_EMAILS[@office_location] || 'VRE.VBACO@va.gov' - Rails.logger.info('VRE claim email: ', - email_addr, - '. user uuid: ', - user.uuid, - '. sent to lighthouse: ', - @sent_to_lighthouse, - '. user present: ', - user.present?) + Rails.logger.info('VRE claim sending to RES service', + { + email: email_addr, + user_uuid: user.uuid, + was_sent: @sent_to_lighthouse, + user_present: user.present? + }) if user.present? VeteranReadinessEmploymentMailer.build(user.participant_id, email_addr, @@ -202,14 +201,13 @@ def send_to_res(user) def send_vre_email_form(user) email_addr = REGIONAL_OFFICE_EMAILS[@office_location] || 'VRE.VBACO@va.gov' - Rails.logger.info('VRE claim email: ', - email_addr, - '. user uuid: ', - user.uuid, - '. sent to lighthouse: ', - @sent_to_lighthouse, - '. user present: ', - user.present?) + Rails.logger.info('VRE claim sending to VRE service', + { + email: email_addr, + user_uuid: user.uuid, + was_sent: @sent_to_lighthouse, + user_present: user.present? + }) if user.present? VeteranReadinessEmploymentMailer.build(user.participant_id, email_addr, diff --git a/lib/res/ch31_form.rb b/lib/res/ch31_form.rb index 6cc692f608b..1a44dadc47c 100644 --- a/lib/res/ch31_form.rb +++ b/lib/res/ch31_form.rb @@ -116,13 +116,8 @@ def new_address def mapped_address_hash(client_hash) { - # isForeign: client_hash['country'] != 'USA', - # isMilitary: client_hash['isMilitary'] || false, country: client_hash['country'], street: client_hash['street'], - # addressLine1: client_hash['street'], - # addressLine2: client_hash['street2'], - # addressLine3: client_hash['street3'], city: client_hash['city'], state: client_hash['state'], postalCode: client_hash['postalCode'] From 5b142cfa30d485dbe3de14ec079cfa0d02104645 Mon Sep 17 00:00:00 2001 From: Tyler Fink Date: Thu, 30 May 2024 11:24:31 -0600 Subject: [PATCH 28/28] other logger messages --- app/models/saved_claim/veteran_readiness_employment_claim.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/saved_claim/veteran_readiness_employment_claim.rb b/app/models/saved_claim/veteran_readiness_employment_claim.rb index ef7128f0f3a..2ccb3a13771 100644 --- a/app/models/saved_claim/veteran_readiness_employment_claim.rb +++ b/app/models/saved_claim/veteran_readiness_employment_claim.rb @@ -153,7 +153,7 @@ def upload_to_vbms(user:, doc_type: '1167') send_vbms_confirmation_email(user) rescue - Rails.logger.error("Error uploading VRE claim to VBMS. user uuid: #{user.uuid}") + Rails.logger.error('Error uploading VRE claim to VBMS.', { user_uuid: user.uuid }) send_to_lighthouse!(user) end @@ -175,7 +175,7 @@ def send_to_lighthouse!(user) send_lighthouse_confirmation_email(user) rescue => e - Rails.logger.error("Error uploading VRE claim to central mail. user uuid: #{user.uuid}. #{e}") + Rails.logger.error('Error uploading VRE claim to central mail.', { user_uuid: user.uuid, e: }) end def send_to_res(user)