Skip to content

Commit

Permalink
Fi 1961 Fix input bug (#353)
Browse files Browse the repository at this point in the history
* Fix oauth parse error and cleanup

* Remove old unused group and add oauth example

* Format issue fix.

* Fix unit tests since I changed a demo suite.
  • Loading branch information
arscan authored Apr 19, 2023
1 parent 4f9b7f2 commit cf1b4d2
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ const InputOAuthCredentials: FC<InputOAuthCredentialsProps> = ({
fullWidth
onChange={(event) => {
const value = event.target.value;
inputsMap.set(requirement.name, value);
oAuthCredentials[field.name as keyof OAuthCredentials] = value;
inputsMap.set(requirement.name, JSON.stringify(oAuthCredentials));
setInputsMap(new Map(inputsMap));
Expand Down
4 changes: 3 additions & 1 deletion client/src/components/InputsModal/InputsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ const InputsModal: FC<InputsModalProps> = ({
let oAuthMissingRequiredInput = false;
if (input.type === 'oauth_credentials') {
try {
const oAuthJSON = JSON.parse(inputsMap.get(input.name) as string) as OAuthCredentials;
const oAuthJSON = JSON.parse(
(inputsMap.get(input.name) as string) || '{}'
) as OAuthCredentials;
const accessTokenIsEmpty = oAuthJSON.access_token === '';
const refreshIsEmpty =
oAuthJSON.refresh_token !== '' &&
Expand Down
89 changes: 0 additions & 89 deletions dev_suites/dev_demo_ig_stu1/demo_suite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,95 +52,6 @@ class DemoSuite < Inferno::TestSuite
exclude_message { |message| message.type == 'info' }
end

group :oauth_validator_demo do
title 'OAuth credentials proof of concept'

group :output_example do
title 'Launch that would provide a bearer token & relevant content from code exchange response'
output :creds

test do
title 'hi'
id :something

run do
creds = {
access_token: 'blah',
refresh_token: 'blah, blah',
expires_in: 400,
client_id: 'hi',
client_secret: 'bye',
token_url: 'https://example.com'
}.to_json

output creds:
end
end
end

group :input_example do
title 'Some simple test that may use smart credentials'
input :url
input :patient_id
input :creds, type: 'oauth_credentials' # this is json, but types probably should have their own classes...

fhir_client :creds_client do
url :url
oauth_credentials :creds
end

test do
id :oauth_creds_use
title 'Patient read with OAuth creds'
input :patient_id, title: 'Patient ID'

run do
fhir_read(:patient, patient_id, client: :creds_client)

assert_response_status(200)
assert_resource_type(:patient)
end
end

test do
title 'hi'
id :something
output :creds

run do
creds = {
access_token: 'refreshed blah token',
refresh_token: 'blah, blah',
expires_in: 400,
client_id: 'hi',
client_secret: 'bye',
token_url: 'https://example.com'
}.to_json

output creds:
end
end
end

# test 'OAuth credentials outputted' do
# id :first_test
# output :creds

# run do

# creds = {
# access_token: 'blah',
# refresh_token: 'blah, blah',
# refresh_date: '5/5/555'
# }.to_json

# output creds: 'hi'

# end

# end
end

config options: {
wait_test_url: "#{Inferno::Application['base_url']}/custom/demo/resume"
}
Expand Down
10 changes: 10 additions & 0 deletions dev_suites/dev_demo_ig_stu1/groups/demo_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,16 @@ class DemoGroup < Inferno::TestGroup
run { info "Received the following 'checkbox' variable: '#{checkbox}'" }
end

test 'OAuth Credentials group input' do
input :credentials,
title: 'OAuth Credentials Group Input Example',
type: 'oauth_credentials',
description: 'OAuth Credentials description',
optional: true

run { info "Received the following 'credentials' variable: '#{credentials}'" }
end

test 'locked input' do
input :patient_name, title: 'Patient Name', description: 'Example of locked, empty input field',
locked: true, optional: true
Expand Down
6 changes: 6 additions & 0 deletions spec/inferno/utils/preset_template_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
_options: { list_options: [{ label: 'Label 1', value: 'value1' },
{ label: 'Label 2', value: 'value2' }] },
value: ['value2'] },
{ name: 'credentials',
_description: 'OAuth Credentials description',
_optional: true,
_title: 'OAuth Credentials Group Input Example',
_type: 'oauth_credentials',
value: nil },
{ name: 'patient_name', _type: 'text', _title: 'Patient Name',
_description: 'Example of locked, empty input field', _locked: true, _optional: true, value: nil },
{ name: 'url_locked', _type: 'text', _title: 'URL', _description: 'Example of locked, filled input field',
Expand Down

0 comments on commit cf1b4d2

Please sign in to comment.