-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #217 from hl7au/199-separate-include-tests
199 separate include tests
- Loading branch information
Showing
5 changed files
with
170 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
lib/au_core_test_kit/generator/include_search_test_generator.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative 'naming' | ||
require_relative 'special_cases' | ||
require_relative 'search_test_generator' | ||
|
||
module AUCoreTestKit | ||
class Generator | ||
class IncludeSearchTestGenerator < SearchTestGenerator | ||
class << self | ||
def generate(ig_metadata, base_output_dir) | ||
ig_metadata.groups | ||
.reject { |group| SpecialCases.exclude_group? group } | ||
.select { |group| group.include_params.present? } | ||
.each do |group| | ||
group.include_params.each { |include_param| new(group, group.searches.first, base_output_dir, include_param).generate } | ||
end | ||
end | ||
end | ||
|
||
attr_accessor :group_metadata, :search_metadata, :base_output_dir, :include_param | ||
|
||
def initialize(group_metadata, search_metadata, base_output_dir, include_param) | ||
self.group_metadata = group_metadata | ||
self.search_metadata = search_metadata | ||
self.base_output_dir = base_output_dir | ||
self.include_param = include_param | ||
end | ||
|
||
def template | ||
@template ||= File.read(File.join(__dir__, 'templates', 'include.rb.erb')) | ||
end | ||
|
||
def search_identifier | ||
includes.first['target_resource'] | ||
end | ||
|
||
def class_name | ||
"#{Naming.upper_camel_case_for_profile(group_metadata)}#{search_title}IncludeTest" | ||
end | ||
|
||
def conformance_expectation | ||
'SHOULD' | ||
end | ||
|
||
def optional? | ||
true | ||
end | ||
|
||
def needs_patient_id? | ||
true | ||
end | ||
|
||
def search_properties | ||
{}.tap do |properties| | ||
properties[:resource_type] = "'#{resource_type}'" | ||
properties[:saves_delayed_references] = 'true' if saves_delayed_references? | ||
properties[:search_param_names] = search_param_names_array | ||
properties[:includes] = includes if group_metadata.include_params.present? | ||
end | ||
end | ||
|
||
def target_resources_string | ||
includes.map { |include| include['target_resource'] }.join(', ') | ||
end | ||
|
||
def include_params_string | ||
includes.map { |include| include['parameter'] }.join(', ') | ||
end | ||
|
||
def search_param_names_string | ||
search_param_names.join(', ') | ||
end | ||
|
||
def title | ||
"Server returns #{target_resources_string} resources from #{resource_type} search by #{search_param_names_string} and #{include_params_string}" | ||
end | ||
|
||
def description | ||
<<~DESCRIPTION.gsub(/\n{3,}/, "\n\n") | ||
This test will perform a search by #{search_param_names_string} and #{include_params_string} | ||
Test will pass if a #{target_resources_string} resources are found in the response. | ||
DESCRIPTION | ||
end | ||
|
||
def search_method | ||
'run_include_test' | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
require_relative '../../../search_test' | ||
require_relative '../../../generator/group_metadata' | ||
require_relative '../../../helpers' | ||
|
||
module AUCoreTestKit | ||
module <%= module_name %> | ||
class <%= class_name %> < Inferno::Test | ||
include AUCoreTestKit::SearchTest | ||
title '<%= title %>' | ||
description %( | ||
<%= description %> | ||
) | ||
|
||
id :<%= test_id %><% if optional? %> | ||
optional | ||
<% end %><% if needs_patient_id? %> | ||
input :patient_ids, | ||
title: 'Patient IDs', | ||
description: 'Comma separated list of patient IDs that in sum contain all MUST SUPPORT elements', | ||
default: '<%= Helpers.default_patient_ids_string %>' | ||
<% end %><% if resource_type == 'Device' %> | ||
input :implantable_device_codes, | ||
title: 'Implantable Device Type Code', | ||
description: 'Enter the code for an Implantable Device type, or multiple codes separated by commas. '\ | ||
'If blank, Inferno will validate all Device resources against the Implantable Device profile', | ||
optional: true | ||
<% end %> | ||
def self.properties | ||
@properties ||= SearchTestProperties.new( | ||
<%= search_test_properties_string %> | ||
) | ||
end | ||
|
||
def self.metadata | ||
@metadata ||= Generator::GroupMetadata.new(YAML.load_file(File.join(__dir__, 'metadata.yml'), aliases: true)) | ||
end | ||
|
||
def scratch_resources | ||
scratch[:<%= profile_identifier %>_resources] ||= {} | ||
end | ||
|
||
run do | ||
<%= search_method %> | ||
end | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters