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) def retrieve_case_logs(current_time)
recent_export = LogsExport.order("started_at").last recent_export = LogsExport.order("started_at").last
if recent_export if recent_export
params = { from: recent_export.started_at, to: current_time, status: CaseLog.statuses[:completed] } params = { from: recent_export.started_at, to: current_time }
CaseLog.where("updated_at >= :from and updated_at <= :to and status = :status", params) CaseLog.where("updated_at >= :from and updated_at <= :to", params)
else else
params = { to: current_time, status: CaseLog.statuses[:completed] } params = { to: current_time }
CaseLog.where("updated_at <= :to and status = :status", params) CaseLog.where("updated_at <= :to", params)
end end
end end

11
spec/services/exports/case_log_export_service_spec.rb

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

Loading…
Cancel
Save