diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml new file mode 100644 index 0000000..04f8d6c --- /dev/null +++ b/.github/workflows/unit-tests.yml @@ -0,0 +1,24 @@ +name: Unit Tests + +on: + push: + branches: + - master + pull_request: + +jobs: + test: + runs-on: ubuntu-24.04 + + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: '3.0' + bundler-cache: true + + - name: Run unit tests + run: bundle exec rake test_unit diff --git a/lib/resource_generator.rb b/lib/resource_generator.rb index 0fa2eb6..9e702e6 100644 --- a/lib/resource_generator.rb +++ b/lib/resource_generator.rb @@ -42,7 +42,7 @@ def self.set_fields!(resource, namespace, embedded=0) # definition in the DSTU2 models. So here, we're just skipping Quantity choice, # and selecting some other (probably primitive) type for the multi-choice FHIR property. ignore_multiple_types = ['Meta'] - ignore_multiple_types += 'Quantity' if namespace == 'FHIR::DSTU2' + ignore_multiple_types += ['Quantity'] if namespace == 'FHIR::DSTU2' selected_multiples = multiples.map { |k| "#{k}#{resource.class::MULTIPLE_TYPES[k].reject { |t| ignore_multiple_types.include?(t) }.sample.titleize.split.join}" } unselected_multiples = all_multiples - selected_multiples end @@ -121,6 +121,8 @@ def self.set_fields!(resource, namespace, embedded=0) c.system = 'https://www.usps.com/' c.code = ['CA','TX','NY','MA','DC'].sample end + elsif type == 'CodeableConcept' && meta['binding'] && meta['binding']['strength'] == 'required' && !meta['valid_codes'] && meta['min'] == 0 + gen = nil # Cannot generate valid code for external required binding (e.g. LOINC/SNOMED); field is optional so safe to skip elsif type == 'Coding' && meta['valid_codes'] && meta['binding'] gen.system = meta['valid_codes'].keys.sample gen.code = meta['valid_codes'][gen.system].sample diff --git a/lib/tests/base_test.rb b/lib/tests/base_test.rb index 7d2ab30..2954a5c 100644 --- a/lib/tests/base_test.rb +++ b/lib/tests/base_test.rb @@ -50,9 +50,9 @@ def initialize(client, client2=nil) end def version_namespace - if @client.fhir_version.to_s.upcase == 'DSTU2' + if @client&.fhir_version.to_s.upcase == 'DSTU2' "FHIR::DSTU2".constantize - elsif @client.fhir_version.to_s.upcase == 'STU3' + elsif @client&.fhir_version.to_s.upcase == 'STU3' "FHIR::STU3".constantize else "FHIR".constantize diff --git a/lib/tests/testscripts/testscript_engine.rb b/lib/tests/testscripts/testscript_engine.rb index c49d5c6..85a11af 100644 --- a/lib/tests/testscripts/testscript_engine.rb +++ b/lib/tests/testscripts/testscript_engine.rb @@ -8,7 +8,7 @@ def initialize(client=nil, client2=nil) @client = client @client2 = client2 @scripts = [] - load_testscripts if client.fhir_version != :dstu2 # Run tests scripts on STU3+ only. + load_testscripts if client&.fhir_version != :dstu2 # Run tests scripts on STU3+ only. end def tests diff --git a/test/unit/metadata_test.rb b/test/unit/metadata_test.rb index d01af79..c58db8d 100644 --- a/test/unit/metadata_test.rb +++ b/test/unit/metadata_test.rb @@ -36,7 +36,7 @@ def test_testscript_find testscript_engine = Crucible::Tests::TestScriptEngine.new(nil) - keyed_test = testscript_engine.find_test('TS-testscript-example') + keyed_test = testscript_engine.find_test(tests.keys.first) assert !keyed_test.nil?, "Failed to find testscript by key" end