diff --git a/Gemfile.lock b/Gemfile.lock index 50a0ccff90c..56b9b292215 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -528,7 +528,7 @@ GEM google-protobuf (4.28.3) bigdecimal rake (>= 13) - googleauth (1.11.1) + googleauth (1.11.2) faraday (>= 1.0, < 3.a) google-cloud-env (~> 2.1) jwt (>= 1.4, < 3.0) @@ -748,7 +748,7 @@ GEM hashery (~> 2.0) ruby-rc4 ttfunk - pg (1.5.8) + pg (1.5.9) pg_query (5.1.0) google-protobuf (>= 3.22.3) pg_search (2.3.7) diff --git a/app/models/appeal_submission.rb b/app/models/appeal_submission.rb index 9ffffcabab1..ad2c91539fb 100644 --- a/app/models/appeal_submission.rb +++ b/app/models/appeal_submission.rb @@ -14,6 +14,7 @@ class AppealSubmission < ApplicationRecord has_encrypted :upload_metadata, key: :kms_key, **lockbox_options has_many :appeal_submission_uploads, dependent: :destroy + has_many :secondary_appeal_forms, dependent: :destroy scope :failure_not_sent, -> { where(failure_notification_sent_at: nil).order(id: :asc) } diff --git a/config/features.yml b/config/features.yml index 1e50190ba2a..5ab6fa34edb 100644 --- a/config/features.yml +++ b/config/features.yml @@ -1618,6 +1618,10 @@ features: actor_type: user description: HLR show form content updates enable_in_development: true + sc_new_form: + actor_type: user + description: Supplemental Claim new form updates + enable_in_development: true pension_ipf_callbacks_endpoint: actor_type: user description: Pension IPF VANotify notification callbacks endpoint diff --git a/lib/lighthouse/benefits_documents/form526/update_documents_status_service.rb b/lib/lighthouse/benefits_documents/form526/update_documents_status_service.rb index d04aae030c3..a490fa60b19 100644 --- a/lib/lighthouse/benefits_documents/form526/update_documents_status_service.rb +++ b/lib/lighthouse/benefits_documents/form526/update_documents_status_service.rb @@ -39,6 +39,7 @@ def self.call(*) # @param lighthouse526_document_uploads [Lighthouse526DocumentUpload] a collection of # Lighthouse526DocumentUpload records polled for status updates on Lighthouse's '/uploads/status' endpoint + # @param lighthouse_status_response [Hash] the parsed JSON response body from the endpoint def initialize(lighthouse526_document_uploads, lighthouse_status_response) @lighthouse526_document_uploads = lighthouse526_document_uploads @lighthouse_status_response = lighthouse_status_response @@ -66,34 +67,29 @@ def update_document_status(status) document_upload = @lighthouse526_document_uploads.find_by!(lighthouse_document_request_id: status['requestId']) statsd_document_base_key(STATSD_DOCUMENT_TYPE_KEY_MAP[document_upload.document_type]) - status_updater(status, document_upload) - @status_updater.update_status + status_updater = BenefitsDocuments::Form526::UploadStatusUpdater.new(status, document_upload) + status_updater.update_status if document_upload.completed? # ex. 'api.form526.lighthouse_document_upload_processing_status.bdd_instructions.complete' StatsD.increment("#{@statsd_document_base_key}.#{STATSD_DOCUMENT_COMPLETE_KEY}") elsif document_upload.failed? - log_failure(document_upload) - elsif @status_updater.processing_timeout? + log_failure(status_updater, document_upload) + elsif status_updater.processing_timeout? # Triggered when a document is still pending more than 24 hours after processing began # ex. 'api.form526.lighthouse_document_upload_processing_status.bdd_instructions.processing_timeout' StatsD.increment("#{@statsd_document_base_key}.#{STATSD_PROCESSING_TIMEOUT_KEY}") end end - def status_updater(status, document_upload) - # UploadStatusUpdater encapsulates all parsing of a status response from Lighthouse - @status_updater ||= BenefitsDocuments::Form526::UploadStatusUpdater.new(status, document_upload) - end - def statsd_document_base_key(statsd_document_type_key) @statsd_document_base_key ||= "#{STATSD_BASE_KEY}.#{statsd_document_type_key}" end - def log_failure(document_upload) + def log_failure(status_updater, document_upload) # Because Lighthouse's processing steps are subject to change, these metrics must be dynamic. # Currently, this should return either CLAIMS_EVIDENCE or BENEFITS_GATEWAY_SERVICE - failure_step = @status_updater.get_failure_step + failure_step = status_updater.get_failure_step # ex. 'api.form526.lighthouse_document_upload_processing_status.bdd_instructions.failed.claims_evidence' StatsD.increment("#{@statsd_document_base_key}.#{STATSD_DOCUMENT_FAILED_KEY}.#{failure_step.downcase}") diff --git a/spec/lib/lighthouse/benefits_documents/form526/update_documents_status_service_spec.rb b/spec/lib/lighthouse/benefits_documents/form526/update_documents_status_service_spec.rb index 9393768e590..25aae3a52dc 100644 --- a/spec/lib/lighthouse/benefits_documents/form526/update_documents_status_service_spec.rb +++ b/spec/lib/lighthouse/benefits_documents/form526/update_documents_status_service_spec.rb @@ -103,6 +103,49 @@ end end end + + context 'when updating multiple records' do + let!(:first_pending_polling_document) { create(:lighthouse526_document_upload, aasm_state: 'pending') } + let!(:second_pending_polling_document) { create(:lighthouse526_document_upload, aasm_state: 'pending') } + + let(:status_response) do + { + 'data' => { + 'statuses' => [ + { + 'requestId' => first_pending_polling_document.lighthouse_document_request_id, + 'time' => { + 'startTime' => start_time_in_unix_milliseconds, + 'endTime' => end_time_in_unix_milliseconds + }, + 'status' => 'SUCCESS' + }, { + 'requestId' => second_pending_polling_document.lighthouse_document_request_id, + 'time' => { + 'startTime' => start_time_in_unix_milliseconds, + 'endTime' => end_time_in_unix_milliseconds + }, + 'status' => 'FAILED', + 'error' => { + 'detail' => 'Something went wrong', + 'step' => 'BENEFITS_GATEWAY_SERVICE' + } + } + ], + 'requestIdsNotFound' => [ + 0 + ] + } + } + end + + it 'updates each record status properly' do + described_class.call(Lighthouse526DocumentUpload.all, status_response) + + expect(first_pending_polling_document.reload.aasm_state).to eq('completed') + expect(second_pending_polling_document.reload.aasm_state).to eq('failed') + end + end end describe 'document type in statsd metrics' do diff --git a/spec/models/accredited_organization_spec.rb b/spec/models/accredited_organization_spec.rb index c908011ccd8..449497b2438 100644 --- a/spec/models/accredited_organization_spec.rb +++ b/spec/models/accredited_organization_spec.rb @@ -4,7 +4,7 @@ RSpec.describe AccreditedOrganization, type: :model do describe 'validations' do - subject { build(:accredited_organization) } + subject { build(:accredited_organization, poa_code: 'A12') } it { is_expected.to have_many(:accredited_individuals).through(:accreditations) }