Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10-10CG] Add ability to not call fully_validate_schema in SavedClaim #19468

Merged
merged 7 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor Author

@coope93 coope93 Nov 15, 2024

Choose a reason for hiding this comment

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

Apparently this was missing? The github job flagged it since I had updated one of the specs in the directory so I went ahead and added the codeowners to match the actual implementation directory.

Copy link
Contributor

Choose a reason for hiding this comment

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

thank you!

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
Expand Down
12 changes: 7 additions & 5 deletions app/models/saved_claim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions config/features.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions spec/controllers/v0/contact_us/inquiries_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions spec/lib/bgs/form674_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Change these to stubs instead of actually enabling/disabling the toggle. Added stub at the top to default to original values to handle any that are not stubbed.

end

# @TODO: may want to return something else
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions spec/lib/bgs/form686c_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }

Expand Down
4 changes: 4 additions & 0 deletions spec/models/saved_claim/education_benefits/va10203_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
132 changes: 92 additions & 40 deletions spec/models/saved_claim_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions spec/requests/swagger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3270,6 +3270,10 @@
end

describe 'contact us' do
before do
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These were failing because some expectations were validating that some toggle was set and the new Flipper call in saved_claim was expecting it. I added this to default all to call the original so any that don't have explicit expectations won't fail.

allow(Flipper).to receive(:enabled?).and_call_original
end

describe 'POST v0/contact_us/inquiries' do
let(:post_body) do
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading