Skip to content

Commit

Permalink
Merge pull request #209 from hl7au/71-add-message-for-skip
Browse files Browse the repository at this point in the history
Add conditional/basic skip with message
  • Loading branch information
projkov authored Sep 16, 2024
2 parents 461044e + 67bde7a commit 2e70143
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 12 deletions.
31 changes: 31 additions & 0 deletions lib/au_core_test_kit/assert_helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

module AUCoreTestKit
module AssertHelpers
extend Forwardable

def_delegators 'properties',
:conditional_skip_with_msg,
:skip_with_msg

def act_if_with_message(act_func, condition, message)
info message if condition

act_func.call(condition, message)
end

def act_with_message(act_func, message)
info message

act_func.call(message)
end

def conditional_skip_with_msg(condition, message)
act_if_with_message(method(:skip_if), condition, message)
end

def skip_with_msg(message)
act_with_message(method(:skip), message)
end
end
end
6 changes: 4 additions & 2 deletions lib/au_core_test_kit/must_support_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

require_relative 'fhir_resource_navigation'
require_relative 'helpers'
require_relative 'assert_helpers'

module AUCoreTestKit
module MustSupportTest
extend Forwardable
include FHIRResourceNavigation
include AssertHelpers

def_delegators 'self.class', :metadata

Expand All @@ -15,7 +17,7 @@ def all_scratch_resources
end

def perform_must_support_test(resources)
skip_if resources.blank?, "No #{resource_type} resources were found"
conditional_skip_with_msg resources.blank?, "No #{resource_type} resources were found"

missing_elements(resources)
missing_slices(resources)
Expand All @@ -24,7 +26,7 @@ def perform_must_support_test(resources)
handle_must_support_choices if metadata.must_supports[:choices].present?

pass if (missing_elements + missing_slices + missing_extensions).empty?
skip "Could not find #{missing_must_support_strings.join(', ')} element(s) in the #{resources.length} " \
skip_with_msg "Could not find #{missing_must_support_strings.join(', ')} element(s) in the #{resources.length} " \
"provided #{resource_type} resource(s). To prevent this issue, please add the missing must support "\
"elements to at least one #{resource_type} resource on the server."
end
Expand Down
6 changes: 4 additions & 2 deletions lib/au_core_test_kit/reference_resolution_test.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
# frozen_string_literal: true

require_relative 'fhir_resource_navigation'
require_relative 'assert_helpers'

module AUCoreTestKit
module ReferenceResolutionTest
extend Forwardable
include FHIRResourceNavigation
include AssertHelpers

def_delegators 'self.class', :metadata

def perform_reference_resolution_test(resources)
skip_if resources.blank?, no_resources_skip_message
conditional_skip_with_msg resources.blank?, no_resources_skip_message

pass if unresolved_references(resources).empty?

skip "Could not resolve and validate any Must Support references for #{unresolved_references_strings.join(', ')}"
skip_with_msg "Could not resolve and validate any Must Support references for #{unresolved_references_strings.join(', ')}"
end

def unresolved_references_strings
Expand Down
8 changes: 5 additions & 3 deletions lib/au_core_test_kit/search_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
require_relative 'fhir_resource_navigation'
require_relative 'search_test_properties'
require_relative 'read_test'
require_relative 'assert_helpers'

module AUCoreTestKit
module SearchTest
extend Forwardable
include DateSearchValidation
include FHIRResourceNavigation
include ReadTest
include AssertHelpers

def_delegators 'self.class', :metadata, :provenance_metadata, :properties
def_delegators 'properties',
Expand Down Expand Up @@ -62,7 +64,7 @@ def any_valid_search_params?(search_params)

def run_provenance_revinclude_search_test
# TODO: skip if not supported?
skip_if !any_valid_search_params?(all_provenance_revinclude_search_params), unable_to_resolve_params_message
conditional_skip_with_msg !any_valid_search_params?(all_provenance_revinclude_search_params), unable_to_resolve_params_message

provenance_resources =
all_provenance_revinclude_search_params.flat_map do |_patient_id, params_list|
Expand Down Expand Up @@ -900,7 +902,7 @@ def check_resource_against_params(resource, params)
private

def run_search_test_common(search_method)
skip_if !any_valid_search_params?(all_search_params), unable_to_resolve_params_message
conditional_skip_with_msg !any_valid_search_params?(all_search_params), unable_to_resolve_params_message

ability_to_search_is_checked = false
search_is_available = true
Expand All @@ -924,7 +926,7 @@ def run_search_test_common(search_method)
end
end

skip_if resources_returned.empty?, no_resources_skip_message
conditional_skip_with_msg resources_returned.empty?, no_resources_skip_message

return unless search_is_available == false

Expand Down
8 changes: 5 additions & 3 deletions lib/au_core_test_kit/special_identifier_search_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

require_relative 'search_test_properties'
require_relative 'search_test'
require_relative 'assert_helpers'

module AUCoreTestKit
module SpecialIdentifierSearchTest
extend Forwardable
include SearchTest
include AssertHelpers

def_delegators 'self.class', :metadata, :provenance_metadata, :properties
def_delegators 'properties',
Expand Down Expand Up @@ -78,15 +80,15 @@ def search_param_value(_name, resource, include_system: false)
end

def run_special_identifier_search_test
skip_if scratch_resources[:all].empty?, no_resources_skip_message
skip_if !any_valid_search_params?(all_search_params), unable_to_resolve_params_message
conditional_skip_with_msg scratch_resources[:all].empty?, no_resources_skip_message
conditional_skip_with_msg !any_valid_search_params?(all_search_params), unable_to_resolve_params_message

resources_returned =
all_search_params.flat_map do |patient_id, params_list|
params_list.flat_map { |params| perform_search_with_system(params, patient_id) }
end

skip_if resources_returned.empty?, no_resources_skip_message
conditional_skip_with_msg resources_returned.empty?, no_resources_skip_message
end
end
end
8 changes: 6 additions & 2 deletions lib/au_core_test_kit/validation_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# frozen_string_literal: true

require_relative 'assert_helpers'

module AUCoreTestKit
module ValidationTest
include AssertHelpers

DAR_CODE_SYSTEM_URL = 'http://terminology.hl7.org/CodeSystem/data-absent-reason'
DAR_EXTENSION_URL = 'http://hl7.org/fhir/StructureDefinition/data-absent-reason'

Expand All @@ -10,8 +14,8 @@ def perform_validation_test(resources,
profile_version,
skip_if_empty: true)

skip_if skip_if_empty && resources.blank?,
"No #{resource_type} resources conforming to the #{profile_url} profile were returned"
conditional_skip_with_msg skip_if_empty && resources.blank?,
"No #{resource_type} resources conforming to the #{profile_url} profile were returned"

omit_if resources.blank?,
"No #{resource_type} resources provided so the #{profile_url} profile does not apply"
Expand Down

0 comments on commit 2e70143

Please sign in to comment.