diff --git a/lib/au_core_test_kit/constants.rb b/lib/au_core_test_kit/constants.rb new file mode 100644 index 00000000..869d72b8 --- /dev/null +++ b/lib/au_core_test_kit/constants.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +module Constants + def self.validation_message_filters + [ + "The value provided ('xml') was not found in the value set 'MimeType'", + "The value provided ('json') was not found in the value set 'MimeType'", + "The value provided ('ttl') was not found in the value set 'MimeType'" + ].freeze + end +end diff --git a/lib/au_core_test_kit/generator/templates/suite.rb.erb b/lib/au_core_test_kit/generator/templates/suite.rb.erb index 888f6ad4..45e630ad 100644 --- a/lib/au_core_test_kit/generator/templates/suite.rb.erb +++ b/lib/au_core_test_kit/generator/templates/suite.rb.erb @@ -6,6 +6,7 @@ require_relative '../../custom_groups/smart_app_launch_group' require_relative '../../custom_groups/missing_data_group' require_relative '../../au_core_options' require_relative '../../helpers' +require_relative '../../constants' <% group_file_list.each do |file_name| %>require_relative '<%= file_name %>' <% end %> @@ -22,15 +23,6 @@ module AUCoreTestKit ) version VERSION - VALIDATION_MESSAGE_FILTERS = [ - %r{Sub-extension url 'introspect' is not defined by the Extension http://fhir-registry\.smarthealthit\.org/StructureDefinition/oauth-uris}, - %r{Sub-extension url 'revoke' is not defined by the Extension http://fhir-registry\.smarthealthit\.org/StructureDefinition/oauth-uris}, - /Observation\.effective\.ofType\(Period\): .*vs-1:/, # Invalid invariant in FHIR v4.0.1 - /Observation\.effective\.ofType\(Period\): .*us-core-1:/, # Invalid invariant in AU Core v3.1.1 - /Provenance.agent\[\d*\]: Rule provenance-1/, #Invalid invariant in AU Core v5.0.1 - /\A\S+: \S+: URL value '.*' does not resolve/, - ].freeze - VERSION_SPECIFIC_MESSAGE_FILTERS = <%=version_specific_message_filters%>.freeze def self.metadata @@ -41,7 +33,7 @@ module AUCoreTestKit fhir_resource_validator do igs '<%= ig_identifier %>' - message_filters = VALIDATION_MESSAGE_FILTERS + VERSION_SPECIFIC_MESSAGE_FILTERS + message_filters = Constants.validation_message_filters + VERSION_SPECIFIC_MESSAGE_FILTERS cli_context do txServer ENV.fetch('TX_SERVER_URL', 'https://tx.dev.hl7.org.au/fhir') @@ -49,7 +41,7 @@ module AUCoreTestKit end exclude_message do |message| - message_filters.any? { |filter| filter.match? message.message } + Helpers.is_message_exist_in_list(message_filters, message.message) end perform_additional_validation do |resource, profile_url| diff --git a/lib/au_core_test_kit/helpers.rb b/lib/au_core_test_kit/helpers.rb index 1d008ee4..521367de 100644 --- a/lib/au_core_test_kit/helpers.rb +++ b/lib/au_core_test_kit/helpers.rb @@ -220,4 +220,8 @@ def self.check_for_dar(resource) def self.check_for_dar_extension(resource) return resource.source_contents&.include? DAR_EXTENSION_URL end + + def self.is_message_exist_in_list(message_list, message) + message_list.any? { |list_message| message.include? list_message } + end end diff --git a/spec/au_core/validation_helpers_test_spec.rb b/spec/au_core/validation_helpers_test_spec.rb new file mode 100644 index 00000000..c07731c8 --- /dev/null +++ b/spec/au_core/validation_helpers_test_spec.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +require 'rspec' +require_relative '../../lib/au_core_test_kit/helpers' + +RSpec.describe 'Validator helpers' do + message_list = [ + "The value provided ('xml') was not found in the value set 'MimeType'" + ] + message_xml = "CapabilityStatement/61a65c7c-4f56-4f45-9342-38699af77e51: CapabilityStatement.format[1]: The value provided ('xml') was not found in the value set 'MimeType' (http://hl7.org/fhir/ValueSet/mimetypes|4.0.1), and a code is required from this value set (error message = The System URI could not be determined for the code 'xml' in the ValueSet 'http://hl7.org/fhir/ValueSet/mimetypes|4.0.1'; None of the provided codes ['#xml'] are in the value set 'http://hl7.org/fhir/ValueSet/mimetypes|4.0.1')" + message_json = "CapabilityStatement/61a65c7c-4f56-4f45-9342-38699af77e51: CapabilityStatement.format[3]: The value provided ('json') was not found in the value set 'MimeType' (http://hl7.org/fhir/ValueSet/mimetypes|4.0.1), and a code is required from this value set (error message = The System URI could not be determined for the code 'json' in the ValueSet 'http://hl7.org/fhir/ValueSet/mimetypes|4.0.1'; None of the provided codes ['#json'] are in the value set 'http://hl7.org/fhir/ValueSet/mimetypes|4.0.1')" + + it 'It should return true if string exist in target message' do + expect( + Helpers.is_message_exist_in_list( + message_list, + message_xml + ) + ).to eq(true) + end + + it 'It should return false if string not exist in target message' do + expect( + Helpers.is_message_exist_in_list( + message_list, + message_json + ) + ).to eq(false) + end +end