Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add validator messages filter #202

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lib/au_core_test_kit/constants.rb
Original file line number Diff line number Diff line change
@@ -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
14 changes: 3 additions & 11 deletions lib/au_core_test_kit/generator/templates/suite.rb.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>
Expand All @@ -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
Expand All @@ -41,15 +33,15 @@ 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')
disableDefaultResourceFetcher false
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|
Expand Down
4 changes: 4 additions & 0 deletions lib/au_core_test_kit/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
30 changes: 30 additions & 0 deletions spec/au_core/validation_helpers_test_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Loading