diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index e2cdeba6706..56856bf7e16 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1107,6 +1107,7 @@ spec/controllers/v0/benefits_reference_data_controller_spec.rb @department-of-ve spec/controllers/v0/burial_claims_controller_spec.rb @department-of-veterans-affairs/mbs-core-team @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group spec/controllers/v0/caregivers_assistance_claims_controller_spec.rb @department-of-veterans-affairs/vfs-10-10 spec/controllers/v0/claim_letters_controller_spec.rb @department-of-veterans-affairs/benefits-management-tools-be @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group +spec/controllers/v0/contact_us @department-of-veterans-affairs/ask-va-team @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group spec/controllers/v0/debt_letters_controller_spec.rb @department-of-veterans-affairs/vsa-debt-resolution @department-of-veterans-affairs/backend-review-group spec/controllers/v0/dependents_applications_controller_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/controllers/v0/dependents_verifications_controller_spec.rb @department-of-veterans-affairs/benefits-dependents-management @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group diff --git a/app/models/saved_claim.rb b/app/models/saved_claim.rb index fd74cf49baa..dd0328a4f3a 100644 --- a/app/models/saved_claim.rb +++ b/app/models/saved_claim.rb @@ -82,13 +82,15 @@ def form_matches_schema return unless form_is_string schema = VetsJsonSchema::SCHEMAS[self.class::FORM] + clear_cache = false - schema_errors = validate_schema(schema) + unless Flipper.enabled?(:saved_claim_schema_validation_disable) + schema_errors = validate_schema(schema) - clear_cache = false - unless schema_errors.empty? - Rails.logger.error('SavedClaim schema failed validation! Attempting to clear cache.', { errors: schema_errors }) - clear_cache = true + unless schema_errors.empty? + Rails.logger.error('SavedClaim schema failed validation! Attempting to clear cache.', { errors: schema_errors }) + clear_cache = true + end end validation_errors = validate_form(schema, clear_cache) diff --git a/config/features.yml b/config/features.yml index 5ce533c5500..5cfef49e160 100644 --- a/config/features.yml +++ b/config/features.yml @@ -1170,6 +1170,9 @@ features: actor_type: user description: When enabled, the rated disabilities application uses Lighthouse instead of EVSS enable_in_development: true + saved_claim_schema_validation_disable: + actor_type: user + description: Disables validating a saved_claim schema before validating the form data with the schema. schema_contract_appointments_index: actor_type: user description: Enables schema validation for the appointments service index fetch. diff --git a/spec/controllers/v0/contact_us/inquiries_controller_spec.rb b/spec/controllers/v0/contact_us/inquiries_controller_spec.rb index f866966e2d0..d8837892b57 100644 --- a/spec/controllers/v0/contact_us/inquiries_controller_spec.rb +++ b/spec/controllers/v0/contact_us/inquiries_controller_spec.rb @@ -51,6 +51,10 @@ def send_create post(:create, params: { ask: { form: } }) end + before do + allow(Flipper).to receive(:enabled?).and_call_original + end + context 'when Flipper :get_help_ask_form is' do context 'disabled' do it 'renders :not_implemented' do diff --git a/spec/lib/bgs/form674_spec.rb b/spec/lib/bgs/form674_spec.rb index e138ac02ae1..cdbd77c15d2 100644 --- a/spec/lib/bgs/form674_spec.rb +++ b/spec/lib/bgs/form674_spec.rb @@ -9,9 +9,13 @@ let(:user_struct) { FactoryBot.build(:user_struct) } let(:saved_claim) { create(:dependency_claim_no_vet_information) } + before do + allow(Flipper).to receive(:enabled?).and_call_original + end + context 'The flipper is turned on' do before do - Flipper.enable(:dependents_enqueue_with_user_struct) + allow(Flipper).to receive(:enabled?).with(:dependents_enqueue_with_user_struct).and_return(true) end # @TODO: may want to return something else @@ -82,7 +86,7 @@ context 'The flipper is turned off' do before do - Flipper.disable(:dependents_enqueue_with_user_struct) + allow(Flipper).to receive(:enabled?).with(:dependents_enqueue_with_user_struct).and_return(false) end # @TODO: may want to return something else diff --git a/spec/lib/bgs/form686c_spec.rb b/spec/lib/bgs/form686c_spec.rb index a6d1123a63f..a77a743dd97 100644 --- a/spec/lib/bgs/form686c_spec.rb +++ b/spec/lib/bgs/form686c_spec.rb @@ -8,6 +8,10 @@ let(:user_struct) { FactoryBot.build(:user_struct) } let(:saved_claim) { create(:dependency_claim_no_vet_information) } + before do + allow(Flipper).to receive(:enabled?).and_call_original + end + describe '#submit' do subject { form686c.submit(payload) } diff --git a/spec/models/saved_claim/education_benefits/va10203_spec.rb b/spec/models/saved_claim/education_benefits/va10203_spec.rb index aa4567df4a9..cd567e742d6 100644 --- a/spec/models/saved_claim/education_benefits/va10203_spec.rb +++ b/spec/models/saved_claim/education_benefits/va10203_spec.rb @@ -9,6 +9,10 @@ let(:user) { create(:user) } let!(:user_verification) { create(:idme_user_verification, idme_uuid: user.idme_uuid) } + before do + allow(Flipper).to receive(:enabled?).and_call_original + end + it_behaves_like 'saved_claim' validate_inclusion(:form_id, '22-10203') diff --git a/spec/models/saved_claim_spec.rb b/spec/models/saved_claim_spec.rb index 38141c39c64..9f5cd2056a6 100644 --- a/spec/models/saved_claim_spec.rb +++ b/spec/models/saved_claim_spec.rb @@ -44,69 +44,121 @@ def attachment_keys end context 'validation errors' do - let(:schema_errors) { [{ fragment: 'error' }] } + context 'saved_claim_schema_validation_disable disabled' do + let(:schema_errors) { [{ fragment: 'error' }] } - context 'when fully_validate_schema returns errors' do before do - allow(JSON::Validator).to receive_messages(fully_validate_schema: schema_errors, fully_validate: []) + allow(Flipper).to receive(:enabled?).with(:saved_claim_schema_validation_disable).and_return(false) end - it 'logs schema failed error and calls fully_validate' do - expect(Rails.logger).to receive(:error) - .with('SavedClaim schema failed validation! Attempting to clear cache.', { errors: schema_errors }) + context 'when fully_validate_schema returns errors' do + before do + allow(JSON::Validator).to receive_messages(fully_validate_schema: schema_errors, fully_validate: []) + end - expect(saved_claim.validate).to eq true - end - end + it 'logs schema failed error and calls fully_validate' do + expect(Rails.logger).to receive(:error) + .with('SavedClaim schema failed validation! Attempting to clear cache.', { errors: schema_errors }) - context 'when fully_validate returns errors' do - before do - allow(JSON::Validator).to receive(:fully_validate).and_return(schema_errors) + expect(saved_claim.validate).to eq true + end end - it 'adds validation errors to the form' do - saved_claim.validate - expect(saved_claim.errors.full_messages).not_to be_empty + context 'when fully_validate returns errors' do + before do + allow(JSON::Validator).to receive(:fully_validate).and_return(schema_errors) + end + + it 'adds validation errors to the form' do + saved_claim.validate + expect(saved_claim.errors.full_messages).not_to be_empty + end end - end - context 'when JSON:Validator.fully_validate_schema throws an exception' do - let(:exception) { StandardError.new('Some exception') } + context 'when JSON:Validator.fully_validate_schema throws an exception' do + let(:exception) { StandardError.new('Some exception') } - before do - allow(JSON::Validator).to receive(:fully_validate_schema).and_raise(exception) - allow(JSON::Validator).to receive(:fully_validate).and_return([]) + before do + allow(JSON::Validator).to receive(:fully_validate_schema).and_raise(exception) + allow(JSON::Validator).to receive(:fully_validate).and_return([]) + end + + it 'logs exception and raises exception' do + expect(Rails.logger).to receive(:error) + .with('Error during schema validation!', { error: exception.message, backtrace: anything, schema: }) + + expect { saved_claim.validate }.to raise_error(exception.class, exception.message) + end end - it 'logs exception and raises exception' do - expect(Rails.logger).to receive(:error) - .with('Error during schema validation!', { error: exception.message, backtrace: anything, schema: }) + context 'when JSON:Validator.fully_validate throws an exception' do + let(:exception) { StandardError.new('Some exception') } + + before do + allow(JSON::Validator).to receive(:fully_validate_schema).and_return([]) + allow(JSON::Validator).to receive(:fully_validate).and_raise(exception) + end + + it 'logs exception and raises exception' do + expect(Rails.logger).to receive(:error) + .with('Error during form validation!', { error: exception.message, backtrace: anything, schema:, + clear_cache: false }) - expect { saved_claim.validate }.to raise_error(exception.class, exception.message) + expect(PersonalInformationLog).to receive(:create).with( + data: { schema: schema, + parsed_form: saved_claim.parsed_form, + params: { errors_as_objects: true, clear_cache: false } }, + error_class: 'SavedClaim FormValidationError' + ) + + expect { saved_claim.validate }.to raise_error(exception.class, exception.message) + end end end - context 'when JSON:Validator.fully_validate throws an exception' do - let(:exception) { StandardError.new('Some exception') } + context 'saved_claim_schema_validation_disable enabled' do + let(:schema_errors) { [{ fragment: 'error' }] } before do - allow(JSON::Validator).to receive(:fully_validate_schema).and_return([]) - allow(JSON::Validator).to receive(:fully_validate).and_raise(exception) + allow(Flipper).to receive(:enabled?).with(:saved_claim_schema_validation_disable).and_return(true) end - it 'logs exception and raises exception' do - expect(Rails.logger).to receive(:error) - .with('Error during form validation!', { error: exception.message, backtrace: anything, schema:, - clear_cache: false }) + context 'when fully_validate returns errors' do + before do + allow(JSON::Validator).to receive(:fully_validate).and_return(schema_errors) + end - expect(PersonalInformationLog).to receive(:create).with( - data: { schema: schema, - parsed_form: saved_claim.parsed_form, - params: { errors_as_objects: true, clear_cache: false } }, - error_class: 'SavedClaim FormValidationError' - ) + it 'adds validation errors to the form' do + expect(JSON::Validator).not_to receive(:fully_validate_schema) + + saved_claim.validate + expect(saved_claim.errors.full_messages).not_to be_empty + end + end + + context 'when JSON:Validator.fully_validate throws an exception' do + let(:exception) { StandardError.new('Some exception') } + + before do + allow(JSON::Validator).to receive(:fully_validate).and_raise(exception) + end + + it 'logs exception and raises exception' do + expect(JSON::Validator).not_to receive(:fully_validate_schema) + + expect(Rails.logger).to receive(:error) + .with('Error during form validation!', { error: exception.message, backtrace: anything, schema:, + clear_cache: false }) + + expect(PersonalInformationLog).to receive(:create).with( + data: { schema: schema, + parsed_form: saved_claim.parsed_form, + params: { errors_as_objects: true, clear_cache: false } }, + error_class: 'SavedClaim FormValidationError' + ) - expect { saved_claim.validate }.to raise_error(exception.class, exception.message) + expect { saved_claim.validate }.to raise_error(exception.class, exception.message) + end end end end diff --git a/spec/requests/swagger_spec.rb b/spec/requests/swagger_spec.rb index a36b46a8a2b..caca15b0b8c 100644 --- a/spec/requests/swagger_spec.rb +++ b/spec/requests/swagger_spec.rb @@ -3270,6 +3270,10 @@ end describe 'contact us' do + before do + allow(Flipper).to receive(:enabled?).and_call_original + end + describe 'POST v0/contact_us/inquiries' do let(:post_body) do { diff --git a/spec/sidekiq/education_form/create_daily_spool_files_spec.rb b/spec/sidekiq/education_form/create_daily_spool_files_spec.rb index 49b2e9092ae..9d265c24718 100644 --- a/spec/sidekiq/education_form/create_daily_spool_files_spec.rb +++ b/spec/sidekiq/education_form/create_daily_spool_files_spec.rb @@ -10,6 +10,10 @@ end let(:line_break) { EducationForm::CreateDailySpoolFiles::WINDOWS_NOTEPAD_LINEBREAK } + before do + allow(Flipper).to receive(:enabled?).and_call_original + end + after(:all) do FileUtils.rm_rf('tmp/spool_files') end diff --git a/spec/sidekiq/education_form/process10203_submissions_spec.rb b/spec/sidekiq/education_form/process10203_submissions_spec.rb index d0df50fbfaf..b57ad52a848 100644 --- a/spec/sidekiq/education_form/process10203_submissions_spec.rb +++ b/spec/sidekiq/education_form/process10203_submissions_spec.rb @@ -16,6 +16,10 @@ let(:no_edipi_user) { create(:user, participant_id: nil) } let(:evss_response_with_poa) { OpenStruct.new(body: get_fixture('json/evss_with_poa')) } + before do + allow(Flipper).to receive(:enabled?).and_call_original + end + describe 'scheduling' do before do allow(Rails.env).to receive('development?').and_return(true)