Class: Inferno::Repositories::TestSessions

Inherits:
Repository
  • Object
show all
Defined in:
lib/inferno/repositories/test_sessions.rb

Overview

Repository that deals with persistence for the ‘TestSession` entity.

Defined Under Namespace

Classes: Model

Instance Method Summary collapse

Methods inherited from Repository

#add_non_db_entities, db, #db_params, #entity_class, #entity_class_name, #find, #handle_non_db_params, #non_db_params, table_name, #update

Instance Method Details

#apply_preset(test_session, preset_id) ⇒ Object



47
48
49
50
51
52
# File 'lib/inferno/repositories/test_sessions.rb', line 47

def apply_preset(test_session, preset_id)
  preset = presets_repo.find(preset_id)
  Utils::PresetProcessor.new(preset, test_session).processed_inputs.each do |input|
    session_data_repo.save(input.merge(test_session_id: test_session.id))
  end
end

#build_entity(params) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/inferno/repositories/test_sessions.rb', line 54

def build_entity(params)
  suite_options = JSON.parse(params[:suite_options] || '[]').map do |suite_option_hash|
    suite_option_hash.deep_symbolize_keys!
    suite_option_hash[:id] = suite_option_hash[:id].to_sym
    DSL::SuiteOption.new(suite_option_hash)
  end

  final_params = params.merge(suite_options:)
  add_non_db_entities(final_params)
  entity_class.new(final_params)
end

#create(params) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/inferno/repositories/test_sessions.rb', line 24

def create(params)
  raw_suite_options = params[:suite_options]
  suite_options =
    if raw_suite_options.blank?
      '[]'
    else
      JSON.generate(raw_suite_options.map(&:to_hash))
    end

  super(params.merge(suite_options:))
end

#json_serializer_optionsObject



15
16
17
18
19
20
21
22
# File 'lib/inferno/repositories/test_sessions.rb', line 15

def json_serializer_options
  {
    include: {
      results: results_repo.json_serializer_options,
      test_runs: {}
    }
  }
end

#results_for_test_session(test_session_id) ⇒ Object



36
37
38
39
40
41
42
43
44
45
# File 'lib/inferno/repositories/test_sessions.rb', line 36

def results_for_test_session(test_session_id)
  test_session_hash =
    self.class::Model
      .find(id: test_session_id)
      .to_json_data(json_serializer_options)
      .deep_symbolize_keys!

  test_session_hash[:results]
    .map! { |result| results_repo.build_entity(result) }
end