Skip to content

Commit

Permalink
Fix reference search by ID
Browse files Browse the repository at this point in the history
Ref: #225
  • Loading branch information
projkov committed Dec 2, 2024
1 parent 814d5e9 commit b28cd76
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/au_core_test_kit/search_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require_relative 'search_test_properties'
require_relative 'read_test'
require_relative 'assert_helpers'
require_relative 'search_test_helpers'

module AUCoreTestKit
module SearchTest
Expand Down Expand Up @@ -160,6 +161,11 @@ def perform_search(params, patient_id)
search_params = is_count_available_for_resource_type?(resource_type, params) == false ? params : params.merge({ _count: 10 })
fhir_search(resource_type, params: search_params)

if SearchTestHelpers.is_search_by_reference?(search_params)
search_params = SearchTestHelpers.replace_full_reference_search_param_to_id(search_params)
fhir_search(resource_type, params: search_params)
end

perform_search_with_status(params, patient_id) if response[:status] == 400 && possible_status_search?

check_search_response
Expand Down Expand Up @@ -193,6 +199,7 @@ def perform_search(params, patient_id)
test_include_param(resources_returned, params, patient_id, include_param)
end
end

perform_reference_with_type_search(params, resources_returned.count) if test_reference_variants?
perform_search_with_system(params, patient_id) if token_search_params.present?

Expand Down
25 changes: 25 additions & 0 deletions lib/au_core_test_kit/search_test_helpers.rb
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
40 changes: 40 additions & 0 deletions spec/au_core/search_test_helpers_spec.rb
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

0 comments on commit b28cd76

Please sign in to comment.