2023-02-22 00:55:31 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-18 17:36:18 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe ReportFilter do
|
|
|
|
describe 'with empty params' do
|
|
|
|
it 'defaults to unresolved reports list' do
|
2023-06-06 11:58:33 +00:00
|
|
|
filter = described_class.new({})
|
2017-04-18 17:36:18 +00:00
|
|
|
|
|
|
|
expect(filter.results).to eq Report.unresolved
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'with invalid params' do
|
|
|
|
it 'raises with key error' do
|
2023-06-06 11:58:33 +00:00
|
|
|
filter = described_class.new(wrong: true)
|
2017-04-18 17:36:18 +00:00
|
|
|
|
|
|
|
expect { filter.results }.to raise_error(/wrong/)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'with valid params' do
|
|
|
|
it 'combines filters on Report' do
|
2023-06-06 11:58:33 +00:00
|
|
|
filter = described_class.new(account_id: '123', resolved: true, target_account_id: '456')
|
2017-04-18 17:36:18 +00:00
|
|
|
|
2023-08-22 07:31:40 +00:00
|
|
|
allow(Report).to receive_messages(where: Report.none, resolved: Report.none)
|
2017-04-18 17:36:18 +00:00
|
|
|
filter.results
|
|
|
|
expect(Report).to have_received(:where).with(account_id: '123')
|
2017-05-22 19:50:58 +00:00
|
|
|
expect(Report).to have_received(:where).with(target_account_id: '456')
|
2017-04-18 17:36:18 +00:00
|
|
|
expect(Report).to have_received(:resolved)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|