Commit b53c5bfc authored by Tan Le's avatar Tan Le

Fix date range filters on audit event export

The current export has two problems:

- Ending time (i.e. in `created_before`) is set to the start of the day
  (00:00:00), instead of the end of the day (23:59:59). This results in
  a lot of missing events.

- If date range params are not provided, it returns the first 100,000
  events ordered by `created_at`, instead of constraining to only a
  month worth of data like in the search UI.

This change addresses the above issue and, as a result, ensures the
exported content matches with the one presented in the search UI.
parent 958fdc20
# frozen_string_literal: true
class Admin::AuditLogReportsController < Admin::ApplicationController
include AuditEvents::DateRange
before_action :validate_audit_log_reports_available!
feature_category :audit_events
......
......@@ -43,10 +43,17 @@ RSpec.describe Admin::AuditLogReportsController do
end
it 'invokes CSV export service with correct arguments' do
expected_params = {
entity_type: 'Project',
entity_id: '789',
created_before: Date.parse('2020-09-01').end_of_day,
created_after: '2020-08-01',
author_id: '67'
}
subject
expect(AuditEvents::ExportCsvService).to have_received(:new)
.with(ActionController::Parameters.new(params).permit!)
expect(AuditEvents::ExportCsvService).to have_received(:new).with(expected_params.with_indifferent_access)
end
it 'returns success status with correct headers', :aggregate_failures do
......@@ -74,6 +81,31 @@ RSpec.describe Admin::AuditLogReportsController do
["20", "sǝʇʎq ƃuᴉpoɔǝp", ",./;'[]\-= old project", "Project", \\_(ツ)_/¯"]
])
end
context 'when date range params are not provided' do
let(:params) do
{
entity_type: 'Project',
entity_id: '789',
author_id: '67'
}
end
it 'passes the default date range filter to the CSV export service' do
current_time = Time.zone.local(2020, 9, 12, 1, 4, 44)
expected_date_range_params = {
created_before: current_time.end_of_day,
created_after: Date.parse('2020-09-01')
}
travel_to(current_time) do
subject
expect(AuditEvents::ExportCsvService).to have_received(:new)
.with(hash_including(expected_date_range_params))
end
end
end
end
context 'when feature flag is disabled' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment