diff --git a/app/models/in_progress_form.rb b/app/models/in_progress_form.rb index fbb446f12dd..2fe30ac1788 100644 --- a/app/models/in_progress_form.rb +++ b/app/models/in_progress_form.rb @@ -28,7 +28,9 @@ def cast(value) } # the double quotes in return_url are part of the value scope :return_url, ->(url) { where(%( #{RETURN_URL_SQL} = ? ), "\"#{url}\"") } - + scope :for_form, ->(form_id) { where(form_id:) } + scope :not_submitted, -> { where.not("(metadata -> 'submission' ->> 'status')::boolean") } + scope :unsubmitted_fsr, -> { for_form('5655').not_submitted } attribute :user_uuid, CleanUUID.new serialize :form_data, JsonMarshal::Marshaller has_kms_key diff --git a/rakelib/in_progress_forms.rake b/rakelib/in_progress_forms.rake index 1c67b42f451..14c2ea11258 100644 --- a/rakelib/in_progress_forms.rake +++ b/rakelib/in_progress_forms.rake @@ -44,6 +44,17 @@ namespace :form_progress do puts data end + desc 'Get metadata for in-progress FSR forms that haven\'t been submitted' + task :pending_fsr, %i[start_date end_date] => [:environment] do |_, args| + start_date = args[:start_date]&.to_date || 31.days.ago.utc + end_date = args[:end_date]&.to_date || 1.day.ago + forms = InProgressForm.unsubmitted_fsr.where(updated_at: [start_date.beginning_of_day..end_date.end_of_day]) + puts '------------------------------------------------------------' + puts "* #{forms.length} unsubmitted FSR form#{forms.length == 1 ? '' : 's'} from #{start_date} to #{end_date} *" + puts '------------------------------------------------------------' + puts forms.pluck :metadata + end + def forms_with_args(args) form_id = args[:form_id] || '21-526EZ' start_date = args[:start_date]&.to_date || 31.days.ago.utc diff --git a/spec/models/in_progress_form_spec.rb b/spec/models/in_progress_form_spec.rb index a002923aa70..60620702508 100644 --- a/spec/models/in_progress_form_spec.rb +++ b/spec/models/in_progress_form_spec.rb @@ -87,12 +87,16 @@ errorMessage: 'bar' } }) end let!(:second_record) { create(:in_progress_form, metadata: { submission: { hasAttemptedSubmit: false } }) } + let!(:third_record) do + create(:in_progress_form, form_id: '5655', metadata: { submission: { hasAttemptedSubmit: true, status: false } }) + end it 'includes records within scope' do expect(described_class.has_attempted_submit).to include(first_record) expect(described_class.has_errors).to include(first_record) expect(described_class.has_error_message).to include(first_record) expect(described_class.has_no_errors).to include(second_record) + expect(described_class.unsubmitted_fsr).to include(third_record) end end