diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 483f0de2b33..e3f0a685a5f 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -245,7 +245,6 @@ app/models/form1010cg/submission.rb @department-of-veterans-affairs/vfs-10-10 @d app/models/form1095_b.rb @department-of-veterans-affairs/vfs-1095-b @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group app/models/form526_job_status.rb @department-of-veterans-affairs/Disability-Experience @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group app/models/form526_submission.rb @department-of-veterans-affairs/Disability-Experience @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group -app/models/form5655_submission.rb @department-of-veterans-affairs/vsa-debt-resolution @department-of-veterans-affairs/backend-review-group app/models/form_attachment.rb @department-of-veterans-affairs/Benefits-Team-1 @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group app/models/form_profile.rb @department-of-veterans-affairs/vfs-authenticated-experience-backend @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group app/models/form_profiles @department-of-veterans-affairs/my-education-benefits @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group @@ -1427,7 +1426,6 @@ spec/models/form1010cg @department-of-veterans-affairs/vfs-10-10 @department-of- spec/models/form1095_b_spec.rb @department-of-veterans-affairs/vfs-1095-b @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group spec/models/form526_job_status_spec.rb @department-of-veterans-affairs/Disability-Experience @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group spec/models/form526_submission_spec.rb @department-of-veterans-affairs/Disability-Experience @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group -spec/models/form5655_submission_spec.rb @department-of-veterans-affairs/vsa-debt-resolution @department-of-veterans-affairs/backend-review-group spec/models/form_attachment_spec.rb @department-of-veterans-affairs/vfs-authenticated-experience-backend @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group spec/models/form_profile_spec.rb @department-of-veterans-affairs/vfs-authenticated-experience-backend @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group spec/models/form_submission_spec.rb @department-of-veterans-affairs/platform-va-product-forms @department-of-veterans-affairs/Disability-Experience @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group diff --git a/app/models/form5655_submission.rb b/app/models/form5655_submission.rb deleted file mode 100644 index f3ea67c89cd..00000000000 --- a/app/models/form5655_submission.rb +++ /dev/null @@ -1,62 +0,0 @@ -# frozen_string_literal: true - -require 'user_profile_attribute_service' - -class Form5655Submission < ApplicationRecord - class StaleUserError < StandardError; end - - enum state: { unassigned: 0, in_progress: 1, submitted: 2, failed: 3 } - - validates :user_uuid, presence: true - belongs_to :user_account, dependent: nil, optional: true - has_kms_key - has_encrypted :form_json, :metadata, key: :kms_key, **lockbox_options - - def kms_encryption_context(*) - { - model_name: model_name.to_s, - model_id: id - } - end - - scope :streamlined, -> { where("(public_metadata -> 'streamlined' ->> 'value')::boolean") } - scope :not_streamlined, -> { where.not("(public_metadata -> 'streamlined' ->> 'value')::boolean") } - scope :streamlined_unclear, -> { where("(public_metadata -> 'streamlined') IS NULL") } - scope :streamlined_nil, lambda { - where("(public_metadata -> 'streamlined') IS NOT NULL and " \ - "(public_metadata -> 'streamlined' ->> 'value') IS NULL") - } - - def public_metadata - super || {} - end - - def form - @form_hash ||= JSON.parse(form_json) - end - - def user_cache_id - user = User.find(user_uuid) - raise StaleUserError, user_uuid unless user - - UserProfileAttributeService.new(user).cache_profile_attributes - end - - def submit_to_vba - DebtsApi::V0::Form5655::VBASubmissionJob.perform_async(id, user_cache_id) - end - - def submit_to_vha - DebtsApi::V0::Form5655::VHASubmissionJob.perform_async(id, user_cache_id) - end - - def register_failure(message) - failed! - update(error_message: message) - Rails.logger.error('Form5655Submission failed', message) - end - - def streamlined? - public_metadata.dig('streamlined', 'value') == true - end -end diff --git a/modules/debts_api/app/models/debts_api/v0/form5655_submission.rb b/modules/debts_api/app/models/debts_api/v0/form5655_submission.rb index 64ab94ca8ff..9451214c3a3 100644 --- a/modules/debts_api/app/models/debts_api/v0/form5655_submission.rb +++ b/modules/debts_api/app/models/debts_api/v0/form5655_submission.rb @@ -16,7 +16,7 @@ class StaleUserError < StandardError; end def kms_encryption_context { - model_name: Form5655Submission.model_name.to_s, + model_name: 'Form5655Submission', model_id: id } end diff --git a/modules/debts_api/spec/lib/debt_api/v0/financial_status_report_service_spec.rb b/modules/debts_api/spec/lib/debt_api/v0/financial_status_report_service_spec.rb index fcfabe88a37..e743694e6e3 100644 --- a/modules/debts_api/spec/lib/debt_api/v0/financial_status_report_service_spec.rb +++ b/modules/debts_api/spec/lib/debt_api/v0/financial_status_report_service_spec.rb @@ -267,7 +267,9 @@ def mock_pdf_fill service = described_class.new(user) builder = DebtsApi::V0::FsrFormBuilder.new(vha_form_data, '', user) copay_count = builder.vha_forms.length - expect { service.submit_combined_fsr(builder) }.to change(Form5655Submission, :count).by(copay_count) + expect { service.submit_combined_fsr(builder) }.to change( + DebtsApi::V0::Form5655Submission, :count + ).by(copay_count) expect(DebtsApi::V0::Form5655Submission.last.in_progress?).to eq(true) form = service.send(:add_vha_specific_data, DebtsApi::V0::Form5655Submission.last) expect(form.class).to be(Hash) @@ -280,7 +282,9 @@ def mock_pdf_fill copay_count = builder.vha_forms.length debt_count = builder.vba_form.present? ? 1 : 0 needed_count = copay_count + debt_count - expect { service.submit_combined_fsr(builder) }.to change(Form5655Submission, :count).by(needed_count) + expect do + service.submit_combined_fsr(builder) + end.to change(DebtsApi::V0::Form5655Submission, :count).by(needed_count) expect(DebtsApi::V0::Form5655Submission.last.public_metadata['combined']).to eq(true) debt_amounts = DebtsApi::V0::Form5655Submission.with_debt_type('DEBT').last.public_metadata['debt_amounts'] expect(debt_amounts).to eq(['541.67', '1134.22']) @@ -300,13 +304,13 @@ def mock_pdf_fill it 'persists vba FSRs' do service = described_class.new(user) builder = DebtsApi::V0::FsrFormBuilder.new(valid_vba_form_data, '', user) - expect { service.create_vba_fsr(builder) }.to change(Form5655Submission, :count).by(1) + expect { service.create_vba_fsr(builder) }.to change(DebtsApi::V0::Form5655Submission, :count).by(1) end it 'gracefully handles a lack of vba FSRs' do service = described_class.new(user) builder = DebtsApi::V0::FsrFormBuilder.new(valid_vha_form_data, '', user) - expect { service.create_vba_fsr(builder) }.not_to change(Form5655Submission, :count) + expect { service.create_vba_fsr(builder) }.not_to change(DebtsApi::V0::Form5655Submission, :count) end end diff --git a/modules/debts_api/spec/models/debt_api/v0/form5655_submission_spec.rb b/modules/debts_api/spec/models/debt_api/v0/form5655_submission_spec.rb index 56de9a15da8..c9ef1655198 100644 --- a/modules/debts_api/spec/models/debt_api/v0/form5655_submission_spec.rb +++ b/modules/debts_api/spec/models/debt_api/v0/form5655_submission_spec.rb @@ -3,41 +3,39 @@ require 'rails_helper' RSpec.describe DebtsApi::V0::Form5655Submission do - describe 'namespace portability' do - let!(:some_record) do - create(:form5655_submission, public_metadata: { 'streamlined' => { 'type' => 'short', 'value' => true } }) - end - - it 'shares data with the old model scope' do - expect(described_class.last.form).to eq(some_record.form) - expect(Form5655Submission.last.form).to eq(some_record.form) - end - end - describe 'scopes' do let!(:first_record) do - create(:form5655_submission, public_metadata: { 'streamlined' => { 'type' => 'short', 'value' => true } }) + create( + :debts_api_form5655_submission, + public_metadata: { 'streamlined' => { 'type' => 'short', 'value' => true } } + ) end let!(:second_record) do - create(:form5655_submission, public_metadata: { 'streamlined' => { 'type' => 'short', 'value' => false } }) + create( + :debts_api_form5655_submission, + public_metadata: { 'streamlined' => { 'type' => 'short', 'value' => false } } + ) end - let!(:third_record) { create(:form5655_submission, public_metadata: {}) } + let!(:third_record) { create(:debts_api_form5655_submission, public_metadata: {}) } let!(:fourth_record) do - create(:form5655_submission, public_metadata: { 'streamlined' => { 'type' => 'short', 'value' => nil } }) + create( + :debts_api_form5655_submission, + public_metadata: { 'streamlined' => { 'type' => 'short', 'value' => nil } } + ) end it 'includes records within scope' do - expect(Form5655Submission.streamlined).to include(first_record) - expect(Form5655Submission.streamlined.length).to eq(1) + expect(DebtsApi::V0::Form5655Submission.streamlined).to include(first_record) + expect(DebtsApi::V0::Form5655Submission.streamlined.length).to eq(1) - expect(Form5655Submission.not_streamlined).to include(second_record) - expect(Form5655Submission.not_streamlined.length).to eq(1) + expect(DebtsApi::V0::Form5655Submission.not_streamlined).to include(second_record) + expect(DebtsApi::V0::Form5655Submission.not_streamlined.length).to eq(1) - expect(Form5655Submission.streamlined_unclear).to include(third_record) - expect(Form5655Submission.streamlined_unclear.length).to eq(1) + expect(DebtsApi::V0::Form5655Submission.streamlined_unclear).to include(third_record) + expect(DebtsApi::V0::Form5655Submission.streamlined_unclear.length).to eq(1) - expect(Form5655Submission.streamlined_nil).to include(fourth_record) - expect(Form5655Submission.streamlined_nil.length).to eq(1) + expect(DebtsApi::V0::Form5655Submission.streamlined_nil).to include(fourth_record) + expect(DebtsApi::V0::Form5655Submission.streamlined_nil.length).to eq(1) end end @@ -65,7 +63,7 @@ end describe '.user_cache_id' do - let(:form5655_submission) { create(:form5655_submission) } + let(:form5655_submission) { create(:debts_api_form5655_submission) } let(:user) { build(:user, :loa3) } it 'creates a new User profile attribute' do @@ -81,7 +79,7 @@ end it 'returns an error' do - expect { form5655_submission.user_cache_id }.to raise_error(Form5655Submission::StaleUserError) + expect { form5655_submission.user_cache_id }.to raise_error(DebtsApi::V0::Form5655Submission::StaleUserError) end end end diff --git a/spec/lib/debt_management_center/sharepoint/request_spec.rb b/spec/lib/debt_management_center/sharepoint/request_spec.rb index a0d1f809729..592687fafdf 100644 --- a/spec/lib/debt_management_center/sharepoint/request_spec.rb +++ b/spec/lib/debt_management_center/sharepoint/request_spec.rb @@ -66,7 +66,7 @@ describe '#upload' do let(:form_content) { { 'foo' => 'bar' } } - let(:form_submission) { create(:form5655_submission) } + let(:form_submission) { create(:debts_api_form5655_submission) } let(:station_id) { '123' } let(:file_path) { ::Rails.root.join(*'/spec/fixtures/dmc/5655.pdf'.split('/')).to_s } let(:body) do @@ -87,6 +87,13 @@ allow(PdfFill::Filler).to receive(:fill_ancillary_form).and_return(file_path) allow(File).to receive(:delete).and_return(nil) allow(DateTime).to receive(:now).and_return(upload_time) + allow_any_instance_of(subject.class).to receive(:set_user_data).and_return( + { + ssn: '123456598', + first_name: 'xxx', + last_name: 'Beer' + } + ) end it 'uploads a pdf file to SharePoint' do diff --git a/spec/models/form5655_submission_spec.rb b/spec/models/form5655_submission_spec.rb deleted file mode 100644 index c6ff7044efc..00000000000 --- a/spec/models/form5655_submission_spec.rb +++ /dev/null @@ -1,92 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -RSpec.describe Form5655Submission do - describe 'scopes' do - let!(:first_record) do - create(:form5655_submission, public_metadata: { 'streamlined' => { 'type' => 'short', 'value' => true } }) - end - let!(:second_record) do - create(:form5655_submission, public_metadata: { 'streamlined' => { 'type' => 'short', 'value' => false } }) - end - let!(:third_record) { create(:form5655_submission, public_metadata: {}) } - let!(:fourth_record) do - create(:form5655_submission, public_metadata: { 'streamlined' => { 'type' => 'short', 'value' => nil } }) - end - - it 'includes records within scope' do - expect(described_class.streamlined).to include(first_record) - expect(described_class.streamlined.length).to eq(1) - - expect(described_class.not_streamlined).to include(second_record) - expect(described_class.not_streamlined.length).to eq(1) - - expect(described_class.streamlined_unclear).to include(third_record) - expect(described_class.streamlined_unclear.length).to eq(1) - - expect(described_class.streamlined_nil).to include(fourth_record) - expect(described_class.streamlined_nil.length).to eq(1) - end - end - - describe '.submit_to_vba' do - let(:form5655_submission) { create(:form5655_submission) } - - it 'enqueues a VBA submission job' do - expect { form5655_submission.submit_to_vba }.to change(DebtsApi::V0::Form5655::VBASubmissionJob.jobs, :size).by(1) - end - end - - describe '.submit_to_vha' do - let(:form5655_submission) { create(:form5655_submission) } - - it 'enqueues a VHA submission job' do - expect { form5655_submission.submit_to_vha }.to change(DebtsApi::V0::Form5655::VHASubmissionJob.jobs, :size).by(1) - end - end - - describe '.user_cache_id' do - let(:form5655_submission) { create(:form5655_submission) } - let(:user) { build(:user, :loa3) } - - it 'creates a new User profile attribute' do - cache_id = form5655_submission.user_cache_id - attributes = UserProfileAttributes.find(cache_id) - expect(attributes.class).to eq(UserProfileAttributes) - expect(attributes.icn).to eq(user.icn) - end - - context 'with stale user id' do - before do - form5655_submission.user_uuid = '00000' - end - - it 'returns an error' do - expect { form5655_submission.user_cache_id }.to raise_error(Form5655Submission::StaleUserError) - end - end - end - - describe '#streamlined?' do - let(:pre_feature_submission) { create(:form5655_submission) } - let(:streamlined_submission) do - create(:sw_form5655_submission, public_metadata: { 'streamlined' => { 'type' => 'short', 'value' => true } }) - end - let(:non_streamlined_submission) do - create(:non_sw_form5655_submission, public_metadata: { 'streamlined' => { 'type' => '', 'value' => false } }) - end - - it 'returns false for submissions with feature off' do - expect(pre_feature_submission.streamlined?).to be false - end - - it 'returns false for post feature non streamlined submissions' do - expect(non_streamlined_submission.streamlined?).to be false - end - - it 'returns true for streamlined submissions' do - expect(streamlined_submission.streamlined?).to be true - end - end -end