From 874382d5e47defbb2803c581abda0c923d72fa92 Mon Sep 17 00:00:00 2001 From: Tom Strassner Date: Fri, 6 Dec 2024 11:39:13 -0500 Subject: [PATCH] Move allow_cors to a module instead of monkey patch --- .../dtr_full_ehr_suite.rb | 4 +++- .../dtr_payer_server_suite.rb | 4 +++- .../dtr_smart_app_suite.rb | 5 +++-- lib/davinci_dtr_test_kit/endpoints/cors.rb | 20 +++++++++++++++++ .../ext/inferno_core/runnable.rb | 22 ------------------- 5 files changed, 29 insertions(+), 26 deletions(-) create mode 100644 lib/davinci_dtr_test_kit/endpoints/cors.rb delete mode 100644 lib/davinci_dtr_test_kit/ext/inferno_core/runnable.rb diff --git a/lib/davinci_dtr_test_kit/dtr_full_ehr_suite.rb b/lib/davinci_dtr_test_kit/dtr_full_ehr_suite.rb index b1daac0..69ee8c7 100644 --- a/lib/davinci_dtr_test_kit/dtr_full_ehr_suite.rb +++ b/lib/davinci_dtr_test_kit/dtr_full_ehr_suite.rb @@ -1,7 +1,7 @@ -require_relative 'ext/inferno_core/runnable' require_relative 'client_groups/dinner_static/dtr_full_ehr_questionnaire_workflow_group' require_relative 'client_groups/dinner_adaptive/dtr_full_ehr_adaptive_dinner_questionnaire_workflow_group' require_relative 'auth_groups/oauth2_authentication_group' +require_relative 'endpoints/cors' require_relative 'endpoints/mock_authorization/simple_token_endpoint' require_relative 'endpoints/mock_payer/full_ehr_questionnaire_package_endpoint' require_relative 'endpoints/mock_payer/full_ehr_next_question_endpoint' @@ -9,6 +9,8 @@ module DaVinciDTRTestKit class DTRFullEHRSuite < Inferno::TestSuite + extend CORS + id :dtr_full_ehr title 'Da Vinci DTR Full EHR Test Suite' description File.read(File.join(__dir__, 'docs', 'dtr_full_ehr_suite_description_v201.md')) diff --git a/lib/davinci_dtr_test_kit/dtr_payer_server_suite.rb b/lib/davinci_dtr_test_kit/dtr_payer_server_suite.rb index 312aff6..d7f98b1 100644 --- a/lib/davinci_dtr_test_kit/dtr_payer_server_suite.rb +++ b/lib/davinci_dtr_test_kit/dtr_payer_server_suite.rb @@ -1,7 +1,7 @@ -require_relative 'ext/inferno_core/runnable' require_relative 'payer_server_groups/payer_server_static_group' require_relative 'payer_server_groups/payer_server_adaptive_group' require_relative 'tags' +require_relative 'endpoints/cors' require_relative 'endpoints/mock_authorization/simple_token_endpoint' require_relative 'endpoints/mock_payer/questionnaire_package_proxy_endpoint' require_relative 'endpoints/mock_payer/next_question_proxy_endpoint' @@ -9,6 +9,8 @@ module DaVinciDTRTestKit class DTRPayerServerSuite < Inferno::TestSuite + extend CORS + id :dtr_payer_server title 'Da Vinci DTR Payer Server Test Suite' description File.read(File.join(__dir__, 'docs', 'dtr_payer_server_suite_description_v201.md')) diff --git a/lib/davinci_dtr_test_kit/dtr_smart_app_suite.rb b/lib/davinci_dtr_test_kit/dtr_smart_app_suite.rb index 82141b1..7fb7ca3 100644 --- a/lib/davinci_dtr_test_kit/dtr_smart_app_suite.rb +++ b/lib/davinci_dtr_test_kit/dtr_smart_app_suite.rb @@ -1,8 +1,8 @@ -require_relative 'ext/inferno_core/runnable' require_relative 'auth_groups/oauth2_authentication_group' require_relative 'client_groups/resp_assist_device/dtr_smart_app_questionnaire_workflow_group' require_relative 'client_groups/dinner_static/dtr_smart_app_questionnaire_workflow_group' require_relative 'client_groups/dinner_adaptive/dtr_smart_app_questionnaire_workflow_group' +require_relative 'endpoints/cors' require_relative 'endpoints/mock_authorization' require_relative 'endpoints/mock_authorization/authorize_endpoint' require_relative 'endpoints/mock_authorization/token_endpoint' @@ -15,7 +15,8 @@ module DaVinciDTRTestKit class DTRSmartAppSuite < Inferno::TestSuite - Inferno::Application['logger'].level = Logger::ERROR + extend CORS + id :dtr_smart_app title 'Da Vinci DTR SMART App Test Suite' description File.read(File.join(__dir__, 'docs', 'dtr_smart_app_suite_description_v201.md')) diff --git a/lib/davinci_dtr_test_kit/endpoints/cors.rb b/lib/davinci_dtr_test_kit/endpoints/cors.rb new file mode 100644 index 0000000..ffff05c --- /dev/null +++ b/lib/davinci_dtr_test_kit/endpoints/cors.rb @@ -0,0 +1,20 @@ +module DaVinciDTRTestKit + module CORS + PRE_FLIGHT_HANDLER = proc do + [ + 200, + { + 'Access-Control-Allow-Origin' => '*', + 'Access-Control-Allow-Headers' => 'Content-Type, Authorization' + }, + [''] + ] + end + + def allow_cors(*paths) + paths.each do |path| + route(:options, path, PRE_FLIGHT_HANDLER) + end + end + end +end diff --git a/lib/davinci_dtr_test_kit/ext/inferno_core/runnable.rb b/lib/davinci_dtr_test_kit/ext/inferno_core/runnable.rb deleted file mode 100644 index 8dd8973..0000000 --- a/lib/davinci_dtr_test_kit/ext/inferno_core/runnable.rb +++ /dev/null @@ -1,22 +0,0 @@ -module Inferno - module DSL - module Runnable - PRE_FLIGHT_HANDLER = proc do - [ - 200, - { - 'Access-Control-Allow-Origin' => '*', - 'Access-Control-Allow-Headers' => 'Content-Type, Authorization' - }, - [''] - ] - end - - def allow_cors(*paths) - paths.each do |path| - route(:options, path, PRE_FLIGHT_HANDLER) - end - end - end - end -end