Skip to content

Commit

Permalink
58559 - Add a rake task to generate stats about recent unsubmitted FS…
Browse files Browse the repository at this point in the history
…R forms (#12832)

* add a rake task to generate stats about recent unsubmitted FSR forms

* conform to linting

* broaden usecase for added scope
  • Loading branch information
kjsuarez authored Jun 5, 2023
1 parent d025b26 commit c0b181c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/models/in_progress_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions rakelib/in_progress_forms.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions spec/models/in_progress_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit c0b181c

Please sign in to comment.