Class: Inferno::Web::Controllers::TestSessionFormPostController
- Inherits:
-
Hanami::Action
- Object
- Hanami::Action
- Inferno::Web::Controllers::TestSessionFormPostController
- Defined in:
- lib/inferno/apps/web/controllers/test_session_form_post_controller.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#handle(req, res) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity.
Class Method Details
.call ⇒ Object
11 12 13 |
# File 'lib/inferno/apps/web/controllers/test_session_form_post_controller.rb', line 11 def self.call(...) new.call(...) end |
Instance Method Details
#handle(req, res) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/inferno/apps/web/controllers/test_session_form_post_controller.rb', line 15 def handle(req, res) # rubocop:disable Metrics/CyclomaticComplexity test_suite_id = req.params[:test_suite_id] test_suite = Inferno::Repositories::TestSuites.new.find(test_suite_id) halt 404, "Unable to find test suite with id #{test_suite_id}" if test_suite.nil? params = { test_suite_id: } suite_option_keys = test_suite..map(&:id) = req.params.to_h.slice(*suite_option_keys) params[:suite_options] = .map { |key, value| { id: key, value: } } if .present? repo = Inferno::Repositories::TestSessions.new session = repo.create(params) preset_id = req.params[:preset_id] if preset_id.present? preset = Inferno::Repositories::Presets.new.find(preset_id) halt 422, "Unable to find preset with id #{preset_id} for test suite #{test_suite_id}" if preset.nil? repo.apply_preset(session, preset_id) end inputs = req.params[:inputs] if inputs.present? begin verify_runnable( test_suite, inputs, session. ) rescue Inferno::Exceptions::RequiredInputsNotFound => e Application['logger'].info("#{e.}. Can be added later at test run creation.") end params.merge!(inputs:, test_session_id: session.id) session_data_repo = Inferno::Repositories::SessionData.new persist_inputs(session_data_repo, params, test_suite) end res.redirect_to "#{Inferno::Application['base_url']}/#{test_suite_id}/#{session.id}" rescue Inferno::Exceptions::NotUserRunnableException => e halt 422, { errors: e. }.to_json rescue StandardError => e Application['logger'].error(e.) halt 500, { errors: e. }.to_json end |