diff --git a/lib/onc_certification_g10_test_kit/patient_scope_test.rb b/lib/onc_certification_g10_test_kit/patient_scope_test.rb index 287a9374..e1a1e706 100644 --- a/lib/onc_certification_g10_test_kit/patient_scope_test.rb +++ b/lib/onc_certification_g10_test_kit/patient_scope_test.rb @@ -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 diff --git a/spec/onc_certification_g10_test_kit/patient_scope_test_spec.rb b/spec/onc_certification_g10_test_kit/patient_scope_test_spec.rb index c3b31d75..8232544a 100644 --- a/spec/onc_certification_g10_test_kit/patient_scope_test_spec.rb +++ b/spec/onc_certification_g10_test_kit/patient_scope_test_spec.rb @@ -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 @@ -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