Browse Source

remove completed status from exports

pull/581/head
Kat 3 years ago
parent
commit
1b1c234e37
  1. 8
      app/services/exports/case_log_export_service.rb
  2. 11
      spec/services/exports/case_log_export_service_spec.rb

8
app/services/exports/case_log_export_service.rb

@ -54,11 +54,11 @@ module Exports
def retrieve_case_logs(current_time)
recent_export = LogsExport.order("started_at").last
if recent_export
params = { from: recent_export.started_at, to: current_time, status: CaseLog.statuses[:completed] }
CaseLog.where("updated_at >= :from and updated_at <= :to and status = :status", params)
params = { from: recent_export.started_at, to: current_time }
CaseLog.where("updated_at >= :from and updated_at <= :to", params)
else
params = { to: current_time, status: CaseLog.statuses[:completed] }
CaseLog.where("updated_at <= :to and status = :status", params)
params = { to: current_time }
CaseLog.where("updated_at <= :to", params)
end
end

11
spec/services/exports/case_log_export_service_spec.rb

@ -46,7 +46,8 @@ RSpec.describe Exports::CaseLogExportService do
end
context "and case logs are available for export" do
let!(:time_now) { Time.now }
let!(:time_now) { Time.zone.now }
before do
Timecop.freeze(time_now)
case_log
@ -81,15 +82,15 @@ RSpec.describe Exports::CaseLogExportService do
start_time = Time.zone.local(2022, 4, 13, 2, 2, 2)
export = LogsExport.new(started_at: start_time, daily_run_number: 1)
export.save!
params = { from: start_time, to: time_now, status: CaseLog.statuses[:completed] }
expect(CaseLog).to receive(:where).with("updated_at >= :from and updated_at <= :to and status = :status", params).and_return([])
params = { from: start_time, to: time_now }
expect(CaseLog).to receive(:where).with("updated_at >= :from and updated_at <= :to", params).and_return([])
export_service.export_case_logs
end
context "when this is the first export" do
it "gets the logs for the timeframe up until the current time" do
params = { to: time_now, status: CaseLog.statuses[:completed] }
expect(CaseLog).to receive(:where).with("updated_at <= :to and status = :status", params).and_return([])
params = { to: time_now }
expect(CaseLog).to receive(:where).with("updated_at <= :to", params).and_return([])
export_service.export_case_logs
end
end

Loading…
Cancel
Save