Module: USCoreTestKit::GranularScopeSearchTest
- Includes:
- GranularScope, ResourceSearchParamChecker
- Included in:
- USCoreV610::ConditionPatientAbatementDateGranularScopeSearchTest, USCoreV610::ConditionPatientAssertedDateGranularScopeSearchTest, USCoreV610::ConditionPatientCategoryClinicalStatusGranularScopeSearchTest, USCoreV610::ConditionPatientCategoryEncounterGranularScopeSearchTest, USCoreV610::ConditionPatientCategoryGranularScopeSearchTest, USCoreV610::ConditionPatientClinicalStatusGranularScopeSearchTest, USCoreV610::ConditionPatientCodeGranularScopeSearchTest, USCoreV610::ConditionPatientGranularScopeSearchTest, USCoreV610::ConditionPatientOnsetDateGranularScopeSearchTest, USCoreV610::ConditionPatientRecordedDateGranularScopeSearchTest, USCoreV610::ObservationPatientCategoryDateGranularScopeSearchTest, USCoreV610::ObservationPatientCategoryGranularScopeSearchTest, USCoreV610::ObservationPatientCategoryStatusGranularScopeSearchTest, USCoreV610::ObservationPatientCodeDateGranularScopeSearchTest, USCoreV610::ObservationPatientCodeGranularScopeSearchTest, USCoreV700_BALLOT::ConditionPatientAbatementDateGranularScopeSearchTest, USCoreV700_BALLOT::ConditionPatientAssertedDateGranularScopeSearchTest, USCoreV700_BALLOT::ConditionPatientCategoryClinicalStatusGranularScopeSearchTest, USCoreV700_BALLOT::ConditionPatientCategoryEncounterGranularScopeSearchTest, USCoreV700_BALLOT::ConditionPatientCategoryGranularScopeSearchTest, USCoreV700_BALLOT::ConditionPatientClinicalStatusGranularScopeSearchTest, USCoreV700_BALLOT::ConditionPatientCodeGranularScopeSearchTest, USCoreV700_BALLOT::ConditionPatientGranularScopeSearchTest, USCoreV700_BALLOT::ConditionPatientOnsetDateGranularScopeSearchTest, USCoreV700_BALLOT::ConditionPatientRecordedDateGranularScopeSearchTest, USCoreV700_BALLOT::DiagnosticReportPatientCategoryDateGranularScopeSearchTest, USCoreV700_BALLOT::DiagnosticReportPatientCategoryGranularScopeSearchTest, USCoreV700_BALLOT::DiagnosticReportPatientCodeDateGranularScopeSearchTest, USCoreV700_BALLOT::DiagnosticReportPatientCodeGranularScopeSearchTest, USCoreV700_BALLOT::DiagnosticReportPatientGranularScopeSearchTest, USCoreV700_BALLOT::DiagnosticReportPatientStatusGranularScopeSearchTest, USCoreV700_BALLOT::DocumentReferenceIdGranularScopeSearchTest, USCoreV700_BALLOT::DocumentReferencePatientCategoryDateGranularScopeSearchTest, USCoreV700_BALLOT::DocumentReferencePatientCategoryGranularScopeSearchTest, USCoreV700_BALLOT::DocumentReferencePatientGranularScopeSearchTest, USCoreV700_BALLOT::DocumentReferencePatientStatusGranularScopeSearchTest, USCoreV700_BALLOT::DocumentReferencePatientTypeGranularScopeSearchTest, USCoreV700_BALLOT::DocumentReferencePatientTypePeriodGranularScopeSearchTest, USCoreV700_BALLOT::ObservationPatientCategoryDateGranularScopeSearchTest, USCoreV700_BALLOT::ObservationPatientCategoryGranularScopeSearchTest, USCoreV700_BALLOT::ObservationPatientCategoryStatusGranularScopeSearchTest, USCoreV700_BALLOT::ObservationPatientCodeDateGranularScopeSearchTest, USCoreV700_BALLOT::ObservationPatientCodeGranularScopeSearchTest, USCoreV700_BALLOT::ServiceRequestIdGranularScopeSearchTest, USCoreV700_BALLOT::ServiceRequestPatientCategoryAuthoredGranularScopeSearchTest, USCoreV700_BALLOT::ServiceRequestPatientCategoryGranularScopeSearchTest, USCoreV700_BALLOT::ServiceRequestPatientCodeAuthoredGranularScopeSearchTest, USCoreV700_BALLOT::ServiceRequestPatientCodeGranularScopeSearchTest, USCoreV700_BALLOT::ServiceRequestPatientGranularScopeSearchTest, USCoreV700_BALLOT::ServiceRequestPatientStatusGranularScopeSearchTest
- Defined in:
- lib/us_core_test_kit/granular_scope_search_test.rb
Constant Summary
Constants included from FHIRResourceNavigation
FHIRResourceNavigation::DAR_EXTENSION_URL, FHIRResourceNavigation::PRIMITIVE_DATA_TYPES
Class Method Summary collapse
Instance Method Summary collapse
- #expected_resource_ids(resources) ⇒ Object
- #load_previous_requests ⇒ Object
- #mismatched_resource_ids(resources) ⇒ Object
- #previous_resources(params) ⇒ Object
- #run_scope_search_test ⇒ Object
Methods included from GranularScope
#granular_scope_search_params, #granular_scopes, #previous_request_resources, #resource_specific_granular_scope_search_params
Methods included from ResourceSearchParamChecker
#element_has_valid_value?, #resource_matches_param?, #search_param_paths
Methods included from FHIRResourceNavigation
#find_a_value_at, #find_slice_via_discriminator, #get_next_value, #get_primitive_type_value, #resolve_path, #verify_slice_by_values
Class Method Details
.included(klass) ⇒ Object
9 10 11 12 |
# File 'lib/us_core_test_kit/granular_scope_search_test.rb', line 9 def self.included(klass) klass.input(:received_scopes) klass.attr_accessor :previous_requests end |
Instance Method Details
#expected_resource_ids(resources) ⇒ Object
79 80 81 82 83 84 85 86 87 |
# File 'lib/us_core_test_kit/granular_scope_search_test.rb', line 79 def expected_resource_ids(resources) resources .select do |resource| granular_scope_search_params.any? do |param| resource_matches_param?(resource, param[:name], param[:value]) end end .map(&:id) end |
#load_previous_requests ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/us_core_test_kit/granular_scope_search_test.rb', line 56 def load_previous_requests search_params_as_hash = search_param_names.each_with_object({}) do |name, hash| hash[name] = nil end @previous_requests ||= load_tagged_requests(search_params_tag(search_params_as_hash)) .sort_by { |request| request.index } end |
#mismatched_resource_ids(resources) ⇒ Object
89 90 91 92 93 94 95 96 97 |
# File 'lib/us_core_test_kit/granular_scope_search_test.rb', line 89 def mismatched_resource_ids(resources) resources .reject do |resource| granular_scope_search_params.any? do |param| resource_matches_param?(resource, param[:name], param[:value]) end end .map(&:id) end |
#previous_resources(params) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/us_core_test_kit/granular_scope_search_test.rb', line 65 def previous_resources(params) previous_requests(params) .flat_map do |request| resource = request.resource if resource.is_a?(FHIR::Bundle) resource.entry&.map(&:resource) else resource end end .compact .select { |resource| resource.resourceType == resource_type } end |
#run_scope_search_test ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/us_core_test_kit/granular_scope_search_test.rb', line 14 def run_scope_search_test assert granular_scopes.present?, "No granular scopes were received for #{resource_type} resources" load_previous_requests skip_if previous_requests.blank?, "No #{resource_type} searches with search params #{search_param_names.join(' & ')} found" previous_request_resources.each do |previous_request, all_previous_resources| search_method = previous_request.verb.to_sym params = search_method == :get ? previous_request.query_parameters : Hash[URI.decode_www_form(previous_request.request_body)] fhir_search(resource_type, params:, search_method:) found_resources = if request.status != 200 [] else fetch_all_bundled_resources end mismatched_ids = mismatched_resource_ids(found_resources) assert mismatched_ids.empty?, 'Resources with the following ids were received even though they do not match the ' \ "granted granular scopes: #{mismatched_ids.join(', ')}" found_ids = found_resources.map(&:id) previous_ids = expected_resource_ids(all_previous_resources) missing_ids = previous_ids - found_ids assert missing_ids.empty?, 'Resources with the following ids were received when using resource-level scopes, ' \ "but not when using granular scopes: #{missing_ids.join(', ')}" unexpected_ids = found_ids - previous_ids assert unexpected_ids.empty?, 'Resources with the following ids were received when using granular scopes, ' \ "but not when using resource-level scopes: #{unexpected_ids.join(', ')}" end end |