Skip to content

Commit

Permalink
Additional review changes, revert merging logic
Browse files Browse the repository at this point in the history
  • Loading branch information
dehall committed Dec 19, 2023
1 parent 4ce1db8 commit dedac17
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 38 deletions.
37 changes: 5 additions & 32 deletions lib/inferno/dsl/fhir_resource_validation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def igs(*validator_igs)
def cli_context(definition = nil, &)
if @cli_context
if definition
merge_into_cli_context(definition)
@cli_context.definition.merge!(definition.deep_symbolize_keys)
elsif block_given?
@cli_context.instance_eval(&)
end
Expand All @@ -98,21 +98,6 @@ def cli_context(definition = nil, &)
@cli_context
end

# @private
def merge_into_cli_context(new_def)
@cli_context.definition.merge!(new_def) do |_key, old_val, new_val|
case old_val
when Array
# take the union of the 2
old_val | new_val
when Hash
old_val.merge(new_val)
else
new_val
end
end
end

# @private
def additional_validations
@additional_validations ||= []
Expand Down Expand Up @@ -254,7 +239,7 @@ def wrap_resource_for_hl7_wrapper(resource, profile_url)
filesToValidate: [
{
fileName: "#{resource.resourceType}/#{resource.id}.json",
fileContent: resource.to_json,
fileContent: resource.source_contents,
fileType: 'json'
}
],
Expand Down Expand Up @@ -320,7 +305,7 @@ class CliContext

# @private
def initialize(definition, &)
@definition = CLICONTEXT_DEFAULTS.merge(definition)
@definition = CLICONTEXT_DEFAULTS.merge(definition.deep_symbolize_keys)
instance_eval(&) if block_given?
end

Expand All @@ -329,21 +314,9 @@ def method_missing(method_name, *args)
# Interpret any other method as setting a field on cliContext.
# Follow the same format as `Validator.url` here:
# only set the value if one is provided.
# Array or Hash values will be merged if a value is already present.
# args will be an empty array if no value is provided.
unless args.empty?
new_val = args[0]
old_val = definition[method_name]
definition[method_name] = case old_val
when Array
# take the union of the 2
old_val | new_val
when Hash
old_val.merge(new_val)
else
new_val
end
end
definition[method_name] = args[0] unless args.empty?

definition[method_name]
end

Expand Down
23 changes: 17 additions & 6 deletions spec/inferno/dsl/fhir_resource_validation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
outcomes: [{
fileInfo: {
fileName: 'Patient/id.json',
fileContent: resource.to_json,
fileContent: resource.source_contents,
fileType: 'json'
},
issues: []
Expand Down Expand Up @@ -111,7 +111,7 @@
filesToValidate: [
{
fileName: 'Patient/0000.json',
fileContent: resource2.to_json,
fileContent: resource2.source_contents,
fileType: 'json'
}
],
Expand Down Expand Up @@ -187,17 +187,28 @@
})
end

v3 = Inferno::DSL::FHIRResourceValidation::Validator.new do
url 'http://example.com'
cli_context({
'igs' => ['hl7.fhir.us.core#1.0.1'],
'extensions' => []
})
end

expect(v1.cli_context.definition.fetch(:txServer, :missing)).to eq(nil)
expect(v1.cli_context.definition.fetch(:displayWarnings, :missing)).to eq(:missing)
expect(v1.cli_context.txServer).to eq(nil)

expect(v2.cli_context.definition.fetch(:txServer, :missing)).to eq(:missing)
expect(v2.cli_context.definition[:displayWarnings]).to eq(true)
expect(v2.cli_context.displayWarnings).to eq(true)

expect(v3.cli_context.igs).to eq(['hl7.fhir.us.core#1.0.1'])
expect(v3.cli_context.extensions).to eq([])
end

it 'uses the right cli_context when submitting the validation request' do
v3 = Inferno::DSL::FHIRResourceValidation::Validator.new do
v4 = Inferno::DSL::FHIRResourceValidation::Validator.new do
url 'http://example.com'
igs 'hl7.fhir.us.core#1.0.1'
cli_context do
Expand All @@ -213,15 +224,15 @@
sv: '4.0.1',
doNative: true,
extensions: ['any'],
igs: ['hl7.fhir.us.core#1.0.1', 'hl7.fhir.us.core#3.1.1'],
igs: ['hl7.fhir.us.core#3.1.1'],
txServer: nil,
displayWarnings: true,
profiles: [profile_url]
},
filesToValidate: [
{
fileName: 'Patient/.json',
fileContent: resource.to_json,
fileContent: resource.source_contents,
fileType: 'json'
}
],
Expand All @@ -232,7 +243,7 @@
.with(body: expected_request_body)
.to_return(status: 200, body: '{}')

expect(v3.validate(resource, profile_url)).to eq('{}')
expect(v4.validate(resource, profile_url)).to eq('{}')
# if the request body doesn't match the stub,
# validate will throw an exception
end
Expand Down

0 comments on commit dedac17

Please sign in to comment.