Class: Inferno::DSL::RecordResponseRoute

Inherits:
Hanami::Action
  • Object
show all
Defined in:
lib/davinci_pdex_test_kit/ext/inferno_core/record_response_route.rb

Overview

A base class for creating routes with custom response logic. Requests and responses are tagged and saved.

See Also:

  • Inferno::DSL::Runnable#resume_test_route

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.callObject



16
17
18
# File 'lib/davinci_pdex_test_kit/ext/inferno_core/record_response_route.rb', line 16

def self.call(...)
  new.call(...)
end

Instance Method Details

#build_response_blockObject



26
27
28
# File 'lib/davinci_pdex_test_kit/ext/inferno_core/record_response_route.rb', line 26

def build_response_block
  self.class.singleton_class.instance_variable_get(:@build_response_block)
end

#find_test(waiting_result) ⇒ Object



68
69
70
# File 'lib/davinci_pdex_test_kit/ext/inferno_core/record_response_route.rb', line 68

def find_test(waiting_result)
  tests_repo.find(waiting_result.test_id)
end

#find_test_run(test_run_identifier) ⇒ Object



41
42
43
# File 'lib/davinci_pdex_test_kit/ext/inferno_core/record_response_route.rb', line 41

def find_test_run(test_run_identifier)
  test_runs_repo.find_latest_waiting_by_identifier(test_run_identifier)
end

#find_waiting_result(test_run) ⇒ Object



46
47
48
# File 'lib/davinci_pdex_test_kit/ext/inferno_core/record_response_route.rb', line 46

def find_waiting_result(test_run)
  results_repo.find_waiting_result(test_run_id: test_run.id)
end

#handle(req, res) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/davinci_pdex_test_kit/ext/inferno_core/record_response_route.rb', line 73

def handle(req, res)
  request = Inferno::Entities::Request.from_hanami_request(req)

  test_run_identifier = instance_exec(request, &test_run_identifier_block)

  test_run = find_test_run(test_run_identifier)

  halt 500, "Unable to find test run with identifier '#{test_run_identifier}'." if test_run.nil?

  waiting_result = find_waiting_result(test_run)
  test = find_test(waiting_result)

  test_runs_repo.mark_as_no_longer_waiting(test_run.id) if resumes? test

  update_result(waiting_result) if resumes? test

  instance_exec(request, test, waiting_result, &build_response_block)

  Inferno::Entities::Request.to_hanami_response(request, res)
  persist_request(request, test_run, waiting_result, test)

  Jobs.perform(Jobs::ResumeTestRun, test_run.id) if resumes? test
end

#persist_request(request, test_run, waiting_result, test) ⇒ Object



56
57
58
59
60
61
62
63
64
65
# File 'lib/davinci_pdex_test_kit/ext/inferno_core/record_response_route.rb', line 56

def persist_request(request, test_run, waiting_result, test)
  requests_repo.create(
    request.to_hash.merge(
      test_session_id: test_run.test_session_id,
      result_id: waiting_result.id,
      name: test.config.request_name(test.incoming_request_name),
      tags:
    )
  )
end

#resumes?(test) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/davinci_pdex_test_kit/ext/inferno_core/record_response_route.rb', line 36

def resumes?(test)
  instance_exec(test, &self.class.singleton_class.instance_variable_get(:@resumes))
end

#tagsObject



31
32
33
# File 'lib/davinci_pdex_test_kit/ext/inferno_core/record_response_route.rb', line 31

def tags
  self.class.singleton_class.instance_variable_get(:@tags)
end

#test_run_identifier_blockObject



21
22
23
# File 'lib/davinci_pdex_test_kit/ext/inferno_core/record_response_route.rb', line 21

def test_run_identifier_block
  self.class.singleton_class.instance_variable_get(:@test_run_identifier_block)
end

#update_result(waiting_result) ⇒ Object



51
52
53
# File 'lib/davinci_pdex_test_kit/ext/inferno_core/record_response_route.rb', line 51

def update_result(waiting_result)
  results_repo.update_result(waiting_result.id, 'pass')
end