diff --git a/app/models/form526_submission.rb b/app/models/form526_submission.rb index bc4975d2d8e..e08e952c3e8 100644 --- a/app/models/form526_submission.rb +++ b/app/models/form526_submission.rb @@ -23,9 +23,7 @@ class Form526Submission < ApplicationRecord :submit_flashes, :poll_form526_pdf, :cleanup, - additional_class_logs: { - action: 'Begin as anciliary 526 submission' - }, + additional_class_logs: { action: 'Begin as anciliary 526 submission' }, additional_instance_logs: { saved_claim_id: %i[saved_claim id], user_uuid: %i[user_uuid] @@ -54,13 +52,11 @@ class Form526Submission < ApplicationRecord has_kms_key has_encrypted :auth_headers_json, :birls_ids_tried, :form_json, key: :kms_key, **lockbox_options - belongs_to :saved_claim, - class_name: 'SavedClaim::DisabilityCompensation', - inverse_of: false + belongs_to :saved_claim, class_name: 'SavedClaim::DisabilityCompensation', inverse_of: false has_many :form526_job_statuses, dependent: :destroy has_many :form526_submission_remediations, dependent: :destroy - belongs_to :user_account, dependent: nil, optional: true + belongs_to :user_account, dependent: nil validates(:auth_headers_json, presence: true) enum :backup_submitted_claim_status, { accepted: 0, rejected: 1, paranoid_success: 2 } @@ -163,9 +159,7 @@ def submit_with_birls_id_that_hasnt_been_tried_yet!( # Note that the User record is cached in Redis -- `User.redis_namespace_ttl` def get_first_name - user = User.find(user_uuid) - user&.first_name&.upcase.presence || - auth_headers&.dig('va_eauth_firstName')&.upcase + user&.first_name&.upcase.presence || auth_headers&.dig('va_eauth_firstName')&.upcase end # Checks against the User record first, and then resorts to checking the auth_headers @@ -174,15 +168,13 @@ def get_first_name # @return [Hash] of the user's full name (first, middle, last, suffix) # def full_name - name_hash = User.find(user_uuid)&.full_name_normalized + name_hash = user&.full_name_normalized return name_hash if name_hash&.[](:first).present? - { - first: auth_headers&.dig('va_eauth_firstName')&.capitalize, + { first: auth_headers&.dig('va_eauth_firstName')&.capitalize, middle: nil, last: auth_headers&.dig('va_eauth_lastName')&.capitalize, - suffix: nil - } + suffix: nil } end # form_json is memoized here so call invalidate_form_hash after updating form_json @@ -468,22 +460,11 @@ def last_remediation end def account - # first, check for an ICN on the UserAccount associated to the submission, return it if found - account = user_account - return account if account&.icn.present? - - # next, check past submissions for different UserAccounts that might have ICNs - past_submissions = get_past_submissions - account = find_user_account_with_icn(past_submissions, 'past submissions') - return account if account.present? && account.icn.present? - - # next, check for any historical UserAccounts for that user which might have an ICN - user_verifications = get_user_verifications - account = find_user_account_with_icn(user_verifications, 'user verifications') - return account if account.present? && account.icn.present? + return user_account if user_account&.icn.present? - # failing all the above, default to an Account lookup - Account.lookup_by_user_uuid(user_uuid) + Rails.logger.info('Form526Submission::account - no UserAccount ICN found', log_payload) + # query MPI by EDIPI first & attributes second for user ICN, return in OpenStruct + get_icn_from_mpi end # Send the Submitted Email - when the Veteran has clicked the "submit" button in va.gov @@ -493,8 +474,7 @@ def account # @param invoker: string where the Received Email trigger is being called from def send_submitted_email(invoker) if Flipper.enabled?(:disability_526_send_form526_submitted_email) - Rails.logger.info("Form526SubmittedEmailJob called for user #{user_uuid}, - submission: #{id} from #{invoker}") + Rails.logger.info("Form526SubmittedEmailJob called for user #{user_uuid}, submission: #{id} from #{invoker}") first_name = get_first_name params = personalization_parameters(first_name) Form526SubmittedEmailJob.perform_async(params) @@ -506,8 +486,7 @@ def send_submitted_email(invoker) # Backup Path: when Form526StatusPollingJob reaches "paranoid_success" status # @param invoker: string where the Received Email trigger is being called from def send_received_email(invoker) - Rails.logger.info("Form526ConfirmationEmailJob called for user #{user_uuid}, - submission: #{id} from #{invoker}") + Rails.logger.info("Form526ConfirmationEmailJob called for user #{user_uuid}, submission: #{id} from #{invoker}") first_name = get_first_name params = personalization_parameters(first_name) Form526ConfirmationEmailJob.perform_async(params) @@ -612,7 +591,6 @@ def submit_form_8940 end def submit_flashes - user = User.find(user_uuid) # Note that the User record is cached in Redis -- `User.redis_namespace_ttl` # If this method runs after the TTL, then the flashes will not be applied -- a possible bug. BGS::FlashUpdater.perform_async(id) if user && Flipper.enabled?(:disability_compensation_flashes, user) @@ -630,27 +608,51 @@ def cleanup EVSS::DisabilityCompensationForm::SubmitForm526Cleanup.perform_async(id) end - def find_user_account_with_icn(records, record_type) - records.pluck(:user_account_id).uniq.each do |user_account_id| - user_account = UserAccount.find(user_account_id) - next if user_account&.icn.blank? - - Rails.logger.info("ICN not found on submission #{id}, " \ - "using ICN for user account #{user_account_id} instead (based on #{record_type})") - return user_account + def get_icn_from_mpi + edipi_response_profile = edipi_mpi_profile_query(auth_headers['va_eauth_dodedipnid']) + if edipi_response_profile&.icn.present? + OpenStruct.new(icn: edipi_response_profile.icn) + else + Rails.logger.info('Form526Submission::account - unable to look up MPI profile with EDIPI', log_payload) + attributes_response_profile = attributes_mpi_profile_query(auth_headers) + if attributes_response_profile&.icn.present? + OpenStruct.new(icn: attributes_response_profile.icn) + else + Rails.logger.info('Form526Submission::account - no ICN present', log_payload) + OpenStruct.new(icn: nil) + end end end - def get_past_submissions - Form526Submission.where(user_uuid:).where.not(user_account_id:) + def edipi_mpi_profile_query(edipi) + return unless edipi + + edipi_response = mpi_service.find_profile_by_edipi(edipi:) + edipi_response.profile if edipi_response.ok? && edipi_response.profile.icn.present? + end + + def attributes_mpi_profile_query(auth_headers) + required_attributes = %w[va_eauth_firstName va_eauth_lastName va_eauth_birthdate va_eauth_pnid] + return unless required_attributes.all? { |attr| auth_headers[attr].present? } + + attributes_response = mpi_service.find_profile_by_attributes( + first_name: auth_headers['va_eauth_firstName'], + last_name: auth_headers['va_eauth_lastName'], + birth_date: auth_headers['va_eauth_birthdate']&.to_date.to_s, + ssn: auth_headers['va_eauth_pnid'] + ) + attributes_response.profile if attributes_response.ok? && attributes_response.profile.icn.present? + end + + def log_payload + @log_payload ||= { user_uuid:, submission_id: id } + end + + def mpi_service + @mpi_service ||= MPI::Service.new end - def get_user_verifications - UserVerification.where(idme_uuid: user_uuid) - .or(UserVerification.where(backing_idme_uuid: user_uuid)) - .or(UserVerification.where(logingov_uuid: user_uuid)) - .or(UserVerification.where(mhv_uuid: user_uuid)) - .or(UserVerification.where(dslogon_uuid: user_uuid)) - .where.not(user_account_id:) + def user + @user ||= User.find(user_uuid) end end diff --git a/rakelib/form526.rake b/rakelib/form526.rake index 1ee1b31f370..1722180f4c7 100644 --- a/rakelib/form526.rake +++ b/rakelib/form526.rake @@ -518,11 +518,15 @@ namespace :form526 do end vname = "#{fs.auth_headers['va_eauth_firstName']} #{fs.auth_headers['va_eauth_lastName']}" - icn = Account.lookup_by_user_uuid(fs.user_uuid).first&.icn + icn = fs.user_account&.icn if icn.blank? - # TODO: make this work for blank icn's - puts "icn blank #{fs.id}" - next + mpi_response = MPI::Service.new.find_profile_by_edipi(edipi: fs['va_eauth_dodedipnid']) + if mpi_response.ok? && mpi_response.profile.icn.present? + icn = mpi_response.profile.icn + else + puts "icn blank #{fs.id}" + next + end end user = OpenStruct.new(participant_id: fs.auth_headers['va_eauth_pid'], icn:, common_name: vname, ssn:) @@ -684,42 +688,26 @@ namespace :form526 do desc 'pretty print MPI profile for submission' task mpi: :environment do |_, args| def puts_mpi_profile(submission) - ids = {} - ids[:edipi] = edipi submission.auth_headers - ids[:icn] = icn ids[:edipi] + edipi = submission.auth_headers['va_eauth_dodedipnid'] + raise Error, 'no edipi' unless edipi - pp mpi_profile(user_identity(**ids)).as_json + ids = { edipi:, icn: submission.user_account&.icn } + + pp mpi_profile(ids).as_json end - def mpi_profile(user_identity) - if user_identity.mhv_icn - find_profile_response = MPI::Service.new.find_profile_by_identifier(identifier: user_identity.mhv_icn, + def mpi_profile(ids) + if ids[:icn] + find_profile_response = MPI::Service.new.find_profile_by_identifier(identifier: ids[:icn], identifier_type: MPI::Constants::ICN) else - find_profile_response = MPI::Service.new.find_profile_by_edipi(edipi: user_identity.edipi) + find_profile_response = MPI::Service.new.find_profile_by_edipi(edipi: ids[:edipi]) end raise find_profile_response.error if find_profile_response.error find_profile_response.profile end - def user_identity(icn:, edipi:) - OpenStruct.new mhv_icn: icn, edipi: - end - - def edipi(auth_headers) - auth_headers['va_eauth_dodedipnid'] - end - - def icn(edipi) - raise Error, 'no edipi' unless edipi - - icns = Account.where(edipi:).pluck :icn - raise Error, 'multiple icns' if icns.uniq.length > 1 - - icns.first - end - Form526Submission.where(id: args.extras).find_each { |sub| puts_mpi_profile sub } end diff --git a/spec/factories/form526_submissions.rb b/spec/factories/form526_submissions.rb index 27ebdc9cbee..86f358d9716 100644 --- a/spec/factories/form526_submissions.rb +++ b/spec/factories/form526_submissions.rb @@ -3,9 +3,11 @@ FactoryBot.define do factory :form526_submission do transient do - user { create(:disabilities_compensation_user) } + user_verification { create(:idme_user_verification) } + user { create(:disabilities_compensation_user, idme_uuid: user_verification.idme_uuid) } submissions_path { Rails.root.join(*'/spec/support/disability_compensation_form/submissions'.split('/')).to_s } end + user_account { user_verification.user_account } user_uuid { user.uuid } saved_claim { create(:va526ez) } submitted_claim_id { nil } diff --git a/spec/lib/sidekiq/form526_backup_submission_process/processor_spec.rb b/spec/lib/sidekiq/form526_backup_submission_process/processor_spec.rb index f0227305a01..7011b801ebd 100644 --- a/spec/lib/sidekiq/form526_backup_submission_process/processor_spec.rb +++ b/spec/lib/sidekiq/form526_backup_submission_process/processor_spec.rb @@ -28,8 +28,10 @@ end describe '#choose_provider' do - let(:account) { create(:account) } - let(:submission) { create(:form526_submission, user_uuid: account.idme_uuid, submit_endpoint: 'claims_api') } + let(:user) { create(:user, :loa3, :with_terms_of_use_agreement) } + let(:user_account) { user.user_account } + let(:icn) { user_account.icn } + let(:submission) { create(:form526_submission, user_account:, submit_endpoint: 'claims_api') } it 'delegates to the ApiProviderFactory with the correct data' do auth_headers = {} @@ -38,7 +40,7 @@ type: ApiProviderFactory::FACTORIES[:generate_pdf], provider: ApiProviderFactory::API_PROVIDER[:lighthouse], options: { auth_headers:, breakered: true }, - current_user: OpenStruct.new({ flipper_id: submission.user_uuid, icn: account.icn }), + current_user: OpenStruct.new({ flipper_id: submission.user_uuid, icn: }), feature_toggle: nil } ) @@ -59,7 +61,7 @@ type: ApiProviderFactory::FACTORIES[:generate_pdf], provider: ApiProviderFactory::API_PROVIDER[:lighthouse], options: { auth_headers: submission.auth_headers, breakered: true }, - current_user: OpenStruct.new({ flipper_id: submission.user_uuid, icn: account.icn }), + current_user: OpenStruct.new({ flipper_id: submission.user_uuid, icn: }), feature_toggle: nil } ).and_call_original diff --git a/spec/lib/sidekiq/form526_backup_submission_process/submit_spec.rb b/spec/lib/sidekiq/form526_backup_submission_process/submit_spec.rb index 18627e39afd..b3336161bfe 100644 --- a/spec/lib/sidekiq/form526_backup_submission_process/submit_spec.rb +++ b/spec/lib/sidekiq/form526_backup_submission_process/submit_spec.rb @@ -16,7 +16,8 @@ .and_return('access_token') end - let(:user) { create(:user, :loa3) } + let(:user_account) { create(:user_account, icn: '123498767V234859') } + let(:user) { create(:user, :loa3, icn: user_account.icn) } let(:auth_headers) do EVSS::DisabilityCompensationAuthHeaders.new(user).add_headers(EVSS::AuthHeaders.new(user).to_h) end @@ -27,7 +28,7 @@ allow(Settings.form526_backup).to receive(:enabled).and_return(false) end - let!(:submission) { create(:form526_submission, :with_everything) } + let!(:submission) { create(:form526_submission, :with_everything, user_account:) } it 'creates a submission job' do expect { subject.perform_async(submission.id) }.to change(subject.jobs, :size).by(1) @@ -42,7 +43,7 @@ let(:timestamp) { Time.now.utc } context 'when all retries are exhausted' do - let!(:form526_submission) { create(:form526_submission) } + let!(:form526_submission) { create(:form526_submission, user_account:) } let!(:form526_job_status) { create(:form526_job_status, :retryable_error, form526_submission:, job_id: 1) } it 'updates a StatsD counter and updates the status on an exhaustion event' do @@ -111,7 +112,7 @@ allow(Settings.form526_backup).to receive_messages(submission_method: payload_method, enabled: true) end - let!(:submission) { create(:form526_submission, :with_everything) } + let!(:submission) { create(:form526_submission, :with_everything, user_account:) } let!(:upload_data) { submission.form[Form526Submission::FORM_526_UPLOADS] } context 'successfully' do @@ -222,7 +223,7 @@ allow(Settings.form526_backup).to receive_messages(submission_method: 'single', enabled: true) end - let!(:submission) { create(:form526_submission, :with_non_pdf_uploads) } + let!(:submission) { create(:form526_submission, :with_non_pdf_uploads, user_account:) } let!(:upload_data) { submission.form[Form526Submission::FORM_526_UPLOADS] } context 'converts non-pdf files to pdf' do diff --git a/spec/lib/sidekiq/form526_job_status_tracker/job_tracker_spec.rb b/spec/lib/sidekiq/form526_job_status_tracker/job_tracker_spec.rb index 389ebe1b8c4..6a6e2c86b05 100644 --- a/spec/lib/sidekiq/form526_job_status_tracker/job_tracker_spec.rb +++ b/spec/lib/sidekiq/form526_job_status_tracker/job_tracker_spec.rb @@ -18,7 +18,8 @@ end context 'with an exhausted callback message' do - let!(:form526_submission) { create(:form526_submission) } + let(:user_account) { create(:user_account, icn: '123498767V234859') } + let!(:form526_submission) { create(:form526_submission, user_account:) } let!(:form526_job_status) do create(:form526_job_status, job_id: msg['jid'], form526_submission:) end diff --git a/spec/models/form526_submission_spec.rb b/spec/models/form526_submission_spec.rb index b3138b52c94..dbee68fda65 100644 --- a/spec/models/form526_submission_spec.rb +++ b/spec/models/form526_submission_spec.rb @@ -7,6 +7,7 @@ subject do Form526Submission.create( user_uuid: user.uuid, + user_account:, saved_claim_id: saved_claim.id, auth_headers_json: auth_headers.to_json, form_json:, @@ -15,8 +16,13 @@ ) end - let(:user) { create(:user, :loa3, first_name: 'Beyonce', last_name: 'Knowles') } - let(:user_account) { create(:user_account, icn: user.icn, id: user.user_account_uuid) } + let(:user_account) { create(:user_account) } + let(:user) do + create(:user, :loa3, first_name: 'Beyonce', + last_name: 'Knowles', + icn: user_account.icn, + idme_uuid: SecureRandom.uuid) + end let(:auth_headers) do EVSS::DisabilityCompensationAuthHeaders.new(user).add_headers(EVSS::AuthHeaders.new(user).to_h) end @@ -657,6 +663,7 @@ def expect_no_max_cfi_logged(diagnostic_code) headers = JSON.parse auth_headers.to_json Form526Submission.new( user_uuid: user.uuid, + user_account:, saved_claim_id: saved_claim.id, auth_headers_json: headers.to_json, form_json:, @@ -741,6 +748,7 @@ def expect_no_max_cfi_logged(diagnostic_code) headers['va_eauth_birlsfilenumber'] = birls_id Form526Submission.new( user_uuid: user.uuid, + user_account:, saved_claim_id: saved_claim.id, auth_headers_json: headers.to_json, form_json:, @@ -767,6 +775,7 @@ def expect_no_max_cfi_logged(diagnostic_code) subject do Form526Submission.new( user_uuid: user.uuid, + user_account:, saved_claim_id: saved_claim.id, form_json:, birls_ids_tried: birls_ids_tried.to_json @@ -793,6 +802,7 @@ def expect_no_max_cfi_logged(diagnostic_code) headers['va_eauth_birlsfilenumber'] = birls_id Form526Submission.new( user_uuid: user.uuid, + user_account:, saved_claim_id: saved_claim.id, auth_headers_json: headers.to_json, form_json:, @@ -835,6 +845,7 @@ def expect_no_max_cfi_logged(diagnostic_code) headers['va_eauth_birlsfilenumber'] = birls_id Form526Submission.new( user_uuid: user.uuid, + user_account:, saved_claim_id: saved_claim.id, auth_headers_json: headers.to_json, form_json:, @@ -1341,10 +1352,11 @@ def expect_no_max_cfi_logged(diagnostic_code) before { create(:idme_user_verification, idme_uuid: user.idme_uuid, user_account:) } + let(:user_account) { create(:user_account, icn: '123498767V234859') } let(:form_526_submission) do Form526Submission.create( user_uuid: user.uuid, - user_account: user.user_account, + user_account:, saved_claim_id: saved_claim.id, auth_headers_json: auth_headers.to_json, form_json: File.read("spec/support/disability_compensation_form/submissions/#{form_json_filename}") @@ -1563,72 +1575,97 @@ def expect_no_max_cfi_logged(diagnostic_code) end describe 'ICN retrieval' do - context 'various ICN retrieval scenarios' do - let(:user) { create(:user, :loa3) } - let(:auth_headers) do - EVSS::DisabilityCompensationAuthHeaders.new(user).add_headers(EVSS::AuthHeaders.new(user).to_h) - end - let(:submission) do - create(:form526_submission, - user_uuid: user.uuid, - auth_headers_json: auth_headers.to_json, - saved_claim_id: saved_claim.id) - end - let!(:form526_submission) { create(:form526_submission) } + let(:user) { create(:user, :loa3) } + let(:auth_headers) do + EVSS::DisabilityCompensationAuthHeaders.new(user).add_headers(EVSS::AuthHeaders.new(user).to_h) + end + let(:submission) do + create(:form526_submission, + user_uuid: user.uuid, + auth_headers_json: auth_headers.to_json, + saved_claim_id: saved_claim.id) + end + let!(:form526_submission) { create(:form526_submission) } + let(:expected_log_payload) { { user_uuid: user.uuid, submission_id: submission.id } } - it 'submissions user account has an ICN, as expected' do + context 'when the submission includes a UserAccount with an ICN, as expected' do + it 'uses the submission\'s user account ICN' do submission.user_account = UserAccount.new(icn: '123498767V222222') account = submission.account expect(account.icn).to eq('123498767V222222') end + end - it 'submissions user account has no ICN, default to Account lookup' do - submission.user_account = UserAccount.new(icn: nil) - account = submission.account - expect(account.icn).to eq('123498767V234859') - end + context 'when the submission does not have a UserAccount with an ICN' do + let(:mpi_profile) { build(:mpi_profile) } + let(:mpi_profile_response) { create(:find_profile_response, profile: mpi_profile) } + let(:edipi_profile_response) { mpi_profile_response } + let(:no_user_account_icn_message) { 'Form526Submission::account - no UserAccount ICN found' } - it 'submission has NO user account, default to Account lookup' do - account = submission.account - expect(account.icn).to eq('123498767V234859') + before do + allow_any_instance_of(MPI::Service).to receive(:find_profile_by_edipi).and_return(edipi_profile_response) end - it 'submissions user account has no ICN, lookup from past submissions' do - user_account_with_icn = UserAccount.create!(icn: '123498767V111111') - create(:form526_submission, user_uuid: submission.user_uuid, user_account: user_account_with_icn) + it 'uses the auth_headers EDIPI to look up account information from MPI' do submission.user_account = UserAccount.create!(icn: nil) submission.save! + expect(Rails.logger).to receive(:info).with(no_user_account_icn_message, expected_log_payload) + expect_any_instance_of(MPI::Service).to receive(:find_profile_by_edipi).with(edipi: user.edipi) account = submission.account - expect(account.icn).to eq('123498767V111111') + expect(account.icn).to eq(mpi_profile.icn) end - it 'lookup ICN from user verifications, idme_uuid defined' do - user_account_with_icn = UserAccount.create!(icn: '123498767V333333') - UserVerification.create!(idme_uuid: submission.user_uuid, user_account_id: user_account_with_icn.id) - submission.user_account = UserAccount.create!(icn: nil) - submission.save! - account = submission.account - expect(account.icn).to eq('123498767V333333') - end + context 'when the MPI lookup by EDIPI fails' do + let(:edipi_profile_response) { create(:find_profile_not_found_response) } + let(:attributes_profile_response) { mpi_profile_response } + let(:no_mpi_by_edipi_message) { 'Form526Submission::account - unable to look up MPI profile with EDIPI' } - it 'lookup ICN from user verifications, backing_idme_uuid defined' do - user_account_with_icn = UserAccount.create!(icn: '123498767V444444') - UserVerification.create!(dslogon_uuid: Faker::Internet.uuid, backing_idme_uuid: submission.user_uuid, - user_account_id: user_account_with_icn.id) - submission.user_account = UserAccount.create!(icn: nil) - submission.save! - account = submission.account - expect(account.icn).to eq('123498767V444444') - end + before do + allow(Rails.logger).to receive(:info).with(no_user_account_icn_message, + expected_log_payload).and_call_original + allow_any_instance_of(MPI::Service).to receive(:find_profile_by_attributes) + .and_return(attributes_profile_response) + end - it 'lookup ICN from user verifications, alternate provider id defined' do - user_account_with_icn = UserAccount.create!(icn: '123498767V555555') - UserVerification.create!(dslogon_uuid: submission.user_uuid, backing_idme_uuid: Faker::Internet.uuid, - user_account_id: user_account_with_icn.id) - submission.user_account = UserAccount.create!(icn: nil) - submission.save! - account = submission.account - expect(account.icn).to eq('123498767V555555') + it 'uses the auth_headers user attributes to look up account information from MPI' do + submission.user_account = UserAccount.create!(icn: nil) + submission.save! + expect(Rails.logger).to receive(:info).with(no_mpi_by_edipi_message, expected_log_payload) + expect_any_instance_of(MPI::Service).to receive(:find_profile_by_attributes).with( + first_name: user.first_name, + last_name: user.last_name, + ssn: user.ssn, + birth_date: user.birth_date + ) + account = submission.account + expect(account.icn).to eq(mpi_profile.icn) + end + + context 'when the MPI lookup by attributes fails' do + let(:attributes_profile_response) { create(:find_profile_not_found_response) } + let(:no_icn_found_message) { 'Form526Submission::account - no ICN present' } + + before do + allow(Rails.logger).to receive(:info).with(no_user_account_icn_message, + expected_log_payload).and_call_original + allow(Rails.logger).to receive(:info).with(no_mpi_by_edipi_message, expected_log_payload).and_call_original + end + + it 'does not return a UserAccount with an ICN' do + submission.user_account = UserAccount.create!(icn: nil) + submission.save! + expect_any_instance_of(MPI::Service).to receive(:find_profile_by_edipi).with(edipi: user.edipi) + expect_any_instance_of(MPI::Service).to receive(:find_profile_by_attributes).with( + first_name: user.first_name, + last_name: user.last_name, + ssn: user.ssn, + birth_date: user.birth_date + ) + expect(Rails.logger).to receive(:info).with(no_icn_found_message, expected_log_payload) + account = submission.account + expect(account.icn).to be_nil + end + end end end end diff --git a/spec/requests/v0/disability_compensation_form_spec.rb b/spec/requests/v0/disability_compensation_form_spec.rb index f10e38c1947..3872a009c3c 100644 --- a/spec/requests/v0/disability_compensation_form_spec.rb +++ b/spec/requests/v0/disability_compensation_form_spec.rb @@ -8,7 +8,7 @@ RSpec.describe 'V0::DisabilityCompensationForm', type: :request do include SchemaMatchers - let(:user) { build(:disabilities_compensation_user) } + let(:user) { build(:disabilities_compensation_user, :with_terms_of_use_agreement) } let(:headers) { { 'CONTENT_TYPE' => 'application/json' } } let(:headers_with_camel) { headers.merge('X-Key-Inflection' => 'camel') } @@ -289,7 +289,10 @@ def build_optional_xx_dates context 'with an `bdd` claim' do let(:bdd_form) { File.read 'spec/support/disability_compensation_form/bdd_fe_submission.json' } - let(:user) { build(:disabilities_compensation_user, icn: '1012666073V986297') } + let(:user) do + build(:disabilities_compensation_user, :with_terms_of_use_agreement, icn: '1012666073V986297', + idme_uuid: SecureRandom.uuid) + end before do allow_any_instance_of(Auth::ClientCredentials::Service).to receive(:get_token).and_return('fake_token') diff --git a/spec/sidekiq/central_mail/submit_form4142_job_spec.rb b/spec/sidekiq/central_mail/submit_form4142_job_spec.rb index e8f8b83af46..30fcedc6d2e 100644 --- a/spec/sidekiq/central_mail/submit_form4142_job_spec.rb +++ b/spec/sidekiq/central_mail/submit_form4142_job_spec.rb @@ -22,7 +22,8 @@ Flipper.disable(:disability_compensation_form4142_supplemental) end - let(:user) { create(:user, :loa3) } + let(:user_account) { user.user_account } + let(:user) { create(:user, :loa3, :with_terms_of_use_agreement) } let(:auth_headers) do EVSS::DisabilityCompensationAuthHeaders.new(user).add_headers(EVSS::AuthHeaders.new(user).to_h) end @@ -35,6 +36,7 @@ end let(:submission) do Form526Submission.create(user_uuid: user.uuid, + user_account:, auth_headers_json: auth_headers.to_json, saved_claim_id: saved_claim.id, form_json:, @@ -120,6 +122,7 @@ end let(:submission) do Form526Submission.create(user_uuid: user.uuid, + user_account:, auth_headers_json: auth_headers.to_json, saved_claim_id: saved_claim.id, form_json: missing_postalcode_form_json, @@ -138,7 +141,7 @@ context 'catastrophic failure state' do describe 'when all retries are exhausted' do - let!(:form526_submission) { create(:form526_submission) } + let!(:form526_submission) { create(:form526_submission, user_account:) } let!(:form526_job_status) { create(:form526_job_status, :retryable_error, form526_submission:, job_id: 1) } it 'updates a StatsD counter and updates the status on an exhaustion event' do @@ -172,7 +175,7 @@ timestamp: instance_of(Time), form526_submission_id: form526_submission.id }, - nil, + user_account.id, call_location: instance_of(Logging::CallLocation) ) @@ -201,7 +204,8 @@ Flipper.enable(:disability_compensation_form4142_supplemental) end - let(:user) { create(:user, :loa3) } + let(:user_account) { user.user_account } + let(:user) { create(:user, :loa3, :with_terms_of_use_agreement) } let(:auth_headers) do EVSS::DisabilityCompensationAuthHeaders.new(user).add_headers(EVSS::AuthHeaders.new(user).to_h) end @@ -214,6 +218,7 @@ end let(:submission) do Form526Submission.create(user_uuid: user.uuid, + user_account:, auth_headers_json: auth_headers.to_json, saved_claim_id: saved_claim.id, form_json:, @@ -349,6 +354,7 @@ end let(:submission) do Form526Submission.create(user_uuid: user.uuid, + user_account:, auth_headers_json: auth_headers.to_json, saved_claim_id: saved_claim.id, form_json: missing_postalcode_form_json, diff --git a/spec/sidekiq/evss/disability_compensation_form/submit_form0781_spec.rb b/spec/sidekiq/evss/disability_compensation_form/submit_form0781_spec.rb index 5d5d84fea5c..f78ad60b380 100644 --- a/spec/sidekiq/evss/disability_compensation_form/submit_form0781_spec.rb +++ b/spec/sidekiq/evss/disability_compensation_form/submit_form0781_spec.rb @@ -18,7 +18,8 @@ anything).and_return(false) end - let(:user) { create(:user, :loa3) } + let(:user) { create(:user, :loa3, :with_terms_of_use_agreement) } + let(:user_account) { user.user_account } let(:auth_headers) do EVSS::DisabilityCompensationAuthHeaders.new(user).add_headers(EVSS::AuthHeaders.new(user).to_h) end @@ -50,6 +51,7 @@ context 'when a submission has both 0781 and 0781a' do let(:submission) do Form526Submission.create(user_uuid: user.uuid, + user_account:, auth_headers_json: auth_headers.to_json, saved_claim_id: saved_claim.id, form_json: form0781, @@ -99,6 +101,7 @@ context 'when a submission has 0781v2' do let(:submission) do Form526Submission.create(user_uuid: user.uuid, + user_account:, auth_headers_json: auth_headers.to_json, saved_claim_id: saved_claim.id, form_json: form0781v2, @@ -148,7 +151,7 @@ context 'catastrophic failure state' do describe 'when all retries are exhausted' do - let!(:form526_submission) { create(:form526_submission) } + let!(:form526_submission) { create(:form526_submission, user_account:) } let!(:form526_job_status) { create(:form526_job_status, :retryable_error, form526_submission:, job_id: 1) } it 'updates a StatsD counter and updates the status on an exhaustion event' do @@ -184,7 +187,7 @@ timestamp: instance_of(Time), form526_submission_id: form526_submission.id }, - nil, + user_account.id, call_location: instance_of(Logging::CallLocation) ) @@ -307,6 +310,7 @@ let(:submission) do Form526Submission.create(user_uuid: user.uuid, + user_account:, auth_headers_json: auth_headers.to_json, saved_claim_id: saved_claim.id, form_json: form0781, # contains 0781 and 0781a @@ -701,6 +705,7 @@ let(:submission) do Form526Submission.create(user_uuid: user.uuid, + user_account:, auth_headers_json: auth_headers.to_json, saved_claim_id: saved_claim.id, form_json: form0781v2, diff --git a/spec/sidekiq/evss/disability_compensation_form/submit_form526_all_claim_spec.rb b/spec/sidekiq/evss/disability_compensation_form/submit_form526_all_claim_spec.rb index 9e005ad95ca..aa76eab73dc 100644 --- a/spec/sidekiq/evss/disability_compensation_form/submit_form526_all_claim_spec.rb +++ b/spec/sidekiq/evss/disability_compensation_form/submit_form526_all_claim_spec.rb @@ -25,7 +25,8 @@ .and_return('fake_access_token') end - let(:user) { create(:user, :loa3) } + let(:user) { create(:user, :loa3, icn: '123498767V234859') } + let(:user_account) { create(:user_account, icn: user.icn, id: user.user_account_uuid) } let(:auth_headers) do EVSS::DisabilityCompensationAuthHeaders.new(user).add_headers(EVSS::AuthHeaders.new(user).to_h) end @@ -35,10 +36,9 @@ let(:saved_claim) { create(:va526ez) } let(:submitted_claim_id) { 600_130_094 } - let(:user_account) { create(:user_account, icn: '123498767V234859') } let(:submission) do create(:form526_submission, - user_account_id: user_account.id, + user_account:, user_uuid: user.uuid, auth_headers_json: auth_headers.to_json, saved_claim_id: saved_claim.id) @@ -107,6 +107,7 @@ def submit_it create(:form526_submission, :asthma_claim_for_increase, user_uuid: user.uuid, + user_account:, auth_headers_json: auth_headers.to_json, saved_claim_id: saved_claim.id) end @@ -124,6 +125,7 @@ def submit_it create(:form526_submission, :without_diagnostic_code, user_uuid: user.uuid, + user_account:, auth_headers_json: auth_headers.to_json, saved_claim_id: saved_claim.id) end @@ -144,6 +146,7 @@ def submit_it create(:form526_submission, :als_claim_for_increase, user_uuid: user.uuid, + user_account:, auth_headers_json: auth_headers.to_json, saved_claim_id: saved_claim.id) end @@ -167,6 +170,7 @@ def submit_it create(:form526_submission, :als_claim_for_increase_terminally_ill, user_uuid: user.uuid, + user_account:, auth_headers_json: auth_headers.to_json, saved_claim_id: saved_claim.id) end @@ -195,6 +199,7 @@ def submit_it create(:form526_submission, :with_mixed_action_disabilities_and_free_text, user_uuid: user.uuid, + user_account:, auth_headers_json: auth_headers.to_json, saved_claim_id: saved_claim.id) end @@ -214,6 +219,7 @@ def submit_it create(:form526_submission, :without_diagnostic_code, user_uuid: user.uuid, + user_account:, auth_headers_json: auth_headers.to_json, saved_claim_id: saved_claim.id) end @@ -296,6 +302,7 @@ def submit_it create(:form526_submission, :with_empty_disabilities, user_uuid: user.uuid, + user_account:, auth_headers_json: auth_headers.to_json, saved_claim_id: saved_claim.id) end @@ -350,6 +357,7 @@ def submit_it create(:form526_submission, :non_rrd_with_mas_diagnostic_code, user_uuid: user.uuid, + user_account:, auth_headers_json: auth_headers.to_json, saved_claim_id: saved_claim.id) end @@ -396,6 +404,7 @@ def submit_it create(:form526_submission, :mas_diagnostic_code_with_classification, user_uuid: user.uuid, + user_account:, auth_headers_json: auth_headers.to_json, saved_claim_id: saved_claim.id) end @@ -429,6 +438,7 @@ def submit_it create(:form526_submission, :with_multiple_mas_diagnostic_code, user_uuid: user.uuid, + user_account:, auth_headers_json: auth_headers.to_json, saved_claim_id: saved_claim.id) end @@ -450,6 +460,7 @@ def submit_it create(:form526_submission, :with_everything, user_uuid: user.uuid, + user_account:, auth_headers_json: auth_headers.to_json, saved_claim_id: saved_claim.id, submit_endpoint: 'claims_api') @@ -560,6 +571,7 @@ def submit_it create(:form526_submission, :with_uploads, user_uuid: user.uuid, + user_account:, auth_headers_json: auth_headers.to_json, saved_claim_id: saved_claim.id) end diff --git a/spec/sidekiq/evss/disability_compensation_form/submit_uploads_spec.rb b/spec/sidekiq/evss/disability_compensation_form/submit_uploads_spec.rb index b36392f9b35..4d62dcd2582 100644 --- a/spec/sidekiq/evss/disability_compensation_form/submit_uploads_spec.rb +++ b/spec/sidekiq/evss/disability_compensation_form/submit_uploads_spec.rb @@ -12,7 +12,8 @@ Flipper.disable(:form526_send_document_upload_failure_notification) end - let(:user) { create(:user, :loa3) } + let(:user) { create(:user, :loa3, :with_terms_of_use_agreement) } + let(:user_account) { user.user_account } let(:auth_headers) do EVSS::DisabilityCompensationAuthHeaders.new(user).add_headers(EVSS::AuthHeaders.new(user).to_h) end @@ -20,6 +21,7 @@ let(:submission) do create(:form526_submission, :with_uploads, user_uuid: user.uuid, + user_account:, auth_headers_json: auth_headers.to_json, saved_claim_id: saved_claim.id, submitted_claim_id: '600130094') @@ -353,7 +355,7 @@ context 'catastrophic failure state' do describe 'when all retries are exhausted' do - let!(:form526_submission) { create(:form526_submission, :with_uploads) } + let!(:form526_submission) { create(:form526_submission, :with_uploads, user_account:) } let!(:form526_job_status) { create(:form526_job_status, :retryable_error, form526_submission:, job_id: 1) } it 'updates a StatsD counter and updates the status on an exhaustion event' do @@ -423,7 +425,7 @@ timestamp: instance_of(Time), form526_submission_id: submission.id }, - nil, + user_account.id, call_location: instance_of(Logging::CallLocation) )