replay-scenario 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.rubocop.yml +105 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE +21 -0
- data/README.md +2 -0
- data/Rakefile +10 -0
- data/lib/replay/scenario/context.rb +118 -0
- data/lib/replay/scenario/sequence.rb +80 -0
- data/lib/replay/scenario/version.rb +5 -0
- data/lib/replay/scenario.rb +78 -0
- data/lib/replay.rb +2 -0
- data/tmp/aliado +71 -0
- data/tmp/sequence +60 -0
- data/tmp/sequencer +64 -0
- metadata +87 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 535ba3ffa9643101815c58307068ba9ed1ea9d24d48378af5e0634ff49a6b63d
|
|
4
|
+
data.tar.gz: 9ea71115b5af9d61e660fc5d91ac5fe39c1962a020a8fc0d252b6f25bf0cac34
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: b80fc75dc7a71f4ca10e9859dea8d56b45323c2f074e0ea3baa1e0b7abe8636e85c4a3b29aa531c71cdef40f769111f3aea693c037bd1c0c3cf74954405e326c
|
|
7
|
+
data.tar.gz: 64c1098fa471efded2892bd827dac500e65003217206119bec15aad47140a49319161e247ea85272842a65477bbd7fc8561f29e244b0a84eace4f72dabab7067
|
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# https://docs.rubocop.org/rubocop/index.html
|
|
2
|
+
AllCops:
|
|
3
|
+
TargetRubyVersion: 3.X
|
|
4
|
+
NewCops: enable
|
|
5
|
+
|
|
6
|
+
# https://docs.rubocop.org/rubocop/cops_style.html#styletrailingcommainarrayliteral
|
|
7
|
+
Style/TrailingCommaInArrayLiteral:
|
|
8
|
+
Enabled: true
|
|
9
|
+
EnforcedStyleForMultiline: consistent_comma
|
|
10
|
+
|
|
11
|
+
# https://docs.rubocop.org/rubocop/cops_style.html#styletrailingcommainhashliteral
|
|
12
|
+
Style/TrailingCommaInHashLiteral:
|
|
13
|
+
Enabled: true
|
|
14
|
+
EnforcedStyleForMultiline: consistent_comma
|
|
15
|
+
|
|
16
|
+
# https://docs.rubocop.org/rubocop/cops_style.html#stylestringliterals
|
|
17
|
+
Style/StringLiterals:
|
|
18
|
+
Enabled: true
|
|
19
|
+
EnforcedStyle: single_quotes
|
|
20
|
+
|
|
21
|
+
# https://docs.rubocop.org/rubocop/cops_style.html#stylestringliteralsininterpolation
|
|
22
|
+
Style/StringLiteralsInInterpolation:
|
|
23
|
+
Enabled: true
|
|
24
|
+
EnforcedStyle: double_quotes
|
|
25
|
+
|
|
26
|
+
# https://docs.rubocop.org/rubocop/cops_style.html#stylefrozenstringliteralcomment
|
|
27
|
+
Style/FrozenStringLiteralComment:
|
|
28
|
+
Enabled: true
|
|
29
|
+
EnforcedStyle: never
|
|
30
|
+
|
|
31
|
+
# https://docs.rubocop.org/rubocop/cops_style.html#styledocumentation
|
|
32
|
+
Style/Documentation:
|
|
33
|
+
Enabled: false
|
|
34
|
+
|
|
35
|
+
# https://docs.rubocop.org/rubocop/cops_style.html#styledocumentationmethod
|
|
36
|
+
Style/DocumentationMethod:
|
|
37
|
+
Enabled: false
|
|
38
|
+
RequireForNonPublicMethods: false
|
|
39
|
+
|
|
40
|
+
# https://docs.rubocop.org/rubocop/cops_style.html#stylemodulefunction
|
|
41
|
+
Style/ModuleFunction:
|
|
42
|
+
Enabled: false
|
|
43
|
+
|
|
44
|
+
# https://docs.rubocop.org/rubocop/cops_style.html#stylemethodcallwithargsparentheses
|
|
45
|
+
Style/MethodCallWithArgsParentheses:
|
|
46
|
+
Enabled: true
|
|
47
|
+
EnforcedStyle: require_parentheses
|
|
48
|
+
|
|
49
|
+
# https://docs.rubocop.org/rubocop/cops_layout.html#layoutparameteralignment
|
|
50
|
+
Layout/ParameterAlignment:
|
|
51
|
+
EnforcedStyle: with_fixed_indentation
|
|
52
|
+
|
|
53
|
+
# https://docs.rubocop.org/rubocop/cops_layout.html#layoutfirsthashelementindentation
|
|
54
|
+
Layout/FirstHashElementIndentation:
|
|
55
|
+
EnforcedStyle: consistent
|
|
56
|
+
|
|
57
|
+
# https://docs.rubocop.org/rubocop/cops_layout.html#layoutfirstarrayelementindentation
|
|
58
|
+
Layout/FirstArrayElementIndentation:
|
|
59
|
+
EnforcedStyle: consistent
|
|
60
|
+
|
|
61
|
+
# https://docs.rubocop.org/rubocop/cops_layout.html#layoutlinelength
|
|
62
|
+
Layout/LineLength:
|
|
63
|
+
Max: 140
|
|
64
|
+
|
|
65
|
+
# https://docs.rubocop.org/rubocop/cops_naming.html#namingmethodparametername
|
|
66
|
+
Naming/MethodParameterName:
|
|
67
|
+
MinNameLength: 1
|
|
68
|
+
|
|
69
|
+
# https://docs.rubocop.org/rubocop/cops_metrics.html
|
|
70
|
+
Metrics/MethodLength:
|
|
71
|
+
Enabled: false
|
|
72
|
+
|
|
73
|
+
# https://docs.rubocop.org/rubocop/cops_metrics.html#metricsabcsize
|
|
74
|
+
Metrics/AbcSize:
|
|
75
|
+
Enabled: false
|
|
76
|
+
|
|
77
|
+
# https://docs.rubocop.org/rubocop/cops_metrics.html#metricsparameterlists
|
|
78
|
+
Metrics/ParameterLists:
|
|
79
|
+
Enabled: false
|
|
80
|
+
|
|
81
|
+
# https://docs.rubocop.org/rubocop/cops_metrics.html#metricsclasslength
|
|
82
|
+
Metrics/ClassLength:
|
|
83
|
+
Enabled: true
|
|
84
|
+
CountComments: false
|
|
85
|
+
Max: 300
|
|
86
|
+
|
|
87
|
+
# https://docs.rubocop.org/rubocop/cops_metrics.html#metricscyclomaticcomplexity
|
|
88
|
+
Metrics/CyclomaticComplexity:
|
|
89
|
+
Enabled: true
|
|
90
|
+
|
|
91
|
+
# https://docs.rubocop.org/rubocop/cops_metrics.html#metricsperceivedcomplexity
|
|
92
|
+
Metrics/PerceivedComplexity:
|
|
93
|
+
Enabled: false
|
|
94
|
+
|
|
95
|
+
# https://docs.rubocop.org/rubocop/cops_metrics.html#metricsblocklength
|
|
96
|
+
Metrics/BlockLength:
|
|
97
|
+
Enabled: false
|
|
98
|
+
|
|
99
|
+
# https://docs.rubocop.org/rubocop/cops_metrics.html#metricsmodulelength
|
|
100
|
+
Metrics/ModuleLength:
|
|
101
|
+
Enabled: false
|
|
102
|
+
|
|
103
|
+
Layout/MultilineMethodCallIndentation:
|
|
104
|
+
Enabled: true
|
|
105
|
+
EnforcedStyle: indented
|
data/CHANGELOG.md
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 thbrd
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
module Replay
|
|
2
|
+
module Scenario
|
|
3
|
+
class Context
|
|
4
|
+
def initialize(scenario)
|
|
5
|
+
@__replay_state = {}
|
|
6
|
+
|
|
7
|
+
# Define the configuration mechanism
|
|
8
|
+
__define_configure_method(
|
|
9
|
+
scenario,
|
|
10
|
+
scenario::REPLAY_ACTIONS.delete(:configure)
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
# Dynamically define user-provided actions as instance methods
|
|
14
|
+
scenario::REPLAY_ACTIONS.each do |name, info|
|
|
15
|
+
__define_action_method(scenario, name, info)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
scenario::REPLAY_SEQUENCES.each do |name, info|
|
|
19
|
+
__define_sequence_method(scenario, name, info)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
scenario::REPLAY_INCLUSIONS.each do |subcontext|
|
|
23
|
+
singleton_class.include(subcontext)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
scenario::REPLAY_EXTENSIONS.each do |subcontext|
|
|
27
|
+
singleton_class.extend(subcontext)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# State management methods
|
|
32
|
+
def get(field)
|
|
33
|
+
@__replay_state[field]
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def set(field, value)
|
|
37
|
+
@__replay_state[field] = value
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# Request methods
|
|
41
|
+
def http(method, uri, options = {})
|
|
42
|
+
raise(ArgumentError, "Invalid HTTP method: #{method}") unless HTTParty.respond_to?(method)
|
|
43
|
+
|
|
44
|
+
# options = options.merge({ debug_output: $stdout })
|
|
45
|
+
response = HTTParty.send(method, uri, options)
|
|
46
|
+
|
|
47
|
+
return response unless block_given?
|
|
48
|
+
|
|
49
|
+
yield(response)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
private
|
|
53
|
+
|
|
54
|
+
def __define_configure_method(scenario, info)
|
|
55
|
+
if info.nil?
|
|
56
|
+
@__replay_configured = true
|
|
57
|
+
define_singleton_method(:configure) { |*| }
|
|
58
|
+
return
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
@__replay_configured = false
|
|
62
|
+
default, blk = info.values_at(:default, :blk)
|
|
63
|
+
_requireness, parameter = blk.parameters.first || []
|
|
64
|
+
|
|
65
|
+
define_singleton_method(:configure) do |argument = default, &handler|
|
|
66
|
+
if argument.nil? && !parameter.nil?
|
|
67
|
+
raise(ArgumentError,
|
|
68
|
+
"Expected '#{parameter}' on 'configure' action from #{scenario}, got: nil")
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
@__replay_configured = true
|
|
72
|
+
|
|
73
|
+
result = instance_exec(argument, &blk)
|
|
74
|
+
|
|
75
|
+
return result if handler.nil?
|
|
76
|
+
|
|
77
|
+
handler.call(result)
|
|
78
|
+
rescue LocalJumpError => e
|
|
79
|
+
e.exit_value
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def __define_action_method(scenario, name, info)
|
|
84
|
+
default, blk = info.values_at(:default, :blk)
|
|
85
|
+
_requireness, parameter = blk.parameters.first || []
|
|
86
|
+
|
|
87
|
+
define_singleton_method(name) do |argument = default, &handler|
|
|
88
|
+
raise("#{scenario} hasn't been configured yet, call .configure") unless @__replay_configured
|
|
89
|
+
raise(ArgumentError, "Expected '#{parameter}' on '#{name}' action from #{scenario}, got nil") if argument.nil? && !parameter.nil?
|
|
90
|
+
|
|
91
|
+
result = instance_exec(argument, &blk)
|
|
92
|
+
|
|
93
|
+
return result if handler.nil?
|
|
94
|
+
|
|
95
|
+
handler.call(result)
|
|
96
|
+
rescue LocalJumpError => e
|
|
97
|
+
e.exit_value
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def __define_sequence_method(scenario, name, info)
|
|
102
|
+
defaults, blk = info.values_at(:defaults, :blk)
|
|
103
|
+
|
|
104
|
+
if !defaults.nil? && !defaults.is_a?(Enumerable)
|
|
105
|
+
raise(ArgumentError, "Expected an Enumerable as '#{name}' default items, got: #{defaults}")
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
define_singleton_method(name) do
|
|
109
|
+
sequence = instance_variable_get("@#{name}")
|
|
110
|
+
|
|
111
|
+
return sequence unless sequence.nil?
|
|
112
|
+
|
|
113
|
+
instance_variable_set("@#{name}", Replay::Scenario::Sequence.new(self, scenario, defaults, name, blk))
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
module Replay
|
|
2
|
+
module Scenario
|
|
3
|
+
class Sequence
|
|
4
|
+
attr_reader :context, :scenario, :defaults, :identifier, :items, :index, :blk
|
|
5
|
+
|
|
6
|
+
def initialize(context, scenario, defaults, identifier, blk)
|
|
7
|
+
@context = context
|
|
8
|
+
@scenario = scenario
|
|
9
|
+
@defaults = defaults
|
|
10
|
+
@identifier = identifier
|
|
11
|
+
@index = 0
|
|
12
|
+
@blk = blk
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def set(items = defaults)
|
|
16
|
+
raise(ArgumentError, "Expected an Enumerable as '#{identifier}' items, got: nil") if items.nil?
|
|
17
|
+
raise(ArgumentError, "Expected an Enumerable as '#{identifier}' items, got: #{items}") unless items.is_a?(Enumerable)
|
|
18
|
+
|
|
19
|
+
@index = 0
|
|
20
|
+
@items = items
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def fw(steps = 1)
|
|
24
|
+
return if steps <= 0
|
|
25
|
+
|
|
26
|
+
@items ||= defaults
|
|
27
|
+
|
|
28
|
+
raise("No sequence of items found for '#{identifier}' sequece, run #set first") if items.nil?
|
|
29
|
+
|
|
30
|
+
results = steps.times.map { __fw }
|
|
31
|
+
|
|
32
|
+
steps == 1 ? results.first : results
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def bw(steps = 1)
|
|
36
|
+
return if steps <= 0
|
|
37
|
+
|
|
38
|
+
@items ||= defaults
|
|
39
|
+
|
|
40
|
+
raise("No sequence of items found for '#{identifier}' sequece, run #set first") if items.nil?
|
|
41
|
+
|
|
42
|
+
results = steps.times.map { __bw }
|
|
43
|
+
|
|
44
|
+
steps == 1 ? results.first : results
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def rw
|
|
48
|
+
@items ||= defaults
|
|
49
|
+
|
|
50
|
+
raise("No sequence of items found for '#{identifier}' sequece, run #set first") if items.nil?
|
|
51
|
+
|
|
52
|
+
(@index + 1).tap do
|
|
53
|
+
@index = -1
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
private
|
|
58
|
+
|
|
59
|
+
def __fw
|
|
60
|
+
return if index >= items.size
|
|
61
|
+
|
|
62
|
+
@index = [0, index].max
|
|
63
|
+
|
|
64
|
+
context.instance_exec(items[index], &blk).tap do
|
|
65
|
+
@index += 1
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def __bw
|
|
70
|
+
return if index < 0
|
|
71
|
+
|
|
72
|
+
@index = [index, items.size - 1].min
|
|
73
|
+
|
|
74
|
+
context.instance_exec(items[index], &blk).tap do
|
|
75
|
+
@index -= 1
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
require 'pry'
|
|
2
|
+
require 'httparty'
|
|
3
|
+
|
|
4
|
+
require_relative 'scenario/version'
|
|
5
|
+
require_relative 'scenario/sequence'
|
|
6
|
+
require_relative 'scenario/context'
|
|
7
|
+
|
|
8
|
+
module Replay
|
|
9
|
+
module Scenario
|
|
10
|
+
def self.included(scenario)
|
|
11
|
+
case scenario
|
|
12
|
+
when Class
|
|
13
|
+
raise(ArgumentError, "Replay should only be included in modules: #{klass}")
|
|
14
|
+
when Module
|
|
15
|
+
scenario.const_set(:REPLAY_ACTIONS, {}) unless scenario.const_defined?(:REPLAY_ACTIONS)
|
|
16
|
+
scenario.const_set(:REPLAY_SEQUENCES, {}) unless scenario.const_defined?(:REPLAY_SEQUENCES)
|
|
17
|
+
scenario.const_set(:REPLAY_INCLUSIONS, []) unless scenario.const_defined?(:REPLAY_INCLUSIONS)
|
|
18
|
+
scenario.const_set(:REPLAY_EXTENSIONS, []) unless scenario.const_defined?(:REPLAY_EXTENSIONS)
|
|
19
|
+
scenario.const_set(:REPLAY_SCENARIO_NAME, scenario.name.split('::').last.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').gsub(/([a-z\d])([A-Z])/, '\1_\2').tr('-', '_').gsub(/\s/, '_').gsub(/__+/, '_').downcase) # rubocop:disable Layout/LineLength
|
|
20
|
+
scenario.extend(ReplayDefinitionMethods)
|
|
21
|
+
abstract_include(scenario)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def self.abstract_include(scenario)
|
|
26
|
+
scenario.extend(scenario)
|
|
27
|
+
|
|
28
|
+
scenario.module_eval do
|
|
29
|
+
scenario_wrapper = Module.new do
|
|
30
|
+
define_method scenario::REPLAY_SCENARIO_NAME do
|
|
31
|
+
scenario.__replay_context
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
define_singleton_method(:included) do |scenario_includer|
|
|
36
|
+
scenario_includer.const_set(:REPLAY_INCLUSIONS, []) unless scenario_includer.const_defined?(:REPLAY_INCLUSIONS)
|
|
37
|
+
scenario_includer::REPLAY_INCLUSIONS << scenario_wrapper
|
|
38
|
+
scenario_includer.send(:include, scenario_wrapper)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
define_singleton_method(:extended) do |scenario_extender|
|
|
42
|
+
scenario_extender.const_set(:REPLAY_EXTENSIONS, []) unless scenario_extender.const_defined?(:REPLAY_EXTENSIONS)
|
|
43
|
+
scenario_extender::REPLAY_EXTENSIONS << scenario_wrapper
|
|
44
|
+
scenario_extender.send(:extend, scenario_wrapper)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
module ReplayDefinitionMethods
|
|
50
|
+
def configuration(default = nil, &blk)
|
|
51
|
+
self::REPLAY_ACTIONS[:configure] = { default: default, blk: blk }
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def action(name, default = nil, &blk)
|
|
55
|
+
self::REPLAY_ACTIONS[name.to_sym] = { default: default, blk: blk }
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def sequence(name, defaults = nil, &blk)
|
|
59
|
+
self::REPLAY_SEQUENCES[name.to_sym] = { defaults: defaults, blk: blk }
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def start(argument = nil)
|
|
63
|
+
context = Replay::Scenario::Context.new(self).tap do |ctx|
|
|
64
|
+
ctx.configure(argument)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
Pry.start(
|
|
68
|
+
context,
|
|
69
|
+
prompt: Pry::Prompt.new('replay', 'replay custom prompt', [proc { "replay(#{self::REPLAY_SCENARIO_NAME})> " }])
|
|
70
|
+
)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def __replay_context
|
|
74
|
+
@__replay_context ||= Replay::Scenario::Context.new(self)
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
data/lib/replay.rb
ADDED
data/tmp/aliado
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
module Gql
|
|
2
|
+
include Replay
|
|
3
|
+
|
|
4
|
+
configuration do |environment|
|
|
5
|
+
set :api_host, URI.join(environment[:host], 'api')
|
|
6
|
+
set :gql_host, URI.join(environment[:host], 'graphql')
|
|
7
|
+
|
|
8
|
+
login environment.slice(:email, :password)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
LOGIN = <<-GRAPHQL
|
|
12
|
+
mutation LOG_IN($input: LoginInput!) { login(input: $input) { accessToken }}
|
|
13
|
+
GRAPHQL
|
|
14
|
+
action :login do |credentials|
|
|
15
|
+
options = {
|
|
16
|
+
headers: { 'Content-Type' => 'application/json' },
|
|
17
|
+
body: { query: LOGIN, variables: { input: credentials } }.to_json,
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
access_token = http(:post, get(:gql_host), options) do |response|
|
|
21
|
+
response.dig('data', 'login', 'accessToken') if response.code == 200
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
set :access_token, access_token
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
action :request do |body|
|
|
28
|
+
options = {
|
|
29
|
+
body: body.to_json,
|
|
30
|
+
headers: { 'Content-Type' => 'application/json', 'Authorization' => "Bearer #{get(:access_token)}" },
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
http :post, get(:gql_host), options do |response|
|
|
34
|
+
response['data'] if response.code == 200
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
module Missions
|
|
40
|
+
include Replay
|
|
41
|
+
include Gql
|
|
42
|
+
|
|
43
|
+
configuration do |environment|
|
|
44
|
+
gql.configure(environment)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
GET_T1_MISSION = <<-GRAPHQL.freeze
|
|
48
|
+
query T1_MISSION($id: ID!) { t1Mission(id: $id) { id status onTime status externalId endDatetime startDatetime externalEndDatetime externalStartDatetime units { id kind bearing direction economic drivingStatus inMissionStatus org { id name } address { id name description reference street neighborhood municipality state country zipCode lat lon } latestReading { datetime latlon { lat lon } } descriptorItems { id identifier name value type labels { en es } } } operators { id name employeeId operativeUnit org { id name } descriptorItems { id identifier name value type labels { en es } } } descriptorItems { id identifier name value type labels { en es } } goalsPlanning { firstGoal { __typename ... on DestinationGoal { id seq realArrival realDeparture scheduleArrival scheduleDeparture externalScheduleArrival externalScheduleDeparture } } lastGoal { __typename ... on DestinationGoal { id seq realArrival realDeparture scheduleArrival scheduleDeparture externalScheduleArrival externalScheduleDeparture address { id name description reference street neighborhood municipality state country zipCode lat lon geofence { id name value } } } } nextGoal { __typename ... on DestinationGoal { id seq realArrival realDeparture scheduleArrival scheduleDeparture externalScheduleArrival externalScheduleDeparture address { id name description reference street neighborhood municipality state country zipCode lat lon geofence { id name value } } } } previousGoal { __typename ... on DestinationGoal { id seq realArrival realDeparture scheduleArrival scheduleDeparture externalScheduleArrival externalScheduleDeparture address { id name description reference street neighborhood municipality state country zipCode lat lon geofence { id name value } } } } currentGoal { __typename ... on DestinationGoal { id seq realArrival realDeparture scheduleArrival scheduleDeparture externalScheduleArrival externalScheduleDeparture address { id name description reference street neighborhood municipality state country zipCode lat lon geofence { id name value } } } } achievedGoals { __typename ... on DestinationGoal { id seq realArrival realDeparture scheduleArrival scheduleDeparture externalScheduleArrival externalScheduleDeparture address { id name description reference street neighborhood municipality state country zipCode lat lon geofence { id name value } } } } remainingGoals { __typename ... on DestinationGoal { id seq realArrival realDeparture scheduleArrival scheduleDeparture externalScheduleArrival externalScheduleDeparture address { id name description reference street neighborhood municipality state country zipCode lat lon geofence { id name value } } } } } } }
|
|
49
|
+
GRAPHQL
|
|
50
|
+
action :get_t1_mission do |id|
|
|
51
|
+
gql.request({ query: GET_T1_MISSION, variables: { id: id } }) do |data|
|
|
52
|
+
data&.dig('t1Mission')
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Missions.start({
|
|
58
|
+
# host: 'https://dev.aliado.alephri.com',
|
|
59
|
+
# email: 'admin@aleph.com',
|
|
60
|
+
# password: 'password',
|
|
61
|
+
# })
|
|
62
|
+
|
|
63
|
+
include Missions
|
|
64
|
+
|
|
65
|
+
# missions.configure({
|
|
66
|
+
# host: 'https://dev.aliado.alephri.com',
|
|
67
|
+
# email: 'admin@aleph.com',
|
|
68
|
+
# password: 'password',
|
|
69
|
+
# })
|
|
70
|
+
|
|
71
|
+
pp missions.get_t1_mission('f10ab504-5a39-47f6-9ebf-b3dfe57df5bc')
|
data/tmp/sequence
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
module Replay
|
|
2
|
+
class Sequence
|
|
3
|
+
attr_reader :context, :scenario, :defaults, :identifier, :items, :index, :blk
|
|
4
|
+
|
|
5
|
+
def initialize(context, scenario, defaults, identifier, blk)
|
|
6
|
+
@context = context
|
|
7
|
+
@scenario = scenario
|
|
8
|
+
@defaults = defaults
|
|
9
|
+
@identifier = identifier
|
|
10
|
+
@index = 0
|
|
11
|
+
@blk = blk
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def start(items = defaults)
|
|
15
|
+
raise(ArgumentError, "Expected an Enumerable for '#{identifier}' sequence from #{scenario}, got: nil") if items.nil?
|
|
16
|
+
raise(ArgumentError, "Expected an Enumerable for '#{identifier}' sequence from #{scenario}, got: #{items}") unless items.is_a?(Enumerable) # rubocop:disable Layout/LineLength
|
|
17
|
+
|
|
18
|
+
@index = 0
|
|
19
|
+
@items = items
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def fw(steps = 1)
|
|
23
|
+
results = []
|
|
24
|
+
|
|
25
|
+
@index = 0 if index < 0
|
|
26
|
+
|
|
27
|
+
steps.times do
|
|
28
|
+
break if index > items.size - 1
|
|
29
|
+
|
|
30
|
+
results << context.instance_exec(items[index], &blk)
|
|
31
|
+
|
|
32
|
+
@index += 1
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
steps == 1 ? results.first : results
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def bw(steps = 1)
|
|
39
|
+
results = []
|
|
40
|
+
|
|
41
|
+
@index = items.size - 1 if index >= items.size
|
|
42
|
+
|
|
43
|
+
steps.times do
|
|
44
|
+
break if index < 0
|
|
45
|
+
|
|
46
|
+
results << context.instance_exec(items[index], &blk)
|
|
47
|
+
|
|
48
|
+
@index -= 1
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
steps == 1 ? results.first : results
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def rw
|
|
55
|
+
(@index + 1).tap do
|
|
56
|
+
@index = -1
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
data/tmp/sequencer
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
def start(name, items = nil)
|
|
2
|
+
unless @__replay_sequence.nil?
|
|
3
|
+
puts("WARN: Currently active '#{@__replay_sequence.identifier}' sequence, finish it first")
|
|
4
|
+
return
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
sequence = @__replay_sequences[name.to_sym]
|
|
8
|
+
|
|
9
|
+
if sequence.nil?
|
|
10
|
+
puts("WARN: No '#{name}' sequence available")
|
|
11
|
+
return
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
items ||= sequence[:defaults]
|
|
15
|
+
|
|
16
|
+
raise(ArgumentError, "No items were provided to '#{name}' sequence start, nor has default items") if items.nil?
|
|
17
|
+
raise(ArgumentError, "An enumerble must be provided to '#{name}' sequence: #{items}") unless items.is_a?(Enumerable)
|
|
18
|
+
|
|
19
|
+
@__replay_sequence = Replay::Sequence.new(name.to_sym, items, sequence[:blk])
|
|
20
|
+
|
|
21
|
+
@__replay_sequence.identifier
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def fw(steps = 1)
|
|
25
|
+
if @__replay_sequence.nil?
|
|
26
|
+
puts('WARN: No active sequence, ignoring')
|
|
27
|
+
return
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
raise(ArgumentError, "Expected a postive amount of steps forward: #{steps}") unless steps.is_a?(Integer) && steps.positive?
|
|
31
|
+
|
|
32
|
+
@__replay_sequence.fw(self, steps)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def bw(steps = 1)
|
|
36
|
+
if @__replay_sequence.nil?
|
|
37
|
+
puts('WARN: No active sequence, ignoring')
|
|
38
|
+
return
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
raise(ArgumentError, "Expected a postive amount of steps backwards: #{steps}") unless steps.is_a?(Integer) && steps.positive?
|
|
42
|
+
|
|
43
|
+
@__replay_sequence.bw(self, steps)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def rw
|
|
47
|
+
if @__replay_sequence.nil?
|
|
48
|
+
puts('WARN: No active sequence, ignoring')
|
|
49
|
+
return
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
@__replay_sequence.rw
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def finish
|
|
56
|
+
if @__replay_sequence.nil?
|
|
57
|
+
puts('WARN: No active sequence, ignoring')
|
|
58
|
+
return
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
@__replay_sequence.identifier.tap do
|
|
62
|
+
@__replay_sequence = nil
|
|
63
|
+
end
|
|
64
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: replay-scenario
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- jaimecgomezz
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2024-11-19 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: httparty
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 0.22.0
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: 0.22.0
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: pry
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: 0.14.2
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: 0.14.2
|
|
41
|
+
description: Replay interactive scenarios
|
|
42
|
+
email:
|
|
43
|
+
- work@jaimecgomezwork.com
|
|
44
|
+
executables: []
|
|
45
|
+
extensions: []
|
|
46
|
+
extra_rdoc_files: []
|
|
47
|
+
files:
|
|
48
|
+
- ".rubocop.yml"
|
|
49
|
+
- CHANGELOG.md
|
|
50
|
+
- LICENSE
|
|
51
|
+
- README.md
|
|
52
|
+
- Rakefile
|
|
53
|
+
- lib/replay.rb
|
|
54
|
+
- lib/replay/scenario.rb
|
|
55
|
+
- lib/replay/scenario/context.rb
|
|
56
|
+
- lib/replay/scenario/sequence.rb
|
|
57
|
+
- lib/replay/scenario/version.rb
|
|
58
|
+
- tmp/aliado
|
|
59
|
+
- tmp/sequence
|
|
60
|
+
- tmp/sequencer
|
|
61
|
+
homepage: https://github.com/jaimecgomezz/replay.rb
|
|
62
|
+
licenses: []
|
|
63
|
+
metadata:
|
|
64
|
+
homepage_uri: https://github.com/jaimecgomezz/replay.rb
|
|
65
|
+
changelog_uri: https://github.com/jaimecgomezz/replay.rb
|
|
66
|
+
source_code_uri: https://github.com/jaimecgomezz/replay.rb
|
|
67
|
+
rubygems_mfa_required: 'true'
|
|
68
|
+
post_install_message:
|
|
69
|
+
rdoc_options: []
|
|
70
|
+
require_paths:
|
|
71
|
+
- lib
|
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
73
|
+
requirements:
|
|
74
|
+
- - ">="
|
|
75
|
+
- !ruby/object:Gem::Version
|
|
76
|
+
version: 2.6.0
|
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
78
|
+
requirements:
|
|
79
|
+
- - ">="
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: '0'
|
|
82
|
+
requirements: []
|
|
83
|
+
rubygems_version: 3.4.10
|
|
84
|
+
signing_key:
|
|
85
|
+
specification_version: 4
|
|
86
|
+
summary: Replay interactive scenarios
|
|
87
|
+
test_files: []
|