From eceeff944dc03f644a961ba67b3c0947a8edac0d Mon Sep 17 00:00:00 2001 From: Joshua Drumm <34111449+JoshingYou1@users.noreply.github.com> Date: Tue, 24 Dec 2024 11:32:39 -0500 Subject: [PATCH 01/26] Created a new enrollment system service to help with code readability --- app/models/health_care_application.rb | 2 +- config/features.yml | 4 + lib/form1010_ezr/service.rb | 30 +- lib/hca/enrollment_system.rb | 6 +- lib/hca/service.rb | 7 +- lib/va1010_forms/enrollment_system/service.rb | 88 +++ lib/va1010_forms/utils.rb | 4 - spec/lib/form1010_ezr/service_spec.rb | 478 ++++++++-------- spec/lib/hca/service_spec.rb | 528 ++++++++++++------ .../enrollment_system/service_spec.rb | 153 +++++ 10 files changed, 888 insertions(+), 412 deletions(-) create mode 100644 lib/va1010_forms/enrollment_system/service.rb create mode 100644 spec/lib/va1010_forms/enrollment_system/service_spec.rb diff --git a/app/models/health_care_application.rb b/app/models/health_care_application.rb index 5fc081a9527..237f30577ab 100644 --- a/app/models/health_care_application.rb +++ b/app/models/health_care_application.rb @@ -67,7 +67,7 @@ def send_failure_email? end def submit_sync - @parsed_form = override_parsed_form(parsed_form) + @parsed_form = HCA::OverridesParser.new(parsed_form).override result = begin HCA::Service.new(user).submit_form(parsed_form) diff --git a/config/features.yml b/config/features.yml index 838ab277e76..87106918b15 100644 --- a/config/features.yml +++ b/config/features.yml @@ -1401,6 +1401,10 @@ features: actor_type: user description: Use the original veteran_x models to power Appoint a Rep entity search enable_in_development: true + va1010_forms_enrollment_system_service_enabled: + actor_type: user + description: Enables the VA1010Forms enrollment system service + enable_in_development: true va_notify_custom_errors: actor_type: user description: Custom error classes instead of the generic Common::Exceptions::BackendServiceException diff --git a/lib/form1010_ezr/service.rb b/lib/form1010_ezr/service.rb index 84d7dea6960..ef3798d7f93 100644 --- a/lib/form1010_ezr/service.rb +++ b/lib/form1010_ezr/service.rb @@ -5,6 +5,7 @@ require 'hca/configuration' require 'hca/ezr_postfill' require 'va1010_forms/utils' +require 'va1010_forms/enrollment_system/service' module Form1010Ezr class Service < Common::Client::Base @@ -37,7 +38,20 @@ def submit_async(parsed_form) def submit_sync(parsed_form) res = with_monitoring do - es_submit(parsed_form, HealthCareApplication.get_user_identifier(@user), FORM_ID) + if Flipper.enabled?(:va1010_forms_enrollment_system_service_enabled) + VA1010Forms::EnrollmentSystem::Service.new( + HealthCareApplication.get_user_identifier(@user) + ).submit( + parsed_form, + FORM_ID + ) + else + es_submit( + parsed_form, + HealthCareApplication.get_user_identifier(@user), + FORM_ID + ) + end end # Log the 'formSubmissionId' for successful submissions @@ -106,11 +120,8 @@ def validate_form(parsed_form) ) end - log_validation_errors(parsed_form) + log_validation_errors(validation_errors, parsed_form) - Rails.logger.error( - "10-10EZR form validation failed. Form does not match schema. Error list: #{validation_errors}" - ) raise Common::Exceptions::SchemaValidationErrors, validation_errors end end @@ -155,7 +166,7 @@ def configure_and_validate_form(parsed_form) post_fill_fields(parsed_form) validate_form(parsed_form) # Due to overriding the JSON form schema, we need to do so after the form has been validated - override_parsed_form(parsed_form) + HCA::OverridesParser.new(parsed_form).override add_financial_flag(parsed_form) end @@ -167,9 +178,14 @@ def add_financial_flag(parsed_form) end end - def log_validation_errors(parsed_form) + # @param [Hash] errors + def log_validation_errors(errors, parsed_form) StatsD.increment("#{Form1010Ezr::Service::STATSD_KEY_PREFIX}.validation_error") + Rails.logger.error( + "10-10EZR form validation failed. Form does not match schema. Error list: #{errors}" + ) + PersonalInformationLog.create( data: parsed_form, error_class: 'Form1010Ezr ValidationError' diff --git a/lib/hca/enrollment_system.rb b/lib/hca/enrollment_system.rb index ecff838ea52..a0186c137fb 100644 --- a/lib/hca/enrollment_system.rb +++ b/lib/hca/enrollment_system.rb @@ -865,18 +865,18 @@ def add_attachment(file, id, is_dd214) end # @param [Hash] veteran data in JSON format - # @param [Account] current_user + # @param [Hash] user_identifier # @param [String] form_id def veteran_to_save_submit_form( veteran, - current_user, + user_identifier, form_id ) return {} if veteran.blank? copy_spouse_address!(veteran) - request = build_form_for_user(current_user, form_id) + request = build_form_for_user(user_identifier, form_id) veteran['attachments']&.each_with_index do |attachment, i| guid = attachment['confirmationCode'] diff --git a/lib/hca/service.rb b/lib/hca/service.rb index 23da8b5a63a..2af381a4a03 100644 --- a/lib/hca/service.rb +++ b/lib/hca/service.rb @@ -4,6 +4,7 @@ require 'hca/enrollment_system' require 'hca/configuration' require 'va1010_forms/utils' +require 'va1010_forms/enrollment_system/service' module HCA class Service < Common::Client::Base @@ -24,7 +25,11 @@ def submit_form(form) is_short_form = HealthCareApplication.new(form: form.to_json).short_form? with_monitoring do - es_submit(form, @user, '10-10EZ') + if Flipper.enabled?(:va1010_forms_enrollment_system_service_enabled) + VA1010Forms::EnrollmentSystem::Service.new(@user).submit(form, '10-10EZ') + else + es_submit(form, @user, '10-10EZ') + end rescue => e increment_failure('submit_form_short_form', e) if is_short_form raise e diff --git a/lib/va1010_forms/enrollment_system/service.rb b/lib/va1010_forms/enrollment_system/service.rb new file mode 100644 index 00000000000..ab4ad4b8aaf --- /dev/null +++ b/lib/va1010_forms/enrollment_system/service.rb @@ -0,0 +1,88 @@ +# frozen_string_literal: true + +require 'benchmark' +require 'common/client/base' +require 'hca/configuration' +require 'hca/overrides_parser' + +module VA1010Forms + module EnrollmentSystem + class Service < Common::Client::Base + include ActionView::Helpers::NumberHelper + + configuration HCA::Configuration + + # @param [Hash] user_identifier + # @example { 'icn' => user.icn, 'edipi' => user.edipi } + def initialize(user_identifier = nil) + @user_identifier = user_identifier + end + + def submit(parsed_form, form_id) + begin + formatted = HCA::EnrollmentSystem.veteran_to_save_submit_form( + parsed_form, + @user_identifier, + form_id + ) + submission_body = submission_body(formatted) + response = perform(:post, '', submission_body) + + root = response.body.locate('S:Envelope/S:Body/submitFormResponse').first + form_submission_id = root.locate('formSubmissionId').first.text.to_i + + { + success: true, + formSubmissionId: form_submission_id, + timestamp: root.locate('timeStamp').first&.text || Time.now.getlocal.to_s + } + rescue + raise + end + end + + private + + def soap + # Savon *seems* like it should be setting these things correctly + # from what the docs say. Our WSDL file is weird, maybe? + Savon.client( + wsdl: HCA::Configuration::WSDL, + env_namespace: :soap, + element_form_default: :qualified, + namespaces: { + 'xmlns:tns': 'http://va.gov/service/esr/voa/v1' + }, + namespace: 'http://va.gov/schema/esr/voa/v1' + ) + end + + def log_payload_info(formatted_form, submission_body) + form_name = formatted_form.dig('va:form', 'va:formIdentifier', 'va:value') + attachments = formatted_form.dig('va:form', 'va:attachments') + attachment_count = attachments&.length || 0 + # Log the attachment sizes in descending order + if attachment_count.positive? + # Convert the attachments into xml format so they resemble what will be sent to VES + attachment_sizes = + attachments.map { |a| a.to_xml.size }.sort.reverse!.map { |size| number_to_human_size(size) }.join(', ') + + Rails.logger.info("Attachment sizes in descending order: #{attachment_sizes}") + end + + Rails.logger.info( + "Payload for submitted #{form_name}: Body size of #{number_to_human_size(submission_body.bytesize)} " \ + "with #{attachment_count} attachment(s)" + ) + end + + def submission_body(formatted_form) + content = Gyoku.xml(formatted_form) + submission_body = soap.build_request(:save_submit_form, message: content).body + log_payload_info(formatted_form, submission_body) + + submission_body + end + end + end +end diff --git a/lib/va1010_forms/utils.rb b/lib/va1010_forms/utils.rb index 1052b8a511d..57258d5c81f 100644 --- a/lib/va1010_forms/utils.rb +++ b/lib/va1010_forms/utils.rb @@ -36,10 +36,6 @@ def soap ) end - def override_parsed_form(parsed_form) - HCA::OverridesParser.new(parsed_form).override - end - private def submission_body(formatted_form) diff --git a/spec/lib/form1010_ezr/service_spec.rb b/spec/lib/form1010_ezr/service_spec.rb index 49db0b1ac8a..d98c6b8da01 100644 --- a/spec/lib/form1010_ezr/service_spec.rb +++ b/spec/lib/form1010_ezr/service_spec.rb @@ -187,315 +187,325 @@ def ezr_form_with_attachments end end - describe '#submit_form' do - it 'submits the ezr with a background job', run_at: 'Tue, 21 Nov 2023 20:42:44 GMT' do - VCR.use_cassette( - 'form1010_ezr/authorized_submit', - match_requests_on: %i[method uri body], - erb: true, - allow_unused_http_interactions: false - ) do - expect { submit_form(form) }.to change { - HCA::EzrSubmissionJob.jobs.size - }.by(1) - - HCA::EzrSubmissionJob.drain + # Loop through the tests and run them once with the 'va1010_forms_enrollment_system_service_enabled' + # flipper enabled and then once disabled + [1, 2].each do |i| + describe '#submit_form' do + before do + if i == 2 + Flipper.disable(:va1010_forms_enrollment_system_service_enabled) + end end - end - context 'when an error occurs' do - let(:current_user) do - create( - :evss_user, - :loa3, - icn: '1013032368V065534', - birth_date: nil, - first_name: nil, - middle_name: nil, - last_name: 'test', - suffix: nil, - ssn: nil, - gender: nil - ) - end + it 'submits the ezr with a background job', run_at: 'Tue, 21 Nov 2023 20:42:44 GMT' do + VCR.use_cassette( + 'form1010_ezr/authorized_submit', + match_requests_on: %i[method uri body], + erb: true, + allow_unused_http_interactions: false + ) do + expect { submit_form(form) }.to change { + HCA::EzrSubmissionJob.jobs.size + }.by(1) - context 'schema validation failure' do - before do - allow_logger_to_receive_error - allow_any_instance_of( - HCA::EnrollmentEligibility::Service - ).to receive(:lookup_user).and_return({ preferred_facility: '988' }) + HCA::EzrSubmissionJob.drain end + end - it 'logs and raises a schema validation error' do - form_sans_required_fields = form.except( - 'privacyAgreementAccepted', - 'veteranDateOfBirth', - 'veteranFullName', - 'veteranSocialSecurityNumber', - 'gender' - ) - - allow(StatsD).to receive(:increment) - - expect(StatsD).to receive(:increment).with('api.1010ezr.validation_error') - expect { submit_form(form_sans_required_fields) }.to raise_error do |e| - expect(e).to be_a(Common::Exceptions::SchemaValidationErrors) - expect(e.errors.length).to eq(6) - e.errors.each do |error| - expect(error.title).to eq('Validation error') - expect(error.status).to eq('422') - end - end - expect_logger_errors( - [ - '10-10EZR form validation failed. Form does not match schema.', - "The property '#/veteranFullName' did not contain a required property of 'first'", - "The property '#/veteranDateOfBirth' of type null did not match the following type: string", - "The property '#/veteranSocialSecurityNumber' of type null did not match the following type: string", - "The property '#/gender' of type null did not match the following type: string", - "The property '#/' did not contain a required property of 'privacyAgreementAccepted'" - ] + context 'when an error occurs' do + let(:current_user) do + create( + :evss_user, + :loa3, + icn: '1013032368V065534', + birth_date: nil, + first_name: nil, + middle_name: nil, + last_name: 'test', + suffix: nil, + ssn: nil, + gender: nil ) end - # REMOVE THIS TEST ONCE THE DOB ISSUE HAS BEEN DIAGNOSED - 3/27/24 - context "when the error pertains to the Veteran's DOB" do + context 'schema validation failure' do before do - allow(JSON::Validator).to receive(:fully_validate).and_return(['veteranDateOfBirth error']) + allow_logger_to_receive_error + allow_any_instance_of( + HCA::EnrollmentEligibility::Service + ).to receive(:lookup_user).and_return({ preferred_facility: '988' }) end - it 'creates a PersonalInformationLog and saves the unprocessed DOB' do - expect { submit_form(form) }.to raise_error do |e| - personal_information_log = - PersonalInformationLog.find_by(error_class: "Form1010Ezr 'veteranDateOfBirth' schema failure") + it 'logs and raises a schema validation error' do + form_sans_required_fields = form.except( + 'privacyAgreementAccepted', + 'veteranDateOfBirth', + 'veteranFullName', + 'veteranSocialSecurityNumber', + 'gender' + ) + + allow(StatsD).to receive(:increment) - expect(personal_information_log.present?).to eq(true) - expect(personal_information_log.data).to eq(form['veteranDateOfBirth']) + expect(StatsD).to receive(:increment).with('api.1010ezr.validation_error') + expect { submit_form(form_sans_required_fields) }.to raise_error do |e| expect(e).to be_a(Common::Exceptions::SchemaValidationErrors) + expect(e.errors.length).to eq(6) + e.errors.each do |error| + expect(error.title).to eq('Validation error') + expect(error.status).to eq('422') + end end + expect_logger_errors( + [ + '10-10EZR form validation failed. Form does not match schema.', + "The property '#/veteranFullName' did not contain a required property of 'first'", + "The property '#/veteranDateOfBirth' of type null did not match the following type: string", + "The property '#/veteranSocialSecurityNumber' of type null did not match the following type: string", + "The property '#/gender' of type null did not match the following type: string", + "The property '#/' did not contain a required property of 'privacyAgreementAccepted'" + ] + ) end - end - end - context 'any other error' do - before do - allow_any_instance_of( - Common::Client::Base - ).to receive(:perform).and_raise( - StandardError.new('Uh oh. Some bad error occurred.') - ) - allow_logger_to_receive_error - end + # REMOVE THIS TEST ONCE THE DOB ISSUE HAS BEEN DIAGNOSED - 3/27/24 + context "when the error pertains to the Veteran's DOB" do + before do + allow(JSON::Validator).to receive(:fully_validate).and_return(['veteranDateOfBirth error']) + end - it 'increments StatsD as well as logs and raises the error' do - allow(StatsD).to receive(:increment) + it 'creates a PersonalInformationLog and saves the unprocessed DOB' do + expect { submit_form(form) }.to raise_error do |e| + personal_information_log = + PersonalInformationLog.find_by(error_class: "Form1010Ezr 'veteranDateOfBirth' schema failure") - expect(StatsD).to receive(:increment).with('api.1010ezr.failed') - expect { submit_form(form) }.to raise_error( - StandardError, 'Uh oh. Some bad error occurred.' - ) - expect_logger_errors( - ['10-10EZR form submission failed: Uh oh. Some bad error occurred.'] - ) + expect(personal_information_log.present?).to eq(true) + expect(personal_information_log.data).to eq(form['veteranDateOfBirth']) + expect(e).to be_a(Common::Exceptions::SchemaValidationErrors) + end + end + end end - end - end - end - - describe '#submit_sync' do - context 'when an error occurs' do - it 'increments statsd' do - allow(StatsD).to receive(:increment) - expect(StatsD).to receive(:increment).with( - 'api.1010ezr.submit_sync.fail', - tags: ['error:VCRErrorsUnhandledHTTPRequestError'] - ) - expect(StatsD).to receive(:increment).with('api.1010ezr.submit_sync.total') - expect { service.submit_sync(form_with_ves_fields) }.to raise_error(StandardError) - end - end + context 'any other error' do + before do + allow_any_instance_of( + Common::Client::Base + ).to receive(:perform).and_raise( + StandardError.new('Uh oh. Some bad error occurred.') + ) + allow_logger_to_receive_error + end - context 'when successful' do - before do - allow_logger_to_receive_info - end + it 'increments StatsD as well as logs and raises the error' do + allow(StatsD).to receive(:increment) - it "returns an object that includes 'success', 'formSubmissionId', and 'timestamp'", - run_at: 'Tue, 21 Nov 2023 20:42:44 GMT' do - VCR.use_cassette( - 'form1010_ezr/authorized_submit', - { match_requests_on: %i[method uri body], erb: true } - ) do - submission_response = service.submit_sync(form_with_ves_fields) - - expect(submission_response).to be_a(Object) - expect(submission_response).to eq( - { - success: true, - formSubmissionId: 436_462_561, - timestamp: '2024-08-23T13:00:11.005-05:00' - } - ) + expect(StatsD).to receive(:increment).with('api.1010ezr.failed') + expect { submit_form(form) }.to raise_error( + StandardError, 'Uh oh. Some bad error occurred.' + ) + expect_logger_errors( + ['10-10EZR form submission failed: Uh oh. Some bad error occurred.'] + ) + end end end + end - it "logs the submission id, user's initials, payload size, and individual attachment sizes in descending " \ - 'order (if applicable)', - run_at: 'Wed, 17 Jul 2024 18:17:30 GMT' do - VCR.use_cassette( - 'form1010_ezr/authorized_submit_with_attachments', - { match_requests_on: %i[method uri body], erb: true } - ) do - submission_response = service.submit_sync(ezr_form_with_attachments) - - expect(Rails.logger).to have_received(:info).with( - '1010EZR successfully submitted', - submission_id: submission_response[:formSubmissionId], - veteran_initials: { - first_initial: 'F', - middle_initial: 'M', - last_initial: 'Z' - } - ) - expect(Rails.logger).to have_received(:info).with('Payload for submitted 1010EZR: ' \ - 'Body size of 362 KB with 2 attachment(s)') - expect(Rails.logger).to have_received(:info).with( - 'Attachment sizes in descending order: 348 KB, 1.8 KB' + describe '#submit_sync' do + context 'when an error occurs' do + it 'increments statsd' do + allow(StatsD).to receive(:increment) + + expect(StatsD).to receive(:increment).with( + 'api.1010ezr.submit_sync.fail', + tags: ['error:VCRErrorsUnhandledHTTPRequestError'] ) + expect(StatsD).to receive(:increment).with('api.1010ezr.submit_sync.total') + expect { service.submit_sync(form_with_ves_fields) }.to raise_error(StandardError) end end - context 'when the form includes a Mexican province' do - let(:form) do - get_fixture('form1010_ezr/valid_form_with_mexican_province').merge!(ves_fields) + context 'when successful' do + before do + allow_logger_to_receive_info end - it 'returns a success object', run_at: 'Tue, 21 Nov 2023 22:29:52 GMT' do + it "returns an object that includes 'success', 'formSubmissionId', and 'timestamp'", + run_at: 'Tue, 21 Nov 2023 20:42:44 GMT' do VCR.use_cassette( - 'form1010_ezr/authorized_submit_with_mexican_province', + 'form1010_ezr/authorized_submit', { match_requests_on: %i[method uri body], erb: true } ) do - overridden_form = HCA::OverridesParser.new(form).override + submission_response = service.submit_sync(form_with_ves_fields) - expect(service.submit_sync(overridden_form)).to eq( + expect(submission_response).to be_a(Object) + expect(submission_response).to eq( { success: true, - formSubmissionId: 436_460_791, - timestamp: '2024-08-23T11:49:44.562-05:00' + formSubmissionId: 436_462_561, + timestamp: '2024-08-23T13:00:11.005-05:00' } ) end end - end - - context 'when the form includes next of kin and/or emergency contact info' do - let(:form) do - get_fixture( - 'form1010_ezr/valid_form_with_next_of_kin_and_emergency_contact' - ).merge!(ves_fields) - end - it 'returns a success object', run_at: 'Thu, 30 Nov 2023 15:52:36 GMT' do + it "logs the submission id, user's initials, payload size, and individual attachment sizes in descending " \ + 'order (if applicable)', + run_at: 'Wed, 17 Jul 2024 18:17:30 GMT' do VCR.use_cassette( - 'form1010_ezr/authorized_submit_with_next_of_kin_and_emergency_contact', + 'form1010_ezr/authorized_submit_with_attachments', { match_requests_on: %i[method uri body], erb: true } ) do - expect(service.submit_sync(form)).to eq( - { - success: true, - formSubmissionId: 436_462_887, - timestamp: '2024-08-23T13:22:29.157-05:00' + submission_response = service.submit_sync(ezr_form_with_attachments) + + expect(Rails.logger).to have_received(:info).with( + '1010EZR successfully submitted', + submission_id: submission_response[:formSubmissionId], + veteran_initials: { + first_initial: 'F', + middle_initial: 'M', + last_initial: 'Z' } ) + expect(Rails.logger).to have_received(:info).with('Payload for submitted 1010EZR: ' \ + 'Body size of 362 KB with 2 attachment(s)') + expect(Rails.logger).to have_received(:info).with( + 'Attachment sizes in descending order: 348 KB, 1.8 KB' + ) end end - end - context 'when the form includes TERA info' do - let(:form) do - get_fixture('form1010_ezr/valid_form_with_tera').merge!(ves_fields) - end + context 'when the form includes a Mexican province' do + let(:form) do + get_fixture('form1010_ezr/valid_form_with_mexican_province').merge!(ves_fields) + end - it 'returns a success object', run_at: 'Wed, 13 Mar 2024 18:14:49 GMT' do - VCR.use_cassette( - 'form1010_ezr/authorized_submit_with_tera', - { match_requests_on: %i[method uri body], erb: true } - ) do - expect(service.submit_sync(form)).to eq( - { - success: true, - formSubmissionId: 436_462_892, - timestamp: '2024-08-23T13:22:59.196-05:00' - } - ) + it 'returns a success object', run_at: 'Tue, 21 Nov 2023 22:29:52 GMT' do + VCR.use_cassette( + 'form1010_ezr/authorized_submit_with_mexican_province', + { match_requests_on: %i[method uri body], erb: true } + ) do + overridden_form = HCA::OverridesParser.new(form).override + + expect(service.submit_sync(overridden_form)).to eq( + { + success: true, + formSubmissionId: 436_460_791, + timestamp: '2024-08-23T11:49:44.562-05:00' + } + ) + end end end - end - - context 'submitting with attachments' do - let(:form) { get_fixture('form1010_ezr/valid_form') } - context 'with pdf attachments' do - it 'increments StatsD and returns a success object', run_at: 'Wed, 17 Jul 2024 18:17:32 GMT' do - allow(StatsD).to receive(:increment) - expect(StatsD).to receive(:increment).with('api.1010ezr.submission_with_attachment') + context 'when the form includes next of kin and/or emergency contact info' do + let(:form) do + get_fixture( + 'form1010_ezr/valid_form_with_next_of_kin_and_emergency_contact' + ).merge!(ves_fields) + end + it 'returns a success object', run_at: 'Thu, 30 Nov 2023 15:52:36 GMT' do VCR.use_cassette( - 'form1010_ezr/authorized_submit_with_attachments', + 'form1010_ezr/authorized_submit_with_next_of_kin_and_emergency_contact', { match_requests_on: %i[method uri body], erb: true } ) do - expect(service.submit_sync(ezr_form_with_attachments)).to eq( + expect(service.submit_sync(form)).to eq( { success: true, - formSubmissionId: 436_462_804, - timestamp: '2024-08-23T13:20:06.967-05:00' + formSubmissionId: 436_462_887, + timestamp: '2024-08-23T13:22:29.157-05:00' } ) - expect(Rails.logger).to have_received(:info).with( - 'Payload for submitted 1010EZR: Body size of 362 KB with 2 attachment(s)' - ) end end end - context 'with a non-pdf attachment' do - it 'increments StatsD and returns a success object', run_at: 'Wed, 17 Jul 2024 18:17:34 GMT' do - allow(StatsD).to receive(:increment) - expect(StatsD).to receive(:increment).with('api.1010ezr.submission_with_attachment') + context 'when the form includes TERA info' do + let(:form) do + get_fixture('form1010_ezr/valid_form_with_tera').merge!(ves_fields) + end + it 'returns a success object', run_at: 'Wed, 13 Mar 2024 18:14:49 GMT' do VCR.use_cassette( - 'form1010_ezr/authorized_submit_with_non_pdf_attachment', + 'form1010_ezr/authorized_submit_with_tera', { match_requests_on: %i[method uri body], erb: true } ) do - ezr_attachment = build(:form1010_ezr_attachment) - ezr_attachment.set_file_data!( - Rack::Test::UploadedFile.new( - 'spec/fixtures/files/sm_file1.jpg', - 'image/jpeg' - ) + expect(service.submit_sync(form)).to eq( + { + success: true, + formSubmissionId: 436_462_892, + timestamp: '2024-08-23T13:22:59.196-05:00' + } ) - ezr_attachment.save! + end + end + end - form_with_non_pdf_attachment = form_with_ves_fields.merge( - 'attachments' => [ + context 'submitting with attachments' do + let(:form) { get_fixture('form1010_ezr/valid_form') } + + context 'with pdf attachments' do + it 'increments StatsD and returns a success object', run_at: 'Wed, 17 Jul 2024 18:17:32 GMT' do + allow(StatsD).to receive(:increment) + expect(StatsD).to receive(:increment).with('api.1010ezr.submission_with_attachment') + + VCR.use_cassette( + 'form1010_ezr/authorized_submit_with_attachments', + { match_requests_on: %i[method uri body], erb: true } + ) do + expect(service.submit_sync(ezr_form_with_attachments)).to eq( { - 'confirmationCode' => ezr_attachment.guid + success: true, + formSubmissionId: 436_462_804, + timestamp: '2024-08-23T13:20:06.967-05:00' } - ] - ) + ) + expect(Rails.logger).to have_received(:info).with( + 'Payload for submitted 1010EZR: Body size of 362 KB with 2 attachment(s)' + ) + end + end + end - expect(service.submit_sync(form_with_non_pdf_attachment)).to eq( - { - success: true, - formSubmissionId: 436_462_905, - timestamp: '2024-08-23T13:23:53.956-05:00' - } - ) - expect(Rails.logger).to have_received(:info).with( - 'Payload for submitted 1010EZR: Body size of 12.8 KB with 1 attachment(s)' - ) + context 'with a non-pdf attachment' do + it 'increments StatsD and returns a success object', run_at: 'Wed, 17 Jul 2024 18:17:34 GMT' do + allow(StatsD).to receive(:increment) + expect(StatsD).to receive(:increment).with('api.1010ezr.submission_with_attachment') + + VCR.use_cassette( + 'form1010_ezr/authorized_submit_with_non_pdf_attachment', + { match_requests_on: %i[method uri body], erb: true } + ) do + ezr_attachment = build(:form1010_ezr_attachment) + ezr_attachment.set_file_data!( + Rack::Test::UploadedFile.new( + 'spec/fixtures/files/sm_file1.jpg', + 'image/jpeg' + ) + ) + ezr_attachment.save! + + form_with_non_pdf_attachment = form_with_ves_fields.merge( + 'attachments' => [ + { + 'confirmationCode' => ezr_attachment.guid + } + ] + ) + + expect(service.submit_sync(form_with_non_pdf_attachment)).to eq( + { + success: true, + formSubmissionId: 436_462_905, + timestamp: '2024-08-23T13:23:53.956-05:00' + } + ) + expect(Rails.logger).to have_received(:info).with( + 'Payload for submitted 1010EZR: Body size of 12.8 KB with 1 attachment(s)' + ) + end end end end diff --git a/spec/lib/hca/service_spec.rb b/spec/lib/hca/service_spec.rb index 6356a036815..977f9d598f8 100644 --- a/spec/lib/hca/service_spec.rb +++ b/spec/lib/hca/service_spec.rb @@ -31,221 +31,425 @@ allow(Rails.logger).to receive(:info) end - it 'doesnt convert validation error to another error' do - error = HCA::SOAPParser::ValidationError - expect(service.send(:connection)).to receive(:post).and_raise(error) + context "when the 'va1010_forms_enrollment_system_service_enabled' flipper is enabled" do + let(:enrollment_system_service) { instance_double(VA1010Forms::EnrollmentSystem::Service) } - expect do - service.submit_form(build(:health_care_application).parsed_form) - end.to raise_error(error) + it "calls the new 'VA1010Forms::EnrollmentSystem::Service'" do + allow(VA1010Forms::EnrollmentSystem::Service).to receive(:new).and_return(enrollment_system_service) - expect(Rails.logger).to have_received(:info).with('Payload for submitted 1010EZ: ' \ - 'Body size of 12.5 KB with 0 attachment(s)') - end + form = get_fixture('hca/tera') + + expect(enrollment_system_service).to receive(:submit).with(form, '10-10EZ') + + service.submit_form(form) + end - context 'logs submission payload size' do - it 'works', run_at: 'Wed, 16 Mar 2022 20:01:14 GMT' do - VCR.use_cassette( - 'hca/short_form', - VCR::MATCH_EVERYTHING.merge(erb: true) - ) do - result = HCA::Service.new.submit_form(get_fixture('hca/short_form')) - expect(result[:success]).to eq(true) - expect(Rails.logger).to have_received(:info).with('Payload for submitted 1010EZ: ' \ + it 'doesnt convert validation error to another error' do + error = HCA::SOAPParser::ValidationError + expect_any_instance_of(VA1010Forms::EnrollmentSystem::Service).to receive(:submit).and_raise(error) + + expect do + service.submit_form(build(:health_care_application).parsed_form) + end.to raise_error(error) + end + + context 'logs submission payload size' do + it 'works', run_at: 'Wed, 16 Mar 2022 20:01:14 GMT' do + VCR.use_cassette( + 'hca/short_form', + VCR::MATCH_EVERYTHING.merge(erb: true) + ) do + result = HCA::Service.new.submit_form(get_fixture('hca/short_form')) + expect(result[:success]).to eq(true) + expect(Rails.logger).to have_received(:info).with('Payload for submitted 1010EZ: ' \ 'Body size of 5.16 KB with 0 attachment(s)') + end end end - end - it 'increments statsd' do - expect(StatsD).to receive(:increment).with('api.1010ez.submit_form.fail', - tags: ['error:VCRErrorsUnhandledHTTPRequestError']) - expect(StatsD).to receive(:increment).with('api.1010ez.submit_form.total') + it 'increments statsd' do + expect(StatsD).to receive(:increment).with('api.1010ez.submit_form.fail', + tags: ['error:VCRErrorsUnhandledHTTPRequestError']) + expect(StatsD).to receive(:increment).with('api.1010ez.submit_form.total') + + expect do + service.submit_form(build(:health_care_application).parsed_form) + end.to raise_error(StandardError) + + allow_any_instance_of(VA1010Forms::EnrollmentSystem::Service).to receive(:perform).and_return(response) + expect(StatsD).not_to receive(:increment).with('api.1010ez.submit_form.fail') + expect(StatsD).to receive(:increment).with('api.1010ez.submit_form.total') - expect do service.submit_form(build(:health_care_application).parsed_form) - end.to raise_error(StandardError) + end - allow_any_instance_of(described_class).to receive(:perform).and_return(response) - expect(StatsD).not_to receive(:increment).with('api.1010ez.submit_form.fail') - expect(StatsD).to receive(:increment).with('api.1010ez.submit_form.total') + context 'with hasDemographicNoAnswer true' do + it 'submits successfully to hca', run_at: 'Fri, 05 May 2023 10:04:13 GMT' do + VCR.use_cassette( + 'hca/demographic_no', + VCR::MATCH_EVERYTHING.merge(erb: true) + ) do + form = get_fixture('hca/demographic_no') + expect(HealthCareApplication.new(form: form.to_json).valid?).to eq(true) - service.submit_form(build(:health_care_application).parsed_form) - end + result = HCA::Service.new.submit_form(form) + expect(result[:success]).to eq(true) + end + end + end - context 'conformance tests', run_at: '2016-12-12' do - root = Rails.root.join('spec', 'fixtures', 'hca', 'conformance') - Dir[File.join(root, '*.json')].map { |f| File.basename(f, '.json') }.each do |form| - it "properly formats #{form} for transmission" do - allow_any_instance_of(MPIData).to receive(:icn).and_return('1000123456V123456') - service = - if form.match?(/authenticated/) - described_class.new( - HealthCareApplication.get_user_identifier(current_user) - ) - else - described_class.new - end + context 'with a medicare claim number' do + it 'submits successfully to hca', run_at: 'Wed, 27 Jul 2022 23:54:25 GMT' do + VCR.use_cassette( + 'hca/medicare_claim_num', + VCR::MATCH_EVERYTHING.merge(erb: true) + ) do + form = get_fixture('hca/medicare_claim_num') + expect(HealthCareApplication.new(form: form.to_json).valid?).to eq(true) - json = JSON.parse(File.open(root.join("#{form}.json")).read) - expect(json).to match_vets_schema('10-10EZ') - xml = File.read(root.join("#{form}.xml")) - expect(service).to receive(:perform) do |_verb, _, body| - submission = body - pretty_printed = Ox.dump(Ox.parse(submission).locate('soap:Envelope/soap:Body/ns1:submitFormRequest').first) - expect(pretty_printed[1..]).to eq(xml) - end.and_return(response) + result = HCA::Service.new.submit_form(form) + expect(result[:success]).to eq(true) + end + end + end - service.submit_form(json) + context 'submitting sigi field' do + it 'works', run_at: 'Tue, 01 Nov 2022 15:07:20 GMT' do + VCR.use_cassette( + 'hca/sigi', + VCR::MATCH_EVERYTHING.merge(erb: true) + ) do + result = HCA::Service.new.submit_form(get_fixture('hca/sigi')) + expect(result[:success]).to eq(true) + end end end - end - context 'with hasDemographicNoAnswer true' do - it 'submits successfully to hca', run_at: 'Fri, 05 May 2023 10:04:13 GMT' do - VCR.use_cassette( - 'hca/demographic_no', - VCR::MATCH_EVERYTHING.merge(erb: true) - ) do - form = get_fixture('hca/demographic_no') - expect(HealthCareApplication.new(form: form.to_json).valid?).to eq(true) - - result = HCA::Service.new.submit_form(form) - expect(result[:success]).to eq(true) + context 'submitting tera questions' do + it 'works', run_at: 'Fri, 23 Feb 2024 19:47:28 GMT' do + VCR.use_cassette( + 'hca/tera', + VCR::MATCH_EVERYTHING.merge(erb: true) + ) do + form = get_fixture('hca/tera') + expect(HealthCareApplication.new(form: form.to_json).valid?).to eq(true) + result = HCA::Service.new.submit_form(form) + expect(result[:success]).to eq(true) + end end end - end - context 'with a medicare claim number' do - it 'submits successfully to hca', run_at: 'Wed, 27 Jul 2022 23:54:25 GMT' do - VCR.use_cassette( - 'hca/medicare_claim_num', - VCR::MATCH_EVERYTHING.merge(erb: true) - ) do - form = get_fixture('hca/medicare_claim_num') - expect(HealthCareApplication.new(form: form.to_json).valid?).to eq(true) - - result = HCA::Service.new.submit_form(form) - expect(result[:success]).to eq(true) + context 'submitting short form' do + it 'works', run_at: 'Wed, 16 Mar 2022 20:01:14 GMT' do + VCR.use_cassette( + 'hca/short_form', + VCR::MATCH_EVERYTHING.merge(erb: true) + ) do + result = HCA::Service.new.submit_form(get_fixture('hca/short_form')) + expect(result[:success]).to eq(true) + end + end + + it 'increments statsd' do + allow(StatsD).to receive(:increment) + + expect(StatsD).to receive(:increment).with('api.1010ez.submit_form_short_form.fail', + tags: ['error:VCRErrorsUnhandledHTTPRequestError']) + expect(StatsD).to receive(:increment).with('api.1010ez.submit_form_short_form.total') + + expect do + HCA::Service.new.submit_form(get_fixture('hca/short_form')) + end.to raise_error(StandardError) end end - end - context 'submitting sigi field' do - it 'works', run_at: 'Tue, 01 Nov 2022 15:07:20 GMT' do - VCR.use_cassette( - 'hca/sigi', - VCR::MATCH_EVERYTHING.merge(erb: true) - ) do - result = HCA::Service.new.submit_form(get_fixture('hca/sigi')) - expect(result[:success]).to eq(true) + context 'submitting with attachment' do + it 'works', run_at: 'Wed, 17 Jul 2024 18:04:50 GMT' do + VCR.use_cassette( + 'hca/submit_with_attachment', + VCR::MATCH_EVERYTHING.merge(erb: true) + ) do + result = HCA::Service.new.submit_form(create(:hca_app_with_attachment).parsed_form) + expect(result[:success]).to eq(true) + expect(Rails.logger).to have_received(:info).with('Payload for submitted 1010EZ: ' \ + 'Body size of 16 KB with 2 attachment(s)') + expect(Rails.logger).to have_received(:info).with( + 'Attachment sizes in descending order: 1.8 KB, 1.8 KB' + ) + end + end + + context 'with a non-pdf attachment' do + it 'works', run_at: 'Wed, 17 Jul 2024 18:04:51 GMT' do + hca_attachment = build(:hca_attachment) + hca_attachment.set_file_data!( + Rack::Test::UploadedFile.new( + 'spec/fixtures/files/sm_file1.jpg', + 'image/jpeg' + ) + ) + hca_attachment.save! + + health_care_application = build(:health_care_application) + form = health_care_application.parsed_form + form['attachments'] = [ + { + 'confirmationCode' => hca_attachment.guid, + 'dd214' => true + } + ] + health_care_application.form = form.to_json + health_care_application.send(:remove_instance_variable, :@parsed_form) + health_care_application.save! + + VCR.use_cassette( + 'hca/submit_with_attachment_jpg', + VCR::MATCH_EVERYTHING.merge(erb: true) + ) do + result = HCA::Service.new.submit_form(health_care_application.parsed_form) + expect(result[:success]).to eq(true) + end + end end end - end - context 'submitting tera questions' do - it 'works', run_at: 'Fri, 23 Feb 2024 19:47:28 GMT' do - VCR.use_cassette( - 'hca/tera', - VCR::MATCH_EVERYTHING.merge(erb: true) - ) do - form = get_fixture('hca/tera') - expect(HealthCareApplication.new(form: form.to_json).valid?).to eq(true) - result = HCA::Service.new.submit_form(form) - expect(result[:success]).to eq(true) + context 'receives a 503 response' do + it 'rescues and raises GatewayTimeout exception' do + expect(service).to receive(:connection).and_return( + Faraday.new do |conn| + conn.builder.handlers = service.send(:connection).builder.handlers.reject do |x| + x.inspect == 'Faraday::Adapter::NetHttp' + end + conn.adapter :test do |stub| + stub.post('/') { [503, { body: 'it took too long!' }, 'timeout'] } + end + end + ) + expect { service.send(:request, :post, '', OpenStruct.new(body: nil)) }.to raise_error( + Common::Exceptions::GatewayTimeout + ) end end end - context 'submitting short form' do - it 'works', run_at: 'Wed, 16 Mar 2022 20:01:14 GMT' do - VCR.use_cassette( - 'hca/short_form', - VCR::MATCH_EVERYTHING.merge(erb: true) - ) do - result = HCA::Service.new.submit_form(get_fixture('hca/short_form')) - expect(result[:success]).to eq(true) + context "when the 'va1010_forms_enrollment_system_service_enabled' flipper is disabled" do + before do + Flipper.disable(:va1010_forms_enrollment_system_service_enabled) + end + + it 'doesnt convert validation error to another error' do + error = HCA::SOAPParser::ValidationError + expect(service.send(:connection)).to receive(:post).and_raise(error) + + expect do + service.submit_form(build(:health_care_application).parsed_form) + end.to raise_error(error) + end + + context 'logs submission payload size' do + it 'works', run_at: 'Wed, 16 Mar 2022 20:01:14 GMT' do + VCR.use_cassette( + 'hca/short_form', + VCR::MATCH_EVERYTHING.merge(erb: true) + ) do + result = HCA::Service.new.submit_form(get_fixture('hca/short_form')) + expect(result[:success]).to eq(true) + expect(Rails.logger).to have_received(:info).with('Payload for submitted 1010EZ: ' \ + 'Body size of 5.16 KB with 0 attachment(s)') + end end end it 'increments statsd' do - allow(StatsD).to receive(:increment) - - expect(StatsD).to receive(:increment).with('api.1010ez.submit_form_short_form.fail', - tags: ['error:VCRErrorsUnhandledHTTPRequestError']) - expect(StatsD).to receive(:increment).with('api.1010ez.submit_form_short_form.total') + expect(StatsD).to receive(:increment).with('api.1010ez.submit_form.fail', + tags: ['error:VCRErrorsUnhandledHTTPRequestError']) + expect(StatsD).to receive(:increment).with('api.1010ez.submit_form.total') expect do - HCA::Service.new.submit_form(get_fixture('hca/short_form')) + service.submit_form(build(:health_care_application).parsed_form) end.to raise_error(StandardError) + + allow_any_instance_of(described_class).to receive(:perform).and_return(response) + expect(StatsD).not_to receive(:increment).with('api.1010ez.submit_form.fail') + expect(StatsD).to receive(:increment).with('api.1010ez.submit_form.total') + + service.submit_form(build(:health_care_application).parsed_form) end - end - context 'submitting with attachment' do - it 'works', run_at: 'Wed, 17 Jul 2024 18:04:50 GMT' do - VCR.use_cassette( - 'hca/submit_with_attachment', - VCR::MATCH_EVERYTHING.merge(erb: true) - ) do - result = HCA::Service.new.submit_form(create(:hca_app_with_attachment).parsed_form) - expect(result[:success]).to eq(true) - expect(Rails.logger).to have_received(:info).with('Payload for submitted 1010EZ: ' \ - 'Body size of 16 KB with 2 attachment(s)') - expect(Rails.logger).to have_received(:info).with( - 'Attachment sizes in descending order: 1.8 KB, 1.8 KB' - ) + context 'conformance tests', run_at: '2016-12-12' do + root = Rails.root.join('spec', 'fixtures', 'hca', 'conformance') + Dir[File.join(root, '*.json')].map { |f| File.basename(f, '.json') }.each do |form| + it "properly formats #{form} for transmission" do + allow_any_instance_of(MPIData).to receive(:icn).and_return('1000123456V123456') + service = + if form.match?(/authenticated/) + described_class.new( + HealthCareApplication.get_user_identifier(current_user) + ) + else + described_class.new + end + + json = JSON.parse(File.open(root.join("#{form}.json")).read) + expect(json).to match_vets_schema('10-10EZ') + xml = File.read(root.join("#{form}.xml")) + expect(service).to receive(:perform) do |_verb, _, body| + submission = body + pretty_printed = Ox.dump(Ox.parse(submission).locate('soap:Envelope/soap:Body/ns1:submitFormRequest').first) + expect(pretty_printed[1..]).to eq(xml) + end.and_return(response) + + service.submit_form(json) + end end end - context 'with a non-pdf attachment' do - it 'works', run_at: 'Wed, 17 Jul 2024 18:04:51 GMT' do - hca_attachment = build(:hca_attachment) - hca_attachment.set_file_data!( - Rack::Test::UploadedFile.new( - 'spec/fixtures/files/sm_file1.jpg', - 'image/jpeg' - ) - ) - hca_attachment.save! - - health_care_application = build(:health_care_application) - form = health_care_application.parsed_form - form['attachments'] = [ - { - 'confirmationCode' => hca_attachment.guid, - 'dd214' => true - } - ] - health_care_application.form = form.to_json - health_care_application.send(:remove_instance_variable, :@parsed_form) - health_care_application.save! + context 'with hasDemographicNoAnswer true' do + it 'submits successfully to hca', run_at: 'Fri, 05 May 2023 10:04:13 GMT' do + VCR.use_cassette( + 'hca/demographic_no', + VCR::MATCH_EVERYTHING.merge(erb: true) + ) do + form = get_fixture('hca/demographic_no') + expect(HealthCareApplication.new(form: form.to_json).valid?).to eq(true) + + result = HCA::Service.new.submit_form(form) + expect(result[:success]).to eq(true) + end + end + end + + context 'with a medicare claim number' do + it 'submits successfully to hca', run_at: 'Wed, 27 Jul 2022 23:54:25 GMT' do + VCR.use_cassette( + 'hca/medicare_claim_num', + VCR::MATCH_EVERYTHING.merge(erb: true) + ) do + form = get_fixture('hca/medicare_claim_num') + expect(HealthCareApplication.new(form: form.to_json).valid?).to eq(true) + + result = HCA::Service.new.submit_form(form) + expect(result[:success]).to eq(true) + end + end + end + context 'submitting sigi field' do + it 'works', run_at: 'Tue, 01 Nov 2022 15:07:20 GMT' do VCR.use_cassette( - 'hca/submit_with_attachment_jpg', + 'hca/sigi', VCR::MATCH_EVERYTHING.merge(erb: true) ) do - result = HCA::Service.new.submit_form(health_care_application.parsed_form) + result = HCA::Service.new.submit_form(get_fixture('hca/sigi')) expect(result[:success]).to eq(true) end end end - end - context 'receives a 503 response' do - it 'rescues and raises GatewayTimeout exception' do - expect(service).to receive(:connection).and_return( - Faraday.new do |conn| - conn.builder.handlers = service.send(:connection).builder.handlers.reject do |x| - x.inspect == 'Faraday::Adapter::NetHttp' - end - conn.adapter :test do |stub| - stub.post('/') { [503, { body: 'it took too long!' }, 'timeout'] } + context 'submitting tera questions' do + it 'works', run_at: 'Fri, 23 Feb 2024 19:47:28 GMT' do + VCR.use_cassette( + 'hca/tera', + VCR::MATCH_EVERYTHING.merge(erb: true) + ) do + form = get_fixture('hca/tera') + expect(HealthCareApplication.new(form: form.to_json).valid?).to eq(true) + result = HCA::Service.new.submit_form(form) + expect(result[:success]).to eq(true) + end + end + end + + context 'submitting short form' do + it 'works', run_at: 'Wed, 16 Mar 2022 20:01:14 GMT' do + VCR.use_cassette( + 'hca/short_form', + VCR::MATCH_EVERYTHING.merge(erb: true) + ) do + result = HCA::Service.new.submit_form(get_fixture('hca/short_form')) + expect(result[:success]).to eq(true) + end + end + + it 'increments statsd' do + allow(StatsD).to receive(:increment) + + expect(StatsD).to receive(:increment).with('api.1010ez.submit_form_short_form.fail', + tags: ['error:VCRErrorsUnhandledHTTPRequestError']) + expect(StatsD).to receive(:increment).with('api.1010ez.submit_form_short_form.total') + + expect do + HCA::Service.new.submit_form(get_fixture('hca/short_form')) + end.to raise_error(StandardError) + end + end + + context 'submitting with attachment' do + it 'works', run_at: 'Wed, 17 Jul 2024 18:04:50 GMT' do + VCR.use_cassette( + 'hca/submit_with_attachment', + VCR::MATCH_EVERYTHING.merge(erb: true) + ) do + result = HCA::Service.new.submit_form(create(:hca_app_with_attachment).parsed_form) + expect(result[:success]).to eq(true) + expect(Rails.logger).to have_received(:info).with('Payload for submitted 1010EZ: ' \ + 'Body size of 16 KB with 2 attachment(s)') + expect(Rails.logger).to have_received(:info).with( + 'Attachment sizes in descending order: 1.8 KB, 1.8 KB' + ) + end + end + + context 'with a non-pdf attachment' do + it 'works', run_at: 'Wed, 17 Jul 2024 18:04:51 GMT' do + hca_attachment = build(:hca_attachment) + hca_attachment.set_file_data!( + Rack::Test::UploadedFile.new( + 'spec/fixtures/files/sm_file1.jpg', + 'image/jpeg' + ) + ) + hca_attachment.save! + + health_care_application = build(:health_care_application) + form = health_care_application.parsed_form + form['attachments'] = [ + { + 'confirmationCode' => hca_attachment.guid, + 'dd214' => true + } + ] + health_care_application.form = form.to_json + health_care_application.send(:remove_instance_variable, :@parsed_form) + health_care_application.save! + + VCR.use_cassette( + 'hca/submit_with_attachment_jpg', + VCR::MATCH_EVERYTHING.merge(erb: true) + ) do + result = HCA::Service.new.submit_form(health_care_application.parsed_form) + expect(result[:success]).to eq(true) end end - ) - expect { service.send(:request, :post, '', OpenStruct.new(body: nil)) }.to raise_error( - Common::Exceptions::GatewayTimeout - ) + end + end + + context 'receives a 503 response' do + it 'rescues and raises GatewayTimeout exception' do + expect(service).to receive(:connection).and_return( + Faraday.new do |conn| + conn.builder.handlers = service.send(:connection).builder.handlers.reject do |x| + x.inspect == 'Faraday::Adapter::NetHttp' + end + conn.adapter :test do |stub| + stub.post('/') { [503, { body: 'it took too long!' }, 'timeout'] } + end + end + ) + expect { service.send(:request, :post, '', OpenStruct.new(body: nil)) }.to raise_error( + Common::Exceptions::GatewayTimeout + ) + end end end end diff --git a/spec/lib/va1010_forms/enrollment_system/service_spec.rb b/spec/lib/va1010_forms/enrollment_system/service_spec.rb new file mode 100644 index 00000000000..911970f0dc1 --- /dev/null +++ b/spec/lib/va1010_forms/enrollment_system/service_spec.rb @@ -0,0 +1,153 @@ +# frozen_string_literal: true + +require 'rails_helper' +require 'va1010_forms/enrollment_system/service' + +RSpec.describe VA1010Forms::EnrollmentSystem::Service do + include SchemaMatchers + + let(:current_user) do + create( + :evss_user, + :loa3, + icn: '1013032368V065534', + birth_date: '1986-01-02', + first_name: 'FirstName', + middle_name: 'MiddleName', + last_name: 'ZZTEST', + suffix: 'Jr.', + ssn: '111111234', + gender: 'F' + ) + end + let(:user_identifier) do + { + 'icn' => current_user.icn, + 'edipi' => current_user.edipi + } + end + let(:form) { get_fixture('form1010_ezr/valid_form') } + let(:ves_fields) do + { + 'discloseFinancialInformation' => true, + 'isEssentialAcaCoverage' => false, + 'vaMedicalFacility' => '988' + } + end + let(:form_with_ves_fields) { form.merge!(ves_fields) } + let(:response) do + double(body: Ox.parse(%( + + + + + 100 + 40124668140 + Form successfully received for EE processing + 2016-05-25T04:59:39.345-05:00 + + + + ))) + end + + describe '#submit' do + before do + allow(Rails.logger).to receive(:info) + end + + context 'when no error occurs' do + it "returns an object that includes 'success', 'formSubmissionId', and 'timestamp'", + run_at: 'Tue, 21 Nov 2023 20:42:44 GMT' do + VCR.use_cassette( + 'form1010_ezr/authorized_submit', + { match_requests_on: %i[method uri body], erb: true } + ) do + submission_response = described_class.new(user_identifier).submit( + form_with_ves_fields, + '10-10EZR' + ) + + expect(submission_response).to be_a(Object) + expect(submission_response).to eq( + { + success: true, + formSubmissionId: 436_462_561, + timestamp: '2024-08-23T13:00:11.005-05:00' + } + ) + end + end + + it "logs the payload size, attachment count, and individual attachment sizes in descending " \ + 'order (if applicable)', + run_at: 'Wed, 17 Jul 2024 18:04:50 GMT' do + VCR.use_cassette( + 'hca/submit_with_attachment', + VCR::MATCH_EVERYTHING.merge(erb: true) + ) do + described_class.new.submit( + create(:hca_app_with_attachment).parsed_form, + '10-10EZ' + ) + + expect(Rails.logger).to have_received(:info).with( + 'Payload for submitted 1010EZ: Body size of 16 KB with 2 attachment(s)' + ) + expect(Rails.logger).to have_received(:info).with( + 'Attachment sizes in descending order: 1.8 KB, 1.8 KB' + ) + end + end + end + + context 'when an error occurs' do + before do + allow_any_instance_of( + Common::Client::Base + ).to receive(:perform).and_raise( + StandardError.new('Uh oh. Some bad error occurred.') + ) + end + + it 'raises the error' do + expect { + described_class.new.submit( + form_with_ves_fields, + '10-10EZR' + ) + }.to raise_error(StandardError, 'Uh oh. Some bad error occurred.') + end + end + end + + describe '#submission_body' do + let(:user) { FactoryBot.build(:user, :loa3, icn: nil) } + + root = Rails.root.join('spec', 'fixtures', 'hca', 'conformance') + + Dir[File.join(root, '*.json')].map { |f| File.basename(f, '.json') }.each do |form| + it 'converts the JSON data into a VES-acceptable xml payload', run_at: '2016-12-12' do + allow_any_instance_of(MPIData).to receive(:icn).and_return('1000123456V123456') + + json = JSON.parse(File.open(root.join("#{form}.json")).read) + + expect(json).to match_vets_schema('10-10EZ') + + xml = File.read(root.join("#{form}.xml")) + user_identifier = form.match?(/authenticated/) ? HealthCareApplication.get_user_identifier(user) : nil + formatted = HCA::EnrollmentSystem.veteran_to_save_submit_form(json, user_identifier, '10-10EZ') + + formatted_xml_request = described_class.new(user_identifier).send(:submission_body, formatted) + pretty_printed = + Ox.dump( + Ox.parse( + formatted_xml_request + ).locate('soap:Envelope/soap:Body/ns1:submitFormRequest').first + ) + + expect(pretty_printed[1..]).to eq(xml) + end + end + end +end \ No newline at end of file From 1c48fca16ab3354f0587920748daaf2be82eb7b9 Mon Sep 17 00:00:00 2001 From: Joshua Drumm <34111449+JoshingYou1@users.noreply.github.com> Date: Tue, 24 Dec 2024 14:20:53 -0500 Subject: [PATCH 02/26] Fixed linting issues --- lib/form1010_ezr/service.rb | 11 ++---- lib/va1010_forms/enrollment_system/service.rb | 35 +++++++++---------- 2 files changed, 19 insertions(+), 27 deletions(-) diff --git a/lib/form1010_ezr/service.rb b/lib/form1010_ezr/service.rb index ef3798d7f93..7eb4f2ebf64 100644 --- a/lib/form1010_ezr/service.rb +++ b/lib/form1010_ezr/service.rb @@ -41,16 +41,9 @@ def submit_sync(parsed_form) if Flipper.enabled?(:va1010_forms_enrollment_system_service_enabled) VA1010Forms::EnrollmentSystem::Service.new( HealthCareApplication.get_user_identifier(@user) - ).submit( - parsed_form, - FORM_ID - ) + ).submit(parsed_form, FORM_ID) else - es_submit( - parsed_form, - HealthCareApplication.get_user_identifier(@user), - FORM_ID - ) + es_submit(parsed_form, HealthCareApplication.get_user_identifier(@user), FORM_ID) end end diff --git a/lib/va1010_forms/enrollment_system/service.rb b/lib/va1010_forms/enrollment_system/service.rb index ab4ad4b8aaf..5f8e51f559e 100644 --- a/lib/va1010_forms/enrollment_system/service.rb +++ b/lib/va1010_forms/enrollment_system/service.rb @@ -15,30 +15,29 @@ class Service < Common::Client::Base # @param [Hash] user_identifier # @example { 'icn' => user.icn, 'edipi' => user.edipi } def initialize(user_identifier = nil) + super() @user_identifier = user_identifier end def submit(parsed_form, form_id) - begin - formatted = HCA::EnrollmentSystem.veteran_to_save_submit_form( - parsed_form, - @user_identifier, - form_id - ) - submission_body = submission_body(formatted) - response = perform(:post, '', submission_body) + formatted = HCA::EnrollmentSystem.veteran_to_save_submit_form( + parsed_form, + @user_identifier, + form_id + ) + submission_body = submission_body(formatted) + response = perform(:post, '', submission_body) - root = response.body.locate('S:Envelope/S:Body/submitFormResponse').first - form_submission_id = root.locate('formSubmissionId').first.text.to_i + root = response.body.locate('S:Envelope/S:Body/submitFormResponse').first + form_submission_id = root.locate('formSubmissionId').first.text.to_i - { - success: true, - formSubmissionId: form_submission_id, - timestamp: root.locate('timeStamp').first&.text || Time.now.getlocal.to_s - } - rescue - raise - end + { + success: true, + formSubmissionId: form_submission_id, + timestamp: root.locate('timeStamp').first&.text || Time.now.getlocal.to_s + } + rescue + raise end private From fd68cdd1f58fc400738843a01bfabf764fb7632e Mon Sep 17 00:00:00 2001 From: Joshua Drumm <34111449+JoshingYou1@users.noreply.github.com> Date: Tue, 24 Dec 2024 14:33:18 -0500 Subject: [PATCH 03/26] Fixed linting issues --- lib/va1010_forms/enrollment_system/service.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/va1010_forms/enrollment_system/service.rb b/lib/va1010_forms/enrollment_system/service.rb index 5f8e51f559e..1bc866fd716 100644 --- a/lib/va1010_forms/enrollment_system/service.rb +++ b/lib/va1010_forms/enrollment_system/service.rb @@ -36,8 +36,8 @@ def submit(parsed_form, form_id) formSubmissionId: form_submission_id, timestamp: root.locate('timeStamp').first&.text || Time.now.getlocal.to_s } - rescue - raise + rescue => e + raise e end private From 92a5f1ff5241f454ea94d66ae77b3e56c35cfb2b Mon Sep 17 00:00:00 2001 From: Joshua Drumm <34111449+JoshingYou1@users.noreply.github.com> Date: Tue, 24 Dec 2024 15:47:56 -0500 Subject: [PATCH 04/26] Removed some unused test code and updated the swagger specs for HCA --- spec/lib/va1010_forms/utils_spec.rb | 15 ----- spec/requests/swagger_spec.rb | 87 +++++++++++++++++++++-------- 2 files changed, 65 insertions(+), 37 deletions(-) diff --git a/spec/lib/va1010_forms/utils_spec.rb b/spec/lib/va1010_forms/utils_spec.rb index 141e6fcdd6c..d3a9687a7be 100644 --- a/spec/lib/va1010_forms/utils_spec.rb +++ b/spec/lib/va1010_forms/utils_spec.rb @@ -38,19 +38,4 @@ end end end - - describe '#override_parsed_form' do - context 'when the form contains a Mexican province as an address state' do - subject do - super().override_parsed_form(form_with_mexican_province) - end - - let(:form_with_mexican_province) { get_fixture('form1010_ezr/valid_form_with_mexican_province') } - - it 'returns the correct corresponding province abbreviation' do - expect(subject['veteranAddress']['state']).to eq('CHIH.') - expect(subject['veteranHomeAddress']['state']).to eq('CHIH.') - end - end - end end diff --git a/spec/requests/swagger_spec.rb b/spec/requests/swagger_spec.rb index bc21779cef4..1981e2f36aa 100644 --- a/spec/requests/swagger_spec.rb +++ b/spec/requests/swagger_spec.rb @@ -806,39 +806,82 @@ expect(subject).to validate(:post, '/v0/hca_attachments', 400, '') end - it 'supports submitting a health care application', run_at: '2017-01-31' do - VCR.use_cassette('hca/submit_anon', match_requests_on: [:body]) do + context "when the 'va1010_forms_enrollment_system_service_enabled' flipper is enabled" do + it 'supports submitting a health care application', run_at: '2017-01-31' do + VCR.use_cassette('hca/submit_anon', match_requests_on: [:body]) do + expect(subject).to validate( + :post, + '/v0/health_care_applications', + 200, + '_data' => { + 'form' => test_veteran + } + ) + end + expect(subject).to validate( :post, '/v0/health_care_applications', - 200, + 422, + '_data' => { + 'form' => {}.to_json + } + ) + + allow_any_instance_of(HCA::Service).to receive(:submit_form) do + raise Common::Client::Errors::HTTPError, 'error message' + end + + expect(subject).to validate( + :post, + '/v0/health_care_applications', + 400, '_data' => { 'form' => test_veteran } ) end + end - expect(subject).to validate( - :post, - '/v0/health_care_applications', - 422, - '_data' => { - 'form' => {}.to_json - } - ) - - allow_any_instance_of(HCA::Service).to receive(:post) do - raise Common::Client::Errors::HTTPError, 'error message' + context "when the 'va1010_forms_enrollment_system_service_enabled' flipper is disabled" do + before do + Flipper.disable(:va1010_forms_enrollment_system_service_enabled) end - expect(subject).to validate( - :post, - '/v0/health_care_applications', - 400, - '_data' => { - 'form' => test_veteran - } - ) + it 'supports submitting a health care application', run_at: '2017-01-31' do + VCR.use_cassette('hca/submit_anon', match_requests_on: [:body]) do + expect(subject).to validate( + :post, + '/v0/health_care_applications', + 200, + '_data' => { + 'form' => test_veteran + } + ) + end + + expect(subject).to validate( + :post, + '/v0/health_care_applications', + 422, + '_data' => { + 'form' => {}.to_json + } + ) + + allow_any_instance_of(HCA::Service).to receive(:post) do + raise Common::Client::Errors::HTTPError, 'error message' + end + + expect(subject).to validate( + :post, + '/v0/health_care_applications', + 400, + '_data' => { + 'form' => test_veteran + } + ) + end end end From 993d293a585f4b64ffe62c9101c82352ad9029fd Mon Sep 17 00:00:00 2001 From: Joshua Drumm <34111449+JoshingYou1@users.noreply.github.com> Date: Tue, 24 Dec 2024 16:03:00 -0500 Subject: [PATCH 05/26] Fixed some failing tests --- app/models/health_care_application.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/health_care_application.rb b/app/models/health_care_application.rb index 15fc10b0705..c0c421ab26b 100644 --- a/app/models/health_care_application.rb +++ b/app/models/health_care_application.rb @@ -240,7 +240,7 @@ def prefill_fields def submit_async submission_job = email.present? ? 'SubmissionJob' : 'AnonSubmissionJob' - @parsed_form = override_parsed_form(parsed_form) + @parsed_form = HCA::OverridesParser.new(parsed_form).override "HCA::#{submission_job}".constantize.perform_async( self.class.get_user_identifier(user), From 874539a9e6f29e9e253415eb5185da5e34cbc699 Mon Sep 17 00:00:00 2001 From: Joshua Drumm <34111449+JoshingYou1@users.noreply.github.com> Date: Tue, 24 Dec 2024 17:44:13 -0500 Subject: [PATCH 06/26] Fixed a couple more failing tests --- spec/requests/v0/health_care_applications_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/requests/v0/health_care_applications_spec.rb b/spec/requests/v0/health_care_applications_spec.rb index 0ecbb316767..14c46818514 100644 --- a/spec/requests/v0/health_care_applications_spec.rb +++ b/spec/requests/v0/health_care_applications_spec.rb @@ -455,7 +455,7 @@ def self.expect_async_submit context 'when hca service raises an error' do before do test_veteran.delete('email') - allow_any_instance_of(HCA::Service).to receive(:post) do + allow_any_instance_of(HCA::Service).to receive(:submit_form) do raise error end end From 03066c651af4c4b48cfbc952cad2f590ee41ccae Mon Sep 17 00:00:00 2001 From: Joshua Drumm <34111449+JoshingYou1@users.noreply.github.com> Date: Tue, 24 Dec 2024 17:57:01 -0500 Subject: [PATCH 07/26] Separated tests with flipper enabled and disabled --- .../v0/health_care_applications_spec.rb | 72 +++++++++++-------- 1 file changed, 42 insertions(+), 30 deletions(-) diff --git a/spec/requests/v0/health_care_applications_spec.rb b/spec/requests/v0/health_care_applications_spec.rb index 14c46818514..eba2ca58beb 100644 --- a/spec/requests/v0/health_care_applications_spec.rb +++ b/spec/requests/v0/health_care_applications_spec.rb @@ -453,46 +453,58 @@ def self.expect_async_submit end context 'when hca service raises an error' do - before do - test_veteran.delete('email') - allow_any_instance_of(HCA::Service).to receive(:submit_form) do - raise error + context "when the 'va1010_forms_enrollment_system_service_enabled' flipper is enabled" do + before do + test_veteran.delete('email') + allow_any_instance_of(HCA::Service).to receive(:submit_form) do + raise error + end end - end - context 'with a validation error' do - let(:error) { HCA::SOAPParser::ValidationError.new } + context 'with a validation error' do + let(:error) { HCA::SOAPParser::ValidationError.new } - it 'renders error message' do - subject + it 'renders error message' do + subject - expect(response).to have_http_status(:unprocessable_entity) - expect(JSON.parse(response.body)).to eq( - 'errors' => [ - { 'title' => 'Operation failed', 'detail' => 'Validation error', 'code' => 'HCA422', 'status' => '422' } - ] - ) + expect(response).to have_http_status(:unprocessable_entity) + expect(JSON.parse(response.body)).to eq( + 'errors' => [ + { 'title' => 'Operation failed', 'detail' => 'Validation error', 'code' => 'HCA422', 'status' => '422' } + ] + ) + end end - end - context 'with a SOAP error' do - let(:error) { Common::Client::Errors::HTTPError.new('error message') } + context 'with a SOAP error' do + let(:error) { Common::Client::Errors::HTTPError.new('error message') } - before do - allow(Settings.sentry).to receive(:dsn).and_return('asdf') - end + before do + allow(Settings.sentry).to receive(:dsn).and_return('asdf') + end - it 'renders error message' do - expect(Sentry).to receive(:capture_exception).with(error, level: 'error').once + it 'renders error message' do + expect(Sentry).to receive(:capture_exception).with(error, level: 'error').once - subject + subject - expect(response).to have_http_status(:bad_request) - expect(JSON.parse(response.body)).to eq( - 'errors' => [ - { 'title' => 'Operation failed', 'detail' => 'error message', 'code' => 'VA900', 'status' => '400' } - ] - ) + expect(response).to have_http_status(:bad_request) + expect(JSON.parse(response.body)).to eq( + 'errors' => [ + { 'title' => 'Operation failed', 'detail' => 'error message', 'code' => 'VA900', 'status' => '400' } + ] + ) + end + end + end + + context "when the 'va1010_forms_enrollment_system_service_enabled' flipper is disabled" do + before do + Flipper.disable(:va1010_forms_enrollment_system_service_enabled) + test_veteran.delete('email') + allow_any_instance_of(HCA::Service).to receive(:post) do + raise error + end end end end From 6f18f95770787758ab004c563c942ffd535f7b95 Mon Sep 17 00:00:00 2001 From: Joshua Drumm <34111449+JoshingYou1@users.noreply.github.com> Date: Thu, 26 Dec 2024 14:36:43 -0500 Subject: [PATCH 08/26] Fixed linting issue --- lib/va1010_forms/enrollment_system/service.rb | 2 -- spec/lib/va1010_forms/enrollment_system/service_spec.rb | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/va1010_forms/enrollment_system/service.rb b/lib/va1010_forms/enrollment_system/service.rb index 1bc866fd716..34f05204728 100644 --- a/lib/va1010_forms/enrollment_system/service.rb +++ b/lib/va1010_forms/enrollment_system/service.rb @@ -36,8 +36,6 @@ def submit(parsed_form, form_id) formSubmissionId: form_submission_id, timestamp: root.locate('timeStamp').first&.text || Time.now.getlocal.to_s } - rescue => e - raise e end private diff --git a/spec/lib/va1010_forms/enrollment_system/service_spec.rb b/spec/lib/va1010_forms/enrollment_system/service_spec.rb index 911970f0dc1..2c576286582 100644 --- a/spec/lib/va1010_forms/enrollment_system/service_spec.rb +++ b/spec/lib/va1010_forms/enrollment_system/service_spec.rb @@ -108,6 +108,7 @@ ).to receive(:perform).and_raise( StandardError.new('Uh oh. Some bad error occurred.') ) + allow(Rails.logger).to receive(:error) end it 'raises the error' do From efb51416c7c8a8cd076c3764724c38b8d93299d4 Mon Sep 17 00:00:00 2001 From: Joshua Drumm <34111449+JoshingYou1@users.noreply.github.com> Date: Thu, 26 Dec 2024 15:35:01 -0500 Subject: [PATCH 09/26] Fixed linting issue --- spec/lib/form1010_ezr/service_spec.rb | 14 ++++++-------- spec/lib/hca/service_spec.rb | 25 +++++++++++++++---------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/spec/lib/form1010_ezr/service_spec.rb b/spec/lib/form1010_ezr/service_spec.rb index d98c6b8da01..71b29e13220 100644 --- a/spec/lib/form1010_ezr/service_spec.rb +++ b/spec/lib/form1010_ezr/service_spec.rb @@ -192,9 +192,7 @@ def ezr_form_with_attachments [1, 2].each do |i| describe '#submit_form' do before do - if i == 2 - Flipper.disable(:va1010_forms_enrollment_system_service_enabled) - end + Flipper.disable(:va1010_forms_enrollment_system_service_enabled) if i == 2 end it 'submits the ezr with a background job', run_at: 'Tue, 21 Nov 2023 20:42:44 GMT' do @@ -332,7 +330,7 @@ def ezr_form_with_attachments end it "returns an object that includes 'success', 'formSubmissionId', and 'timestamp'", - run_at: 'Tue, 21 Nov 2023 20:42:44 GMT' do + run_at: 'Tue, 21 Nov 2023 20:42:44 GMT' do VCR.use_cassette( 'form1010_ezr/authorized_submit', { match_requests_on: %i[method uri body], erb: true } @@ -351,8 +349,7 @@ def ezr_form_with_attachments end it "logs the submission id, user's initials, payload size, and individual attachment sizes in descending " \ - 'order (if applicable)', - run_at: 'Wed, 17 Jul 2024 18:17:30 GMT' do + 'order (if applicable)', run_at: 'Wed, 17 Jul 2024 18:17:30 GMT' do VCR.use_cassette( 'form1010_ezr/authorized_submit_with_attachments', { match_requests_on: %i[method uri body], erb: true } @@ -368,8 +365,9 @@ def ezr_form_with_attachments last_initial: 'Z' } ) - expect(Rails.logger).to have_received(:info).with('Payload for submitted 1010EZR: ' \ - 'Body size of 362 KB with 2 attachment(s)') + expect(Rails.logger).to have_received(:info).with( + 'Payload for submitted 1010EZR: Body size of 362 KB with 2 attachment(s)' + ) expect(Rails.logger).to have_received(:info).with( 'Attachment sizes in descending order: 348 KB, 1.8 KB' ) diff --git a/spec/lib/hca/service_spec.rb b/spec/lib/hca/service_spec.rb index 977f9d598f8..37e70aebeb8 100644 --- a/spec/lib/hca/service_spec.rb +++ b/spec/lib/hca/service_spec.rb @@ -61,15 +61,17 @@ ) do result = HCA::Service.new.submit_form(get_fixture('hca/short_form')) expect(result[:success]).to eq(true) - expect(Rails.logger).to have_received(:info).with('Payload for submitted 1010EZ: ' \ - 'Body size of 5.16 KB with 0 attachment(s)') + expect(Rails.logger).to have_received(:info).with( + 'Payload for submitted 1010EZ: Body size of 5.16 KB with 0 attachment(s)' + ) end end end it 'increments statsd' do - expect(StatsD).to receive(:increment).with('api.1010ez.submit_form.fail', - tags: ['error:VCRErrorsUnhandledHTTPRequestError']) + expect(StatsD).to receive(:increment).with( + 'api.1010ez.submit_form.fail', tags: ['error:VCRErrorsUnhandledHTTPRequestError'] + ) expect(StatsD).to receive(:increment).with('api.1010ez.submit_form.total') expect do @@ -153,8 +155,9 @@ it 'increments statsd' do allow(StatsD).to receive(:increment) - expect(StatsD).to receive(:increment).with('api.1010ez.submit_form_short_form.fail', - tags: ['error:VCRErrorsUnhandledHTTPRequestError']) + expect(StatsD).to receive(:increment).with( + 'api.1010ez.submit_form_short_form.fail', tags: ['error:VCRErrorsUnhandledHTTPRequestError'] + ) expect(StatsD).to receive(:increment).with('api.1010ez.submit_form_short_form.total') expect do @@ -171,8 +174,9 @@ ) do result = HCA::Service.new.submit_form(create(:hca_app_with_attachment).parsed_form) expect(result[:success]).to eq(true) - expect(Rails.logger).to have_received(:info).with('Payload for submitted 1010EZ: ' \ - 'Body size of 16 KB with 2 attachment(s)') + expect(Rails.logger).to have_received(:info).with( + 'Payload for submitted 1010EZ: Body size of 16 KB with 2 attachment(s)' + ) expect(Rails.logger).to have_received(:info).with( 'Attachment sizes in descending order: 1.8 KB, 1.8 KB' ) @@ -254,8 +258,9 @@ ) do result = HCA::Service.new.submit_form(get_fixture('hca/short_form')) expect(result[:success]).to eq(true) - expect(Rails.logger).to have_received(:info).with('Payload for submitted 1010EZ: ' \ - 'Body size of 5.16 KB with 0 attachment(s)') + expect(Rails.logger).to have_received(:info).with( + 'Payload for submitted 1010EZ: Body size of 5.16 KB with 0 attachment(s)' + ) end end end From f2a6d59f137f6fba2c078db2706adf4c51f1a4b8 Mon Sep 17 00:00:00 2001 From: Joshua Drumm <34111449+JoshingYou1@users.noreply.github.com> Date: Thu, 26 Dec 2024 15:45:53 -0500 Subject: [PATCH 10/26] Fixed linting issues --- .../va1010_forms/enrollment_system/service_spec.rb | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/spec/lib/va1010_forms/enrollment_system/service_spec.rb b/spec/lib/va1010_forms/enrollment_system/service_spec.rb index 2c576286582..d0f809f9d85 100644 --- a/spec/lib/va1010_forms/enrollment_system/service_spec.rb +++ b/spec/lib/va1010_forms/enrollment_system/service_spec.rb @@ -58,7 +58,7 @@ context 'when no error occurs' do it "returns an object that includes 'success', 'formSubmissionId', and 'timestamp'", - run_at: 'Tue, 21 Nov 2023 20:42:44 GMT' do + run_at: 'Tue, 21 Nov 2023 20:42:44 GMT' do VCR.use_cassette( 'form1010_ezr/authorized_submit', { match_requests_on: %i[method uri body], erb: true } @@ -79,9 +79,8 @@ end end - it "logs the payload size, attachment count, and individual attachment sizes in descending " \ - 'order (if applicable)', - run_at: 'Wed, 17 Jul 2024 18:04:50 GMT' do + it 'logs the payload size, attachment count, and individual attachment sizes in descending ' \ + 'order (if applicable)', run_at: 'Wed, 17 Jul 2024 18:04:50 GMT' do VCR.use_cassette( 'hca/submit_with_attachment', VCR::MATCH_EVERYTHING.merge(erb: true) @@ -112,12 +111,12 @@ end it 'raises the error' do - expect { + expect do described_class.new.submit( form_with_ves_fields, '10-10EZR' ) - }.to raise_error(StandardError, 'Uh oh. Some bad error occurred.') + end.to raise_error(StandardError, 'Uh oh. Some bad error occurred.') end end end @@ -131,7 +130,7 @@ it 'converts the JSON data into a VES-acceptable xml payload', run_at: '2016-12-12' do allow_any_instance_of(MPIData).to receive(:icn).and_return('1000123456V123456') - json = JSON.parse(File.open(root.join("#{form}.json")).read) + json = JSON.parse(File.read(root.join("#{form}.json"))) expect(json).to match_vets_schema('10-10EZ') From 49c107b648eac2fd67c90a74201b6b94139299ee Mon Sep 17 00:00:00 2001 From: Joshua Drumm <34111449+JoshingYou1@users.noreply.github.com> Date: Thu, 26 Dec 2024 16:23:30 -0500 Subject: [PATCH 11/26] Fixed linting issues --- spec/lib/hca/service_spec.rb | 18 +++++++++++------- .../enrollment_system/service_spec.rb | 2 +- .../v0/health_care_applications_spec.rb | 7 ++++++- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/spec/lib/hca/service_spec.rb b/spec/lib/hca/service_spec.rb index 37e70aebeb8..cfe7ecf0ace 100644 --- a/spec/lib/hca/service_spec.rb +++ b/spec/lib/hca/service_spec.rb @@ -266,8 +266,9 @@ end it 'increments statsd' do - expect(StatsD).to receive(:increment).with('api.1010ez.submit_form.fail', - tags: ['error:VCRErrorsUnhandledHTTPRequestError']) + expect(StatsD).to receive(:increment).with( + 'api.1010ez.submit_form.fail', tags: ['error:VCRErrorsUnhandledHTTPRequestError'] + ) expect(StatsD).to receive(:increment).with('api.1010ez.submit_form.total') expect do @@ -300,7 +301,8 @@ xml = File.read(root.join("#{form}.xml")) expect(service).to receive(:perform) do |_verb, _, body| submission = body - pretty_printed = Ox.dump(Ox.parse(submission).locate('soap:Envelope/soap:Body/ns1:submitFormRequest').first) + pretty_printed = + Ox.dump(Ox.parse(submission).locate('soap:Envelope/soap:Body/ns1:submitFormRequest').first) expect(pretty_printed[1..]).to eq(xml) end.and_return(response) @@ -379,8 +381,9 @@ it 'increments statsd' do allow(StatsD).to receive(:increment) - expect(StatsD).to receive(:increment).with('api.1010ez.submit_form_short_form.fail', - tags: ['error:VCRErrorsUnhandledHTTPRequestError']) + expect(StatsD).to receive(:increment).with( + 'api.1010ez.submit_form_short_form.fail', tags: ['error:VCRErrorsUnhandledHTTPRequestError'] + ) expect(StatsD).to receive(:increment).with('api.1010ez.submit_form_short_form.total') expect do @@ -397,8 +400,9 @@ ) do result = HCA::Service.new.submit_form(create(:hca_app_with_attachment).parsed_form) expect(result[:success]).to eq(true) - expect(Rails.logger).to have_received(:info).with('Payload for submitted 1010EZ: ' \ - 'Body size of 16 KB with 2 attachment(s)') + expect(Rails.logger).to have_received(:info).with( + 'Payload for submitted 1010EZ: Body size of 16 KB with 2 attachment(s)' + ) expect(Rails.logger).to have_received(:info).with( 'Attachment sizes in descending order: 1.8 KB, 1.8 KB' ) diff --git a/spec/lib/va1010_forms/enrollment_system/service_spec.rb b/spec/lib/va1010_forms/enrollment_system/service_spec.rb index d0f809f9d85..8c2911a0057 100644 --- a/spec/lib/va1010_forms/enrollment_system/service_spec.rb +++ b/spec/lib/va1010_forms/enrollment_system/service_spec.rb @@ -150,4 +150,4 @@ end end end -end \ No newline at end of file +end diff --git a/spec/requests/v0/health_care_applications_spec.rb b/spec/requests/v0/health_care_applications_spec.rb index eba2ca58beb..c1225dbffdb 100644 --- a/spec/requests/v0/health_care_applications_spec.rb +++ b/spec/requests/v0/health_care_applications_spec.rb @@ -491,7 +491,12 @@ def self.expect_async_submit expect(response).to have_http_status(:bad_request) expect(JSON.parse(response.body)).to eq( 'errors' => [ - { 'title' => 'Operation failed', 'detail' => 'error message', 'code' => 'VA900', 'status' => '400' } + { + 'title' => 'Operation failed', + 'detail' => 'error message', + 'code' => 'VA900', + 'status' => '400' + } ] ) end From ae3a4193aa39ff81b5654e25481318b7b7fffd45 Mon Sep 17 00:00:00 2001 From: Joshua Drumm <34111449+JoshingYou1@users.noreply.github.com> Date: Thu, 26 Dec 2024 16:26:44 -0500 Subject: [PATCH 12/26] Fixed linting issue --- spec/requests/v0/health_care_applications_spec.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/spec/requests/v0/health_care_applications_spec.rb b/spec/requests/v0/health_care_applications_spec.rb index c1225dbffdb..9891f89af6f 100644 --- a/spec/requests/v0/health_care_applications_spec.rb +++ b/spec/requests/v0/health_care_applications_spec.rb @@ -470,7 +470,12 @@ def self.expect_async_submit expect(response).to have_http_status(:unprocessable_entity) expect(JSON.parse(response.body)).to eq( 'errors' => [ - { 'title' => 'Operation failed', 'detail' => 'Validation error', 'code' => 'HCA422', 'status' => '422' } + { + 'title' => 'Operation failed', + 'detail' => 'Validation error', + 'code' => 'HCA422', + 'status' => '422' + } ] ) end From 9347b9b75d266a52004067c48d0bd777c650904b Mon Sep 17 00:00:00 2001 From: Joshua Drumm <34111449+JoshingYou1@users.noreply.github.com> Date: Tue, 7 Jan 2025 14:57:29 -0500 Subject: [PATCH 13/26] Removed some code changes that were made in a different branch --- app/models/health_care_application.rb | 1 + lib/form1010_ezr/service.rb | 14 +++++--------- lib/va1010_forms/enrollment_system/service.rb | 3 +++ .../va1010_forms/enrollment_system/service_spec.rb | 8 ++++++-- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/app/models/health_care_application.rb b/app/models/health_care_application.rb index c0c421ab26b..6faecec23bb 100644 --- a/app/models/health_care_application.rb +++ b/app/models/health_care_application.rb @@ -6,6 +6,7 @@ require 'hca/enrollment_eligibility/service' require 'hca/enrollment_eligibility/status_matcher' require 'mpi/service' +require 'hca/overrides_parser' class HealthCareApplication < ApplicationRecord include SentryLogging diff --git a/lib/form1010_ezr/service.rb b/lib/form1010_ezr/service.rb index 7eb4f2ebf64..3785039c2b6 100644 --- a/lib/form1010_ezr/service.rb +++ b/lib/form1010_ezr/service.rb @@ -5,7 +5,7 @@ require 'hca/configuration' require 'hca/ezr_postfill' require 'va1010_forms/utils' -require 'va1010_forms/enrollment_system/service' +require 'hca/overrides_parser' module Form1010Ezr class Service < Common::Client::Base @@ -60,7 +60,8 @@ def submit_sync(parsed_form) res rescue => e - log_and_raise_error(e, parsed_form) + log_submission_failure(parsed_form) + raise e end # @param [HashWithIndifferentAccess] parsed_form JSON form data @@ -72,7 +73,8 @@ def submit_form(parsed_form) submit_async(parsed_form) rescue => e - log_and_raise_error(e, parsed_form) + log_submission_failure(parsed_form) + raise e end def log_submission_failure(parsed_form) @@ -184,11 +186,5 @@ def log_validation_errors(errors, parsed_form) error_class: 'Form1010Ezr ValidationError' ) end - - def log_and_raise_error(error, form) - log_submission_failure(form) - Rails.logger.error "10-10EZR form submission failed: #{error.message}" - raise error - end end end diff --git a/lib/va1010_forms/enrollment_system/service.rb b/lib/va1010_forms/enrollment_system/service.rb index 34f05204728..87ec66ffc73 100644 --- a/lib/va1010_forms/enrollment_system/service.rb +++ b/lib/va1010_forms/enrollment_system/service.rb @@ -36,6 +36,9 @@ def submit(parsed_form, form_id) formSubmissionId: form_submission_id, timestamp: root.locate('timeStamp').first&.text || Time.now.getlocal.to_s } + rescue => e + Rails.logger.error "#{form_id} form submission failed: #{e.message}" + raise e end private diff --git a/spec/lib/va1010_forms/enrollment_system/service_spec.rb b/spec/lib/va1010_forms/enrollment_system/service_spec.rb index 8c2911a0057..a72e227d6e4 100644 --- a/spec/lib/va1010_forms/enrollment_system/service_spec.rb +++ b/spec/lib/va1010_forms/enrollment_system/service_spec.rb @@ -54,11 +54,12 @@ describe '#submit' do before do allow(Rails.logger).to receive(:info) + allow(Rails.logger).to receive(:error) end context 'when no error occurs' do it "returns an object that includes 'success', 'formSubmissionId', and 'timestamp'", - run_at: 'Tue, 21 Nov 2023 20:42:44 GMT' do + run_at: 'Tue, 21 Nov 2023 20:42:44 GMT' do VCR.use_cassette( 'form1010_ezr/authorized_submit', { match_requests_on: %i[method uri body], erb: true } @@ -110,13 +111,16 @@ allow(Rails.logger).to receive(:error) end - it 'raises the error' do + it 'logs and raises the error' do expect do described_class.new.submit( form_with_ves_fields, '10-10EZR' ) end.to raise_error(StandardError, 'Uh oh. Some bad error occurred.') + expect(Rails.logger).to have_received(:error).with( + '10-10EZR form submission failed: Uh oh. Some bad error occurred.' + ) end end end From 7d05fde45b58fc632ef73198635096039eb441b5 Mon Sep 17 00:00:00 2001 From: Joshua Drumm <34111449+JoshingYou1@users.noreply.github.com> Date: Tue, 7 Jan 2025 17:06:53 -0500 Subject: [PATCH 14/26] Cleaned up some test code --- lib/form1010_ezr/service.rb | 4 +- .../v0/health_care_applications_spec.rb | 142 ++++++++++++------ 2 files changed, 100 insertions(+), 46 deletions(-) diff --git a/lib/form1010_ezr/service.rb b/lib/form1010_ezr/service.rb index 3785039c2b6..3f8b11fabfe 100644 --- a/lib/form1010_ezr/service.rb +++ b/lib/form1010_ezr/service.rb @@ -6,6 +6,7 @@ require 'hca/ezr_postfill' require 'va1010_forms/utils' require 'hca/overrides_parser' +require 'va1010_forms/enrollment_system/service' module Form1010Ezr class Service < Common::Client::Base @@ -48,8 +49,7 @@ def submit_sync(parsed_form) end # Log the 'formSubmissionId' for successful submissions - Rails.logger.info( - '1010EZR successfully submitted', + Rails.logger.info('1010EZR successfully submitted', submission_id: res[:formSubmissionId], veteran_initials: veteran_initials(parsed_form) ) diff --git a/spec/requests/v0/health_care_applications_spec.rb b/spec/requests/v0/health_care_applications_spec.rb index 9891f89af6f..aabc2e955d0 100644 --- a/spec/requests/v0/health_care_applications_spec.rb +++ b/spec/requests/v0/health_care_applications_spec.rb @@ -160,7 +160,7 @@ it 'returns 404' do get(enrollment_status_v0_health_care_applications_path, - params: { userAttributes: build(:health_care_application).parsed_form }) + params: { userAttributes: build(:health_care_application).parsed_form }) expect(response).to have_http_status(:not_found) end end @@ -172,7 +172,7 @@ ).and_return(success_response) get(enrollment_status_v0_health_care_applications_path, - params: { userAttributes: build(:health_care_application).parsed_form }) + params: { userAttributes: build(:health_care_application).parsed_form }) expect(response.body).to eq(success_response.to_json) end @@ -234,42 +234,50 @@ end expect(response).to have_http_status(:ok) expect(response.parsed_body[0]).to eq({ 'access' => nil, - 'active_status' => nil, - 'address' => { - 'mailing' => { 'zip' => '66713', 'city' => 'Leavenworth', - 'state' => 'KS', 'address1' => '150 Muncie Rd' }, - 'physical' => { 'zip' => '66713', 'city' => 'Baxter Springs', - 'state' => 'KS', - 'address1' => 'Baxter Springs City Cemetery' } - }, - 'classification' => 'Soldiers Lot', - 'detailed_services' => nil, - 'distance' => nil, - 'facility_type' => 'va_cemetery', - 'facility_type_prefix' => 'nca', - 'feedback' => nil, - 'hours' => - { 'monday' => 'Sunrise - Sundown', - 'tuesday' => 'Sunrise - Sundown', - 'wednesday' => 'Sunrise - Sundown', - 'thursday' => 'Sunrise - Sundown', - 'friday' => 'Sunrise - Sundown', - 'saturday' => 'Sunrise - Sundown', - 'sunday' => 'Sunrise - Sundown' }, - 'id' => 'nca_042', - 'lat' => 37.0320575, - 'long' => -94.7706605, - 'mobile' => nil, - 'name' => "Baxter Springs City Soldiers' Lot", - 'operating_status' => { 'code' => 'NORMAL' }, - 'operational_hours_special_instructions' => nil, - 'parent' => nil, - 'phone' => { 'fax' => '9137584136', 'main' => '9137584105' }, - 'services' => nil, - 'type' => 'va_facilities', - 'unique_id' => '042', - 'visn' => nil, - 'website' => 'https://www.cem.va.gov/cems/lots/BaxterSprings.asp' }) + 'active_status' => nil, + 'address' => { + 'mailing' => { + 'zip' => '66713', + 'city' => 'Leavenworth', + 'state' => 'KS', + 'address1' => '150 Muncie Rd' + }, + 'physical' => { + 'zip' => '66713', + 'city' => 'Baxter Springs', + 'state' => 'KS', + 'address1' => 'Baxter Springs City Cemetery' + } + }, + 'classification' => 'Soldiers Lot', + 'detailed_services' => nil, + 'distance' => nil, + 'facility_type' => 'va_cemetery', + 'facility_type_prefix' => 'nca', + 'feedback' => nil, + 'hours' => { + 'monday' => 'Sunrise - Sundown', + 'tuesday' => 'Sunrise - Sundown', + 'wednesday' => 'Sunrise - Sundown', + 'thursday' => 'Sunrise - Sundown', + 'friday' => 'Sunrise - Sundown', + 'saturday' => 'Sunrise - Sundown', + 'sunday' => 'Sunrise - Sundown' + }, + 'id' => 'nca_042', + 'lat' => 37.0320575, + 'long' => -94.7706605, + 'mobile' => nil, + 'name' => "Baxter Springs City Soldiers' Lot", + 'operating_status' => { 'code' => 'NORMAL' }, + 'operational_hours_special_instructions' => nil, + 'parent' => nil, + 'phone' => { 'fax' => '9137584136', 'main' => '9137584105' }, + 'services' => nil, + 'type' => 'va_facilities', + 'unique_id' => '042', + 'visn' => nil, + 'website' => 'https://www.cem.va.gov/cems/lots/BaxterSprings.asp' }) end context 'with hca_retrieve_facilities_without_repopulating disabled' do @@ -302,8 +310,8 @@ describe 'POST create' do subject do post(v0_health_care_applications_path, - params: params.to_json, - headers: { 'CONTENT_TYPE' => 'application/json', 'HTTP_X_KEY_INFLECTION' => 'camel' }) + params: params.to_json, + headers: { 'CONTENT_TYPE' => 'application/json', 'HTTP_X_KEY_INFLECTION' => 'camel' }) end context 'with invalid params' do @@ -342,10 +350,10 @@ def self.expect_async_submit body = JSON.parse(response.body) expect(body).to eq( 'data' => - { 'id' => HealthCareApplication.last.id.to_s, - 'type' => 'health_care_applications', - 'attributes' => - { 'state' => 'pending', 'formSubmissionId' => nil, 'timestamp' => nil } } + { 'id' => HealthCareApplication.last.id.to_s, + 'type' => 'health_care_applications', + 'attributes' => + { 'state' => 'pending', 'formSubmissionId' => nil, 'timestamp' => nil } } ) end end @@ -516,6 +524,52 @@ def self.expect_async_submit raise error end end + + context 'with a validation error' do + let(:error) { HCA::SOAPParser::ValidationError.new } + + it 'renders error message' do + subject + + expect(response).to have_http_status(:unprocessable_entity) + expect(JSON.parse(response.body)).to eq( + 'errors' => [ + { + 'title' => 'Operation failed', + 'detail' => 'Validation error', + 'code' => 'HCA422', + 'status' => '422' + } + ] + ) + end + end + + context 'with a SOAP error' do + let(:error) { Common::Client::Errors::HTTPError.new('error message') } + + before do + allow(Settings.sentry).to receive(:dsn).and_return('asdf') + end + + it 'renders error message' do + expect(Sentry).to receive(:capture_exception).with(error, level: 'error').once + + subject + + expect(response).to have_http_status(:bad_request) + expect(JSON.parse(response.body)).to eq( + 'errors' => [ + { + 'title' => 'Operation failed', + 'detail' => 'error message', + 'code' => 'VA900', + 'status' => '400' + } + ] + ) + end + end end end From afe133742157cf866875b0cafbeb2a05a85591fc Mon Sep 17 00:00:00 2001 From: Joshua Drumm <34111449+JoshingYou1@users.noreply.github.com> Date: Tue, 7 Jan 2025 17:13:57 -0500 Subject: [PATCH 15/26] Fixed some linting errors --- lib/form1010_ezr/service.rb | 3 ++- .../v0/health_care_applications_spec.rb | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/form1010_ezr/service.rb b/lib/form1010_ezr/service.rb index 3f8b11fabfe..64a49084aad 100644 --- a/lib/form1010_ezr/service.rb +++ b/lib/form1010_ezr/service.rb @@ -49,7 +49,8 @@ def submit_sync(parsed_form) end # Log the 'formSubmissionId' for successful submissions - Rails.logger.info('1010EZR successfully submitted', + Rails.logger.info( + '1010EZR successfully submitted', submission_id: res[:formSubmissionId], veteran_initials: veteran_initials(parsed_form) ) diff --git a/spec/requests/v0/health_care_applications_spec.rb b/spec/requests/v0/health_care_applications_spec.rb index aabc2e955d0..ef7d12f851e 100644 --- a/spec/requests/v0/health_care_applications_spec.rb +++ b/spec/requests/v0/health_care_applications_spec.rb @@ -159,8 +159,10 @@ end it 'returns 404' do - get(enrollment_status_v0_health_care_applications_path, - params: { userAttributes: build(:health_care_application).parsed_form }) + get( + enrollment_status_v0_health_care_applications_path, + params: { userAttributes: build(:health_care_application).parsed_form } + ) expect(response).to have_http_status(:not_found) end end @@ -171,8 +173,10 @@ current_user.icn, true ).and_return(success_response) - get(enrollment_status_v0_health_care_applications_path, - params: { userAttributes: build(:health_care_application).parsed_form }) + get( + enrollment_status_v0_health_care_applications_path, + params: { userAttributes: build(:health_care_application).parsed_form } + ) expect(response.body).to eq(success_response.to_json) end @@ -233,7 +237,8 @@ get(facilities_v0_health_care_applications_path(facilityIds: %w[vha_757 vha_358])) end expect(response).to have_http_status(:ok) - expect(response.parsed_body[0]).to eq({ 'access' => nil, + expect(response.parsed_body[0]).to eq({ + 'access' => nil, 'active_status' => nil, 'address' => { 'mailing' => { @@ -277,7 +282,8 @@ 'type' => 'va_facilities', 'unique_id' => '042', 'visn' => nil, - 'website' => 'https://www.cem.va.gov/cems/lots/BaxterSprings.asp' }) + 'website' => 'https://www.cem.va.gov/cems/lots/BaxterSprings.asp' + }) end context 'with hca_retrieve_facilities_without_repopulating disabled' do From 35a57892ae0040b5ce29fd993a1f55ac63ff1c96 Mon Sep 17 00:00:00 2001 From: Joshua Drumm <34111449+JoshingYou1@users.noreply.github.com> Date: Tue, 7 Jan 2025 17:21:24 -0500 Subject: [PATCH 16/26] Fixed some more linting errors --- .../v0/health_care_applications_spec.rb | 126 ++++++++++-------- 1 file changed, 69 insertions(+), 57 deletions(-) diff --git a/spec/requests/v0/health_care_applications_spec.rb b/spec/requests/v0/health_care_applications_spec.rb index ef7d12f851e..5ae1c49417b 100644 --- a/spec/requests/v0/health_care_applications_spec.rb +++ b/spec/requests/v0/health_care_applications_spec.rb @@ -237,53 +237,55 @@ get(facilities_v0_health_care_applications_path(facilityIds: %w[vha_757 vha_358])) end expect(response).to have_http_status(:ok) - expect(response.parsed_body[0]).to eq({ - 'access' => nil, - 'active_status' => nil, - 'address' => { - 'mailing' => { - 'zip' => '66713', - 'city' => 'Leavenworth', - 'state' => 'KS', - 'address1' => '150 Muncie Rd' + expect(response.parsed_body[0]).to eq( + { + 'access' => nil, + 'active_status' => nil, + 'address' => { + 'mailing' => { + 'zip' => '66713', + 'city' => 'Leavenworth', + 'state' => 'KS', + 'address1' => '150 Muncie Rd' + }, + 'physical' => { + 'zip' => '66713', + 'city' => 'Baxter Springs', + 'state' => 'KS', + 'address1' => 'Baxter Springs City Cemetery' + } }, - 'physical' => { - 'zip' => '66713', - 'city' => 'Baxter Springs', - 'state' => 'KS', - 'address1' => 'Baxter Springs City Cemetery' - } - }, - 'classification' => 'Soldiers Lot', - 'detailed_services' => nil, - 'distance' => nil, - 'facility_type' => 'va_cemetery', - 'facility_type_prefix' => 'nca', - 'feedback' => nil, - 'hours' => { - 'monday' => 'Sunrise - Sundown', - 'tuesday' => 'Sunrise - Sundown', - 'wednesday' => 'Sunrise - Sundown', - 'thursday' => 'Sunrise - Sundown', - 'friday' => 'Sunrise - Sundown', - 'saturday' => 'Sunrise - Sundown', - 'sunday' => 'Sunrise - Sundown' - }, - 'id' => 'nca_042', - 'lat' => 37.0320575, - 'long' => -94.7706605, - 'mobile' => nil, - 'name' => "Baxter Springs City Soldiers' Lot", - 'operating_status' => { 'code' => 'NORMAL' }, - 'operational_hours_special_instructions' => nil, - 'parent' => nil, - 'phone' => { 'fax' => '9137584136', 'main' => '9137584105' }, - 'services' => nil, - 'type' => 'va_facilities', - 'unique_id' => '042', - 'visn' => nil, - 'website' => 'https://www.cem.va.gov/cems/lots/BaxterSprings.asp' - }) + 'classification' => 'Soldiers Lot', + 'detailed_services' => nil, + 'distance' => nil, + 'facility_type' => 'va_cemetery', + 'facility_type_prefix' => 'nca', + 'feedback' => nil, + 'hours' => { + 'monday' => 'Sunrise - Sundown', + 'tuesday' => 'Sunrise - Sundown', + 'wednesday' => 'Sunrise - Sundown', + 'thursday' => 'Sunrise - Sundown', + 'friday' => 'Sunrise - Sundown', + 'saturday' => 'Sunrise - Sundown', + 'sunday' => 'Sunrise - Sundown' + }, + 'id' => 'nca_042', + 'lat' => 37.0320575, + 'long' => -94.7706605, + 'mobile' => nil, + 'name' => "Baxter Springs City Soldiers' Lot", + 'operating_status' => { 'code' => 'NORMAL' }, + 'operational_hours_special_instructions' => nil, + 'parent' => nil, + 'phone' => { 'fax' => '9137584136', 'main' => '9137584105' }, + 'services' => nil, + 'type' => 'va_facilities', + 'unique_id' => '042', + 'visn' => nil, + 'website' => 'https://www.cem.va.gov/cems/lots/BaxterSprings.asp' + } + ) end context 'with hca_retrieve_facilities_without_repopulating disabled' do @@ -315,9 +317,11 @@ describe 'POST create' do subject do - post(v0_health_care_applications_path, + post( + v0_health_care_applications_path, params: params.to_json, - headers: { 'CONTENT_TYPE' => 'application/json', 'HTTP_X_KEY_INFLECTION' => 'camel' }) + headers: { 'CONTENT_TYPE' => 'application/json', 'HTTP_X_KEY_INFLECTION' => 'camel' } + ) end context 'with invalid params' do @@ -355,20 +359,26 @@ def self.expect_async_submit subject body = JSON.parse(response.body) expect(body).to eq( - 'data' => - { 'id' => HealthCareApplication.last.id.to_s, - 'type' => 'health_care_applications', - 'attributes' => - { 'state' => 'pending', 'formSubmissionId' => nil, 'timestamp' => nil } } + 'data' => { + 'id' => HealthCareApplication.last.id.to_s, + 'type' => 'health_care_applications', + 'attributes' => { + 'state' => 'pending', + 'formSubmissionId' => nil, + 'timestamp' => nil + } + } ) end end context 'anonymously' do let(:body) do - { 'formSubmissionId' => 436_426_165, + { + 'formSubmissionId' => 436_426_165, 'timestamp' => '2024-08-20T12:08:06.729-05:00', - 'success' => true } + 'success' => true + } end context 'with an email set' do @@ -414,9 +424,11 @@ def self.expect_async_submit context 'while authenticated', :skip_mvi do let(:current_user) { build(:user, :mhv) } let(:body) do - { 'formSubmissionId' => 436_426_340, + { + 'formSubmissionId' => 436_426_340, 'timestamp' => '2024-08-20T12:26:48.275-05:00', - 'success' => true } + 'success' => true + } end before do From 8fff4f50534fb4c4ecb239f664f6d88c8fff3019 Mon Sep 17 00:00:00 2001 From: Joshua Drumm <34111449+JoshingYou1@users.noreply.github.com> Date: Tue, 7 Jan 2025 17:26:13 -0500 Subject: [PATCH 17/26] Fixed another linting issue --- lib/form1010_ezr/service.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/form1010_ezr/service.rb b/lib/form1010_ezr/service.rb index 64a49084aad..5c14c33ee2e 100644 --- a/lib/form1010_ezr/service.rb +++ b/lib/form1010_ezr/service.rb @@ -47,7 +47,6 @@ def submit_sync(parsed_form) es_submit(parsed_form, HealthCareApplication.get_user_identifier(@user), FORM_ID) end end - # Log the 'formSubmissionId' for successful submissions Rails.logger.info( '1010EZR successfully submitted', From 4683176c461178ae4132d519b0edef9395ec5af2 Mon Sep 17 00:00:00 2001 From: Joshua Drumm <34111449+JoshingYou1@users.noreply.github.com> Date: Tue, 7 Jan 2025 17:29:52 -0500 Subject: [PATCH 18/26] Fixed another linting issue --- lib/form1010_ezr/service.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/form1010_ezr/service.rb b/lib/form1010_ezr/service.rb index 5c14c33ee2e..407ee728195 100644 --- a/lib/form1010_ezr/service.rb +++ b/lib/form1010_ezr/service.rb @@ -53,7 +53,6 @@ def submit_sync(parsed_form) submission_id: res[:formSubmissionId], veteran_initials: veteran_initials(parsed_form) ) - if parsed_form['attachments'].present? StatsD.increment("#{Form1010Ezr::Service::STATSD_KEY_PREFIX}.submission_with_attachment") end From 827217d611b5ec326e64f42cbb469fbc397d17cd Mon Sep 17 00:00:00 2001 From: Joshua Drumm <34111449+JoshingYou1@users.noreply.github.com> Date: Wed, 8 Jan 2025 12:49:37 -0500 Subject: [PATCH 19/26] Fixed some failing tests --- spec/lib/form1010_ezr/service_spec.rb | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/spec/lib/form1010_ezr/service_spec.rb b/spec/lib/form1010_ezr/service_spec.rb index 71b29e13220..2031f8f100e 100644 --- a/spec/lib/form1010_ezr/service_spec.rb +++ b/spec/lib/form1010_ezr/service_spec.rb @@ -295,16 +295,24 @@ def ezr_form_with_attachments allow_logger_to_receive_error end - it 'increments StatsD as well as logs and raises the error' do + it 'increments StatsD, logs the message to sentry, and raises the error' do allow(StatsD).to receive(:increment) expect(StatsD).to receive(:increment).with('api.1010ezr.failed') + expect_any_instance_of(SentryLogging).to receive(:log_message_to_sentry).with( + '1010EZR failure', + :error, + { + first_initial: 'F', + middle_initial: 'M', + last_initial: 'Z' + }, + ezr: :failure + ) + expect { submit_form(form) }.to raise_error( StandardError, 'Uh oh. Some bad error occurred.' ) - expect_logger_errors( - ['10-10EZR form submission failed: Uh oh. Some bad error occurred.'] - ) end end end From 19b426fdfb693d10006f2d9764bfdbdf8e7493ae Mon Sep 17 00:00:00 2001 From: Joshua Drumm <34111449+JoshingYou1@users.noreply.github.com> Date: Wed, 8 Jan 2025 13:46:41 -0500 Subject: [PATCH 20/26] Tried to fix a linting issue --- lib/form1010_ezr/service.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/form1010_ezr/service.rb b/lib/form1010_ezr/service.rb index 407ee728195..e4ed3a4389a 100644 --- a/lib/form1010_ezr/service.rb +++ b/lib/form1010_ezr/service.rb @@ -40,9 +40,7 @@ def submit_async(parsed_form) def submit_sync(parsed_form) res = with_monitoring do if Flipper.enabled?(:va1010_forms_enrollment_system_service_enabled) - VA1010Forms::EnrollmentSystem::Service.new( - HealthCareApplication.get_user_identifier(@user) - ).submit(parsed_form, FORM_ID) + VA1010Forms::EnrollmentSystem::Service.new(HealthCareApplication.get_user_identifier(@user)).submit(parsed_form,FORM_ID) else es_submit(parsed_form, HealthCareApplication.get_user_identifier(@user), FORM_ID) end From 9efcd0ad4ae5ec61c51d23c4392a4d07ba2b0846 Mon Sep 17 00:00:00 2001 From: Joshua Drumm <34111449+JoshingYou1@users.noreply.github.com> Date: Wed, 8 Jan 2025 14:03:57 -0500 Subject: [PATCH 21/26] Tried to fix a linting issue --- lib/form1010_ezr/service.rb | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/form1010_ezr/service.rb b/lib/form1010_ezr/service.rb index e4ed3a4389a..913f55904e3 100644 --- a/lib/form1010_ezr/service.rb +++ b/lib/form1010_ezr/service.rb @@ -40,17 +40,16 @@ def submit_async(parsed_form) def submit_sync(parsed_form) res = with_monitoring do if Flipper.enabled?(:va1010_forms_enrollment_system_service_enabled) - VA1010Forms::EnrollmentSystem::Service.new(HealthCareApplication.get_user_identifier(@user)).submit(parsed_form,FORM_ID) + VA1010Forms::EnrollmentSystem::Service.new( + HealthCareApplication.get_user_identifier(@user) + ).submit(parsed_form, FORM_ID) else es_submit(parsed_form, HealthCareApplication.get_user_identifier(@user), FORM_ID) end end # Log the 'formSubmissionId' for successful submissions - Rails.logger.info( - '1010EZR successfully submitted', - submission_id: res[:formSubmissionId], - veteran_initials: veteran_initials(parsed_form) - ) + log_successful_submission(res[:formSubmissionId], veteran_initials(parsed_form)) + if parsed_form['attachments'].present? StatsD.increment("#{Form1010Ezr::Service::STATSD_KEY_PREFIX}.submission_with_attachment") end @@ -183,5 +182,13 @@ def log_validation_errors(errors, parsed_form) error_class: 'Form1010Ezr ValidationError' ) end + + def log_successful_submission(submission_id, veteran_initials) + Rails.logger.info( + '1010EZR successfully submitted', + submission_id:, + veteran_initials: + ) + end end end From 761d5f2a884661a8d07b3f455572bf68a9af2665 Mon Sep 17 00:00:00 2001 From: Joshua Drumm <34111449+JoshingYou1@users.noreply.github.com> Date: Tue, 14 Jan 2025 17:37:21 -0500 Subject: [PATCH 22/26] test: trigger preview environment From d1599d51fa4ea318e76e6f03af02451b8d53bb3e Mon Sep 17 00:00:00 2001 From: Joshua Drumm <34111449+JoshingYou1@users.noreply.github.com> Date: Wed, 15 Jan 2025 12:26:05 -0500 Subject: [PATCH 23/26] test: trigger preview environment From daf3fe7736430bd501368183ad8c14496d7e6c0b Mon Sep 17 00:00:00 2001 From: Joshua Drumm <34111449+JoshingYou1@users.noreply.github.com> Date: Thu, 16 Jan 2025 12:32:51 -0500 Subject: [PATCH 24/26] Fixed linting issues --- spec/lib/form1010_ezr/service_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/lib/form1010_ezr/service_spec.rb b/spec/lib/form1010_ezr/service_spec.rb index 7bc17f87ed7..8cefde0dd91 100644 --- a/spec/lib/form1010_ezr/service_spec.rb +++ b/spec/lib/form1010_ezr/service_spec.rb @@ -277,13 +277,13 @@ def ezr_form_with_attachments personal_information_log = PersonalInformationLog.find_by(error_class: "Form1010Ezr 'veteranDateOfBirth' schema failure") - expect(personal_information_log.present?).to be(true) - expect(personal_information_log.data).to eq(form['veteranDateOfBirth']) - expect(e).to be_a(Common::Exceptions::SchemaValidationErrors) + expect(personal_information_log.present?).to be(true) + expect(personal_information_log.data).to eq(form['veteranDateOfBirth']) + expect(e).to be_a(Common::Exceptions::SchemaValidationErrors) + end end end end - end context 'any other error' do before do From 37e125df4d868f527afe7f647fbb87107203b317 Mon Sep 17 00:00:00 2001 From: Joshua Drumm <34111449+JoshingYou1@users.noreply.github.com> Date: Thu, 16 Jan 2025 12:55:49 -0500 Subject: [PATCH 25/26] Fixed linting issues --- spec/lib/hca/service_spec.rb | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/spec/lib/hca/service_spec.rb b/spec/lib/hca/service_spec.rb index 53d5b75b178..21b52c37f50 100644 --- a/spec/lib/hca/service_spec.rb +++ b/spec/lib/hca/service_spec.rb @@ -60,7 +60,7 @@ VCR::MATCH_EVERYTHING.merge(erb: true) ) do result = HCA::Service.new.submit_form(get_fixture('hca/short_form')) - expect(result[:success]).to eq(true) + expect(result[:success]).to be(true) expect(Rails.logger).to have_received(:info).with( 'Payload for submitted 1010EZ: Body size of 5.16 KB with 0 attachment(s)' ) @@ -92,10 +92,10 @@ VCR::MATCH_EVERYTHING.merge(erb: true) ) do form = get_fixture('hca/demographic_no') - expect(HealthCareApplication.new(form: form.to_json).valid?).to eq(true) + expect(HealthCareApplication.new(form: form.to_json).valid?).to be(true) result = HCA::Service.new.submit_form(form) - expect(result[:success]).to eq(true) + expect(result[:success]).to be(true) end end end @@ -107,10 +107,10 @@ VCR::MATCH_EVERYTHING.merge(erb: true) ) do form = get_fixture('hca/medicare_claim_num') - expect(HealthCareApplication.new(form: form.to_json).valid?).to eq(true) + expect(HealthCareApplication.new(form: form.to_json).valid?).to be(true) result = HCA::Service.new.submit_form(form) - expect(result[:success]).to eq(true) + expect(result[:success]).to be(true) end end end @@ -122,7 +122,7 @@ VCR::MATCH_EVERYTHING.merge(erb: true) ) do result = HCA::Service.new.submit_form(get_fixture('hca/sigi')) - expect(result[:success]).to eq(true) + expect(result[:success]).to be(true) end end end @@ -134,9 +134,9 @@ VCR::MATCH_EVERYTHING.merge(erb: true) ) do form = get_fixture('hca/tera') - expect(HealthCareApplication.new(form: form.to_json).valid?).to eq(true) + expect(HealthCareApplication.new(form: form.to_json).valid?).to be(true) result = HCA::Service.new.submit_form(form) - expect(result[:success]).to eq(true) + expect(result[:success]).to be(true) end end end @@ -148,7 +148,7 @@ VCR::MATCH_EVERYTHING.merge(erb: true) ) do result = HCA::Service.new.submit_form(get_fixture('hca/short_form')) - expect(result[:success]).to eq(true) + expect(result[:success]).to be(true) end end @@ -173,7 +173,7 @@ VCR::MATCH_EVERYTHING.merge(erb: true) ) do result = HCA::Service.new.submit_form(create(:hca_app_with_attachment).parsed_form) - expect(result[:success]).to eq(true) + expect(result[:success]).to be(true) expect(Rails.logger).to have_received(:info).with( 'Payload for submitted 1010EZ: Body size of 16 KB with 2 attachment(s)' ) @@ -211,7 +211,7 @@ VCR::MATCH_EVERYTHING.merge(erb: true) ) do result = HCA::Service.new.submit_form(health_care_application.parsed_form) - expect(result[:success]).to eq(true) + expect(result[:success]).to be(true) end end end From 154ded00b5b5f677fd686cd0725f830b83a66d8c Mon Sep 17 00:00:00 2001 From: Joshua Drumm <34111449+JoshingYou1@users.noreply.github.com> Date: Wed, 22 Jan 2025 15:55:20 -0500 Subject: [PATCH 26/26] test: trigger preview environment