Skip to content

Commit

Permalink
FI-3259: Include presets in gems (#572)
Browse files Browse the repository at this point in the history
* load presets from test kits

* remove test kit presets

* update template to include presets

* handle reference server in qa for presets

* add spec for altering presets to point to qa
  • Loading branch information
Jammjammjamm authored Dec 13, 2024
1 parent 4034350 commit 1565a94
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 704 deletions.
542 changes: 0 additions & 542 deletions config/presets/g10_certification_preset.json.erb

This file was deleted.

81 changes: 0 additions & 81 deletions config/presets/smart_preset.json.erb

This file was deleted.

36 changes: 0 additions & 36 deletions config/presets/us_core_preset.json.erb

This file was deleted.

36 changes: 0 additions & 36 deletions config/presets/us_core_v311_reference_server_preset.json.erb

This file was deleted.

3 changes: 3 additions & 0 deletions lib/inferno/apps/cli/templates/%library_name%.gemspec.tt
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'rspec', '~> 3.10'
spec.add_development_dependency 'webmock', '~> 3.11'
spec.required_ruby_version = Gem::Requirement.new('>= 3.1.2')
spec.metadata['inferno_test_kit'] = 'true'
# spec.metadata['homepage_uri'] = spec.homepage
# spec.metadata['source_code_uri'] = 'TODO'
spec.files = [
Dir['lib/**/*.rb'],
Dir['lib/**/*.json'],
Dir['config/presets/*.json'],
Dir['config/presets/*.json.erb'],
'LICENSE'
].flatten

Expand Down
19 changes: 18 additions & 1 deletion lib/inferno/config/boot/presets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,26 @@
prepare do
target_container.start :suites

presets_repo = Inferno::Repositories::Presets.new

test_kit_gems =
Bundler
.definition
.specs
.select { |spec| spec.metadata.fetch('inferno_test_kit', 'false').casecmp? 'true' }

files_to_load = Dir.glob(['config/presets/*.json', 'config/presets/*.json.erb'])
files_to_load +=
test_kit_gems.flat_map do |gem|
[
Dir.glob([File.join(gem.full_gem_path, 'config', 'presets', '*.json')]),
Dir.glob([File.join(gem.full_gem_path, 'config', 'presets', '*.json.erb')])
].flatten
end

files_to_load.compact!
files_to_load.uniq!
files_to_load.map! { |path| File.realpath(path) }
presets_repo = Inferno::Repositories::Presets.new

files_to_load.each do |path|
presets_repo.insert_from_file(path)
Expand Down
18 changes: 12 additions & 6 deletions lib/inferno/repositories/presets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,20 @@ module Repositories
# Repository that deals with persistence for the `Preset` entity.
class Presets < InMemoryRepository
def insert_from_file(path)
case path
when /\.json$/
preset_hash = JSON.parse(File.read(path))
when /\.erb$/
templated = ERB.new(File.read(path)).result
preset_hash = JSON.parse(templated)
raw_contents =
case path
when /\.json$/
File.read(path)
when /\.erb$/
ERB.new(File.read(path)).result
end

if Application['base_url'].start_with? 'https://inferno-qa.healthit.gov'
raw_contents.gsub!('https://inferno.healthit.gov', 'https://inferno-qa.healthit.gov')
end

preset_hash = JSON.parse(raw_contents)

preset_hash.deep_symbolize_keys!
preset_hash[:id] ||= SecureRandom.uuid
preset = Entities::Preset.new(preset_hash)
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/simple_preset.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"type": "text",
"title": "Title",
"description": "Description",
"value": "https://hardcoded.example.org"
"value": "https://inferno.healthit.gov"
}
]
}
13 changes: 12 additions & 1 deletion spec/inferno/repositories/presets_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
type: 'text',
title: 'Title',
description: 'Description',
value: 'https://hardcoded.example.org'
value: 'https://inferno.healthit.gov'
]
}
)
Expand Down Expand Up @@ -67,5 +67,16 @@
expect(inserted.inputs.first[:value]).to eq('http://default.example.com')
end
end

context 'when hosted on QA' do
before do
stub_const 'Inferno::Application', { 'base_url' => 'https://inferno-qa.healthit.gov' }
end

it 'replaces inferno.healthit.gov with inferno-qa.healthit.gov' do
inserted = presets.insert_from_file(simple_json)
expect(inserted.inputs.first[:value]).to eq('https://inferno-qa.healthit.gov')
end
end
end
end

0 comments on commit 1565a94

Please sign in to comment.