-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ref: #225
- Loading branch information
Showing
3 changed files
with
72 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module SearchTestHelpers | ||
|
||
def self.is_search_by_reference?(search_param) | ||
search_param = search_param.transform_keys(&:to_s) | ||
search_param.keys.map {|key| is_search_param_is_reference?(search_param[key])}.include?(true) | ||
end | ||
|
||
def self.replace_full_reference_search_param_to_id(search_param) | ||
search_param = search_param.transform_keys(&:to_s) | ||
search_param.keys.each do |key| | ||
if is_search_param_is_reference?(search_param[key]) | ||
search_param[key] = search_param[key].split('/').last | ||
end | ||
end | ||
search_param | ||
end | ||
|
||
private | ||
|
||
def self.is_search_param_is_reference?(single_search_param) | ||
single_search_param = single_search_param.to_s | ||
single_search_param.include?('/') && single_search_param.split('/').length == 2 | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rspec' | ||
require_relative '../../lib/au_core_test_kit/search_test_helpers' | ||
|
||
RSpec.describe 'is_search_by_reference? method' do | ||
it 'SHOULD return false if there is no references in the search params hash' do | ||
expect( | ||
SearchTestHelpers.is_search_by_reference?( | ||
{"patient"=>"baratz-toni", :_count =>10} | ||
) | ||
).to eq(false) | ||
end | ||
|
||
it 'SHOULD return true if there is references in the search params hash' do | ||
expect( | ||
SearchTestHelpers.is_search_by_reference?( | ||
{"patient"=>"Patient/baratz-toni", :_count =>10} | ||
) | ||
).to eq(true) | ||
end | ||
end | ||
|
||
RSpec.describe 'replace_full_reference_search_param_to_id method' do | ||
it 'SHOULD return correctly formatted hash without resourceType' do | ||
expect( | ||
SearchTestHelpers.replace_full_reference_search_param_to_id( | ||
{"patient"=>"Patient/baratz-toni", :_count =>10} | ||
) | ||
).to eq({"patient"=>"baratz-toni", "_count" =>10}) | ||
end | ||
|
||
it 'SHOULD return true if there is references in the search params hash' do | ||
expect( | ||
SearchTestHelpers.replace_full_reference_search_param_to_id( | ||
{"patient"=>"baratz-toni", :_count =>10} | ||
) | ||
).to eq({"patient"=>"baratz-toni", "_count" =>10}) | ||
end | ||
end |