Skip to content

Commit

Permalink
support receiving read and search scopes separately
Browse files Browse the repository at this point in the history
  • Loading branch information
Jammjammjamm committed Sep 6, 2024
1 parent fdce6a1 commit e1bd1e4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
36 changes: 29 additions & 7 deletions lib/onc_certification_g10_test_kit/patient_scope_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,35 @@ def scope_version
end

run do
expected_scope = if scope_version == :v2
'patient/Patient.rs'
else
'patient/Patient.read'
end
assert received_scopes&.include?(expected_scope),
"#{expected_scope} scope was requested, but not received. Received: `#{received_scopes}`"
expected_scopes =
if scope_version == :v2
[
Regexp.new(scope_regex_string('patient/Patient.rs').gsub('.rs', '.r?s')),
Regexp.new(scope_regex_string('patient/Patient.rs').gsub('.rs', '.rs?'))
]
else
[Regexp.new(scope_regex_string('patient/Patient.read'))]
end

received_scopes = self.received_scopes.split

unmatched_scopes =
expected_scopes.reject do |expected_scope|
received_scopes.any? { |received_scope| received_scope.match? expected_scope }
end

assert unmatched_scopes.blank?,
"No scope matching the following was received: `#{unmatched_scopes_string(unmatched_scopes)}`"
end

def scope_regex_string(scope)
"\\A#{Regexp.quote(scope)}\\z"
end

def unmatched_scopes_string(unmatched_scopes)
unmatched_scopes
.map { |scope| "`#{scope.source}`" }
.join(', ')
end
end
end
13 changes: 11 additions & 2 deletions spec/onc_certification_g10_test_kit/patient_scope_test_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def run(runnable, inputs = {})
result = run(test, received_scopes:)

expect(result.result).to eq('fail')
expect(result.result_message).to match(/but not received/)
expect(result.result_message).to match(/No scope matching/)
end
end

Expand Down Expand Up @@ -62,7 +62,16 @@ def run(runnable, inputs = {})
result = run(test, received_scopes:)

expect(result.result).to eq('fail')
expect(result.result_message).to match(/but not received/)
expect(result.result_message).to match(/No scope matching/)
end

it 'fails if both read and search scopes are not received' do
received_scopes.gsub!('.rs', '.r')

result = run(test, received_scopes:)

expect(result.result).to eq('fail')
expect(result.result_message).to match(/No scope matching/)
end
end
end

0 comments on commit e1bd1e4

Please sign in to comment.