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_id, preset_id) ⇒ Object



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

def apply_preset(test_session_id, preset_id)
  preset = presets_repo.find(preset_id)
  preset.inputs.each do |input|
    session_data_repo.save(input.merge(test_session_id:))
  end
end

#build_entity(params) ⇒ Object



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

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



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

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



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

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

#results_for_test_session(test_session_id) ⇒ Object



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

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