-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CRIMAPP-89 add search filters and attributes for return reasons report
- Loading branch information
Showing
9 changed files
with
140 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
db/migrate/20231117142406_add_return_reason_virtual_attribute_to_crime_applications.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class AddReturnReasonVirtualAttributeToCrimeApplications < ActiveRecord::Migration[7.0] | ||
def change | ||
add_column( | ||
:crime_applications, | ||
:return_reason, | ||
:virtual, | ||
as: "(return_details->>'reason')", | ||
type: :string, | ||
stored: true | ||
) | ||
|
||
add_index :crime_applications, :return_reason | ||
end | ||
end |
5 changes: 5 additions & 0 deletions
5
...grate/20231117142441_add_index_for_office_code_virtual_attribute_on_crime_applications.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddIndexForOfficeCodeVirtualAttributeOnCrimeApplications < ActiveRecord::Migration[7.0] | ||
def change | ||
add_index :crime_applications, :office_code | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
spec/api/datastore/v1/searching/filter_by_reviewed_at_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe 'searches filter by reviewed_at' do | ||
subject(:api_request) do | ||
post '/api/v1/searches', params: { search: search, pagination: {} } | ||
end | ||
|
||
let(:search) { {} } | ||
let(:records) { JSON.parse(response.body).fetch('records') } | ||
|
||
before do | ||
CrimeApplication.insert_all( | ||
[ | ||
{ reviewed_at: 3.days.ago, submitted_application: { reference: 101 } }, | ||
{ reviewed_at: 2.days.ago, submitted_application: { reference: 102 } }, | ||
{ reviewed_at: 1.day.ago, submitted_application: { reference: 103 } } | ||
] | ||
) | ||
|
||
api_request | ||
end | ||
|
||
it 'defaults to showing all applications' do | ||
expect(records.pluck('reference')).to contain_exactly(101, 102, 103) | ||
end | ||
|
||
context 'when reviewed_after is provided' do | ||
let(:search) { { reviewed_after: 2.days.ago } } | ||
|
||
it 'only shows records reviewed after' do | ||
expect(records.pluck('reference')).to contain_exactly(102, 103) | ||
end | ||
end | ||
|
||
context 'when reviewed_before is provided' do | ||
let(:search) { { reviewed_before: 2.days.ago } } | ||
|
||
it 'only shows records reviewed before' do | ||
expect(records.pluck('reference')).to eq([101]) | ||
end | ||
end | ||
end |