light-service-ext 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +6 -0
  3. data/CHANGELOG.md +9 -1
  4. data/README.md +193 -5
  5. data/dev/setup.rb +5 -3
  6. data/lib/light-service-ext/application_action.rb +0 -21
  7. data/lib/light-service-ext/application_context.rb +29 -1
  8. data/lib/light-service-ext/application_validator_action.rb +2 -2
  9. data/lib/light-service-ext/configuration.rb +28 -0
  10. data/lib/light-service-ext/constants.rb +1 -1
  11. data/lib/light-service-ext/error_info.rb +11 -11
  12. data/lib/light-service-ext/version.rb +1 -1
  13. data/lib/light-service-ext/with_error_handler.rb +26 -0
  14. data/lib/light-service-ext.rb +35 -13
  15. data/light-service-ext.gemspec +1 -0
  16. data/spec/light-service-ext/application_action_spec.rb +39 -0
  17. data/spec/light-service-ext/application_context_spec.rb +189 -0
  18. data/spec/{light_service_ext → light-service-ext}/application_organizer_spec.rb +9 -2
  19. data/spec/light-service-ext/configuration_spec.rb +66 -0
  20. data/spec/{light_service_ext → light-service-ext}/error_info_spec.rb +18 -7
  21. data/spec/light-service-ext/with_error_handler_spec.rb +62 -0
  22. data/spec/light_service_ext_spec.rb +67 -1
  23. data/spec/spec_helper.rb +7 -3
  24. metadata +42 -22
  25. data/spec/light_service_ext/application_action_spec.rb +0 -77
  26. data/spec/light_service_ext/application_context_spec.rb +0 -68
  27. /data/spec/{light_service_ext → light-service-ext}/all_actions_complete_action_spec.rb +0 -0
  28. /data/spec/{light_service_ext → light-service-ext}/application_contract_spec.rb +0 -0
  29. /data/spec/{light_service_ext → light-service-ext}/application_validator_action_spec.rb +0 -0
  30. /data/spec/{light_service_ext → light-service-ext}/around_action_execute_extension_spec.rb +0 -0
  31. /data/spec/{light_service_ext → light-service-ext}/context_error_spec.rb +0 -0
  32. /data/spec/{light_service_ext → light-service-ext}/regex_spec.rb +0 -0
@@ -0,0 +1,189 @@
1
+ # rubocop:disable Metrics/ModuleLength
2
+ module LightServiceExt
3
+ RSpec.describe ApplicationContext do
4
+ let(:input) { { key: 'some-value' } }
5
+ let(:key) { :key }
6
+ let(:value) { 'some-value' }
7
+
8
+ subject(:ctx) { described_class.make_with_defaults(input) }
9
+
10
+ describe '#add_errors!' do
11
+ before { allow(ctx).to receive(:fail_and_return!) }
12
+
13
+ it 'fails the context' do
14
+ ctx.add_errors!(key => value)
15
+
16
+ expect(ctx).to have_received(:fail_and_return!)
17
+ end
18
+
19
+ it 'adds errors to context' do
20
+ ctx.add_errors!(key => value)
21
+
22
+ expect(ctx.errors).to eql(key => value)
23
+ end
24
+
25
+ it 'updates older values' do
26
+ ctx.add_errors!(key => value)
27
+
28
+ ctx.add_errors!(key => 'other-value')
29
+
30
+ expect(ctx.errors).to eql(key => 'other-value')
31
+ end
32
+
33
+ it 'preserves other keys' do
34
+ ctx.add_errors!(key => value)
35
+
36
+ ctx.add_errors!(other_key: 'other-value')
37
+
38
+ expect(ctx.errors).to include(key => value, :other_key => 'other-value')
39
+ end
40
+ end
41
+
42
+ describe '#add_errors' do
43
+ before { allow(ctx).to receive(:fail_and_return!) }
44
+
45
+ it 'does not fail the context' do
46
+ ctx.add_errors(key => value)
47
+
48
+ expect(ctx).not_to have_received(:fail_and_return!)
49
+ end
50
+
51
+ it 'adds errors to context' do
52
+ ctx.add_errors(key => value)
53
+
54
+ expect(ctx.errors).to eql(key => value)
55
+ end
56
+
57
+ it 'updates older values' do
58
+ ctx.add_errors(key => value)
59
+
60
+ ctx.add_errors(key => 'other-value')
61
+
62
+ expect(ctx.errors).to eql(key => 'other-value')
63
+ end
64
+
65
+ it 'preserves other keys' do
66
+ ctx.add_errors(key => value)
67
+
68
+ ctx.add_errors(other_key: 'other-value')
69
+
70
+ expect(ctx.errors).to include(key => value, :other_key => 'other-value')
71
+ end
72
+ end
73
+
74
+ describe '#add_params' do
75
+ it 'adds params to context' do
76
+ ctx.add_params(key => value)
77
+
78
+ expect(ctx.params).to eql(key => value)
79
+ end
80
+
81
+ it 'updates older values' do
82
+ ctx.add_params(key => value)
83
+
84
+ ctx.add_params(key => 'other-value')
85
+
86
+ expect(ctx.params).to eql(key => 'other-value')
87
+ end
88
+
89
+ it 'preserves other keys' do
90
+ ctx.add_params(key => value)
91
+
92
+ ctx.add_params(other_key: 'other-value')
93
+
94
+ expect(ctx.params).to include(key => value, :other_key => 'other-value')
95
+ end
96
+ end
97
+
98
+ describe '#add_internal_only' do
99
+ it 'adds params to context' do
100
+ ctx.add_internal_only(key => value)
101
+
102
+ expect(ctx.internal_only).to include(key => value)
103
+ end
104
+
105
+ it 'updates older values' do
106
+ ctx.add_internal_only(key => value)
107
+
108
+ ctx.add_internal_only(key => 'other-value')
109
+
110
+ expect(ctx.internal_only).to include(key => 'other-value')
111
+ end
112
+
113
+ it 'preserves other keys' do
114
+ ctx.add_internal_only(key => value)
115
+
116
+ ctx.add_internal_only(other_key: 'other-value')
117
+
118
+ expect(ctx.internal_only).to include(key => value, :other_key => 'other-value')
119
+ end
120
+ end
121
+
122
+ describe '.make_with_defaults' do
123
+ let(:input) { { key: 'some-value' } }
124
+ let(:overrides) { {} }
125
+
126
+ subject(:ctx_with_defaults) { described_class.make_with_defaults(input, overrides) }
127
+
128
+ context 'with non symbolized input keys' do
129
+ let(:input) { { "key" => 'some-value' } }
130
+
131
+ it 'symbolizes input attr keys' do
132
+ expect(ctx_with_defaults[:input].keys).to include(:key)
133
+ end
134
+ end
135
+
136
+ it 'returns context with default attrs' do
137
+ expect(ctx_with_defaults.keys).to match_array(%i[input
138
+ errors
139
+ params
140
+ successful_actions
141
+ api_responses
142
+ allow_raise_on_failure
143
+ internal_only])
144
+
145
+ expect(ctx_with_defaults[:input]).to eql(input)
146
+ end
147
+
148
+ describe 'overrideable attrs' do
149
+ { errors: { key: 'some-error' },
150
+ params: { key: 'value' },
151
+ allow_raise_on_failure: false }.each_pair do |overridable_key, value|
152
+ it "allows for default #{overridable_key.inspect} to be changed" do
153
+ ctx_with_defaults = described_class.make_with_defaults(input, **{ overridable_key => value })
154
+ expect(ctx_with_defaults[overridable_key]).to eql(value)
155
+ end
156
+ end
157
+
158
+ context 'with successful_actions set' do
159
+ subject(:ctx_with_defaults) do
160
+ described_class.make_with_defaults(input, successful_actions: ['some-action-class-name'])
161
+ end
162
+
163
+ it 'prevents successful_actions to change from default' do
164
+ expect(ctx_with_defaults[:successful_actions]).to be_empty
165
+ end
166
+ end
167
+
168
+ context 'with api_responses set' do
169
+ subject(:ctx_with_defaults) do
170
+ described_class.make_with_defaults(input, api_responses: ['some-api-response'])
171
+ end
172
+
173
+ it 'prevents successful_actions to change from default' do
174
+ expect(ctx_with_defaults[:api_responses]).to be_empty
175
+ end
176
+ end
177
+
178
+ context 'with unexpected override' do
179
+ subject(:ctx_with_defaults) { described_class.make_with_defaults(input, unknown_key: 'some-value') }
180
+
181
+ it 'prevents successful_actions to change from default' do
182
+ expect(ctx_with_defaults.keys).not_to include(:unknown_key)
183
+ end
184
+ end
185
+ end
186
+ end
187
+ end
188
+ end
189
+ # rubocop:enable Metrics/ModuleLength
@@ -27,8 +27,15 @@ module LightServiceExt
27
27
  it 'adds inputted data as input key value pair' do
28
28
  ctx = subject_class.call(input)
29
29
 
30
- expect(ctx.keys).to match_array(%i[api_responses errors input params allow_raise_on_failure
31
- successful_actions])
30
+ expect(ctx.keys).to match_array(%i[
31
+ api_responses
32
+ errors
33
+ input
34
+ params
35
+ allow_raise_on_failure
36
+ successful_actions
37
+ internal_only
38
+ ])
32
39
  expect(ctx[:input]).to eql(input)
33
40
  end
34
41
 
@@ -0,0 +1,66 @@
1
+ module LightServiceExt
2
+ RSpec.describe Configuration do
3
+ let(:error_class) { ArgumentError }
4
+ let(:default_error_class) { EncodingError }
5
+
6
+ subject(:config) { described_class.new }
7
+
8
+ describe '#new' do
9
+ context 'with non fatal error classes' do
10
+ before do
11
+ config.non_fatal_error_classes = [error_class]
12
+ end
13
+
14
+ describe '#non_fatal_error_classes' do
15
+ it 'returns set fatal error classes' do
16
+ expect(config.non_fatal_error_classes).to match_array([error_class])
17
+ end
18
+ end
19
+ end
20
+
21
+ context 'with default non fatal errors' do
22
+ before do
23
+ described_class.configure do |config|
24
+ config.default_non_fatal_error_classes = [default_error_class]
25
+ end
26
+ end
27
+
28
+ describe '#default_non_fatal_error_classes' do
29
+ it 'returns set non fatal error classes' do
30
+ expect(config.default_non_fatal_error_classes).to match_array([default_error_class])
31
+ end
32
+ end
33
+ end
34
+
35
+ context 'with default and non default non fatal errors' do
36
+ before do
37
+ described_class.configure do |config|
38
+ config.non_fatal_error_classes = [error_class, default_error_class, nil]
39
+ config.default_non_fatal_error_classes = [default_error_class]
40
+ end
41
+ end
42
+
43
+ describe '#non_fatal_errors' do
44
+ it 'returns non duplicate error classes' do
45
+ expect(config.non_fatal_errors).to match_array([error_class, default_error_class].map(&:to_s))
46
+ end
47
+ end
48
+ end
49
+
50
+ describe '#allow_raise_on_failure' do
51
+ it 'returns false' do
52
+ expect(config.allow_raise_on_failure?).to be_truthy
53
+ end
54
+
55
+ context 'with allow raise on failure unset' do
56
+ it 'returns true' do
57
+ described_class.configure { |config| config.allow_raise_on_failure = false }
58
+
59
+ expect(config.allow_raise_on_failure?).to be_falsey
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+
@@ -4,7 +4,7 @@ RSpec.describe LightServiceExt::ErrorInfo do
4
4
  let(:value) { 'some-value' }
5
5
  let(:message_override) { nil }
6
6
  let(:message) { 'some-error' }
7
- let(:fatal) { nil }
7
+ let(:fatal) { false }
8
8
  let(:backtrace) { ['some-backtrace-item'] }
9
9
  let(:error) { StandardError.new(message) }
10
10
  let(:error_info_class) { Class.new(described_class) }
@@ -53,8 +53,6 @@ RSpec.describe LightServiceExt::ErrorInfo do
53
53
  context 'with non fatal error' do
54
54
  let(:error) { ArgumentError.new(message) }
55
55
 
56
- before { error_info_class.non_fatal_errors = [ArgumentError] }
57
-
58
56
  context 'with fatal passed as arg' do
59
57
  let(:fatal) { true }
60
58
 
@@ -63,8 +61,20 @@ RSpec.describe LightServiceExt::ErrorInfo do
63
61
  end
64
62
  end
65
63
 
66
- it 'returns false' do
67
- expect(instance.fatal_error?).to be_falsey
64
+ context 'with error set as non fatal' do
65
+ before { LightServiceExt.configure { |c| c.non_fatal_error_classes = [ArgumentError] } }
66
+
67
+ it 'returns false' do
68
+ expect(instance.fatal_error?).to be_falsey
69
+ end
70
+
71
+ context 'with fatal passed as arg' do
72
+ let(:fatal) { true }
73
+
74
+ it 'returns true' do
75
+ expect(instance.fatal_error?).to be_truthy
76
+ end
77
+ end
68
78
  end
69
79
  end
70
80
  end
@@ -87,7 +97,7 @@ RSpec.describe LightServiceExt::ErrorInfo do
87
97
  subject(:hash) { instance.to_h }
88
98
 
89
99
  it 'returns custom key value pairs' do
90
- expect(hash.keys).to match_array(%i[type message exception backtrace error fatal_error?])
100
+ expect(hash.keys).to match_array(%i[type message exception backtrace error errors fatal_error?])
91
101
 
92
102
  expect(hash[:type]).to eql(error.class.name)
93
103
  expect(hash[:message]).to eql(message)
@@ -95,12 +105,13 @@ RSpec.describe LightServiceExt::ErrorInfo do
95
105
  expect(hash[:backtrace]).to eql(backtrace.join)
96
106
  expect(hash[:error]).to eql(error)
97
107
  expect(hash[:fatal_error?]).to be_truthy
108
+ expect(hash[:errors]).to eql({ base: "some-error" })
98
109
  end
99
110
 
100
111
  context 'with non fatal error' do
101
112
  let(:error) { ArgumentError.new(message) }
102
113
 
103
- before { error_info_class.non_fatal_errors = [ArgumentError] }
114
+ before { LightServiceExt.configure { |c| c.non_fatal_error_classes = [ArgumentError] } }
104
115
 
105
116
  it 'returns non fatal error' do
106
117
  expect(hash[:fatal_error?]).to be_falsey
@@ -0,0 +1,62 @@
1
+ module LightServiceExt
2
+ RSpec.describe WithErrorHandler do
3
+ unless defined? Rails
4
+ module Rails
5
+ end
6
+ end
7
+
8
+ unless defined? Rails::ActiveRecordError
9
+ module Rails
10
+ class ActiveRecordError < StandardError
11
+ def model; end
12
+ end
13
+ end
14
+ end
15
+
16
+ let(:implementor_class) do
17
+ Class.new do
18
+ extend WithErrorHandler
19
+ end
20
+ end
21
+
22
+ let(:key) { :key }
23
+ let(:key_error) { 'invalid' }
24
+ let(:messages) { { key => [key_error] } }
25
+ let(:error_message) { 'some-error' }
26
+ let(:errors) { OpenStruct.new(messages: messages) }
27
+ let(:model) { OpenStruct.new(errors: errors) }
28
+ let(:results_ctx_proc) { -> { ApplicationContext.make_with_defaults } }
29
+ let(:ctx) { ApplicationContext.make_with_defaults }
30
+ let(:error) { Rails::ActiveRecordError.new(error_message) }
31
+
32
+ before { allow(LightServiceExt.config.logger).to receive(:error) }
33
+
34
+ describe '.with_error_handler' do
35
+ subject(:errors_handled_ctx) do
36
+ implementor_class.with_error_handler(ctx: ctx, &results_ctx_proc)
37
+ end
38
+
39
+ context 'with active record error' do
40
+ let(:results_ctx_proc) { -> { raise error } }
41
+
42
+ context 'with error including model' do
43
+ before { allow(error).to receive(:model) { model } }
44
+
45
+ it 'adds model errors' do
46
+ expect(errors_handled_ctx.failure?).to be_truthy
47
+ expect(errors_handled_ctx.errors).to eql({ key => key_error })
48
+ expect(errors_handled_ctx.internal_only[:error_info]).to be_an_instance_of(ErrorInfo)
49
+ expect(LightServiceExt.config.logger).to have_received(:error)
50
+ end
51
+ end
52
+
53
+ it 'adds errors to context' do
54
+ expect(errors_handled_ctx.failure?).to be_truthy
55
+ expect(errors_handled_ctx.errors).to eql({ base: error_message })
56
+ expect(errors_handled_ctx.internal_only[:error_info]).to be_an_instance_of(ErrorInfo)
57
+ expect(LightServiceExt.config.logger).to have_received(:error)
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -2,6 +2,72 @@
2
2
 
3
3
  RSpec.describe LightServiceExt do
4
4
  it "has a version number" do
5
- expect(LightServiceExt::VERSION).not_to be_nil
5
+ expect(described_class::VERSION).not_to be_nil
6
+ end
7
+
8
+ describe '.configure' do
9
+ subject(:config) { described_class.configuration }
10
+
11
+ let(:error_class) { ArgumentError }
12
+ let(:default_error_class) { EncodingError }
13
+
14
+ after do
15
+ # rubocop:disable Style/ClassVars
16
+ described_class.class_variable_set(:@@configuration, described_class::Configuration.new)
17
+ # rubocop:enable Style/ClassVars
18
+ end
19
+
20
+ context 'with non fatal error classes' do
21
+ before do
22
+ described_class.configure do |config|
23
+ config.non_fatal_error_classes = [error_class]
24
+ end
25
+ end
26
+
27
+ describe '#non_fatal_error_classes' do
28
+ it 'returns set fatal error classes' do
29
+ expect(config.non_fatal_error_classes).to match_array([error_class])
30
+ end
31
+ end
32
+ end
33
+
34
+ context 'with default non fatal errors' do
35
+ before do
36
+ described_class.configure do |config|
37
+ config.default_non_fatal_error_classes = [default_error_class]
38
+ end
39
+ end
40
+
41
+ describe '#default_non_fatal_error_classes' do
42
+ it 'returns set non fatal error classes' do
43
+ expect(config.default_non_fatal_error_classes).to match_array([default_error_class])
44
+ end
45
+ end
46
+ end
47
+
48
+ context 'with default and non default non fatal errors' do
49
+ before do
50
+ described_class.configure do |config|
51
+ config.non_fatal_error_classes = [error_class, default_error_class, nil]
52
+ config.default_non_fatal_error_classes = [default_error_class]
53
+ end
54
+ end
55
+
56
+ describe '#non_fatal_errors' do
57
+ it 'returns non duplicate error classes' do
58
+ expect(config.non_fatal_errors).to match_array([error_class, default_error_class].map(&:to_s))
59
+ end
60
+ end
61
+ end
62
+
63
+ describe '#allow_raise_on_failure' do
64
+ context 'with allow raise on failure unset' do
65
+ it 'returns true' do
66
+ described_class.configure { |config| config.allow_raise_on_failure = false }
67
+
68
+ expect(config.allow_raise_on_failure?).to be_falsey
69
+ end
70
+ end
71
+ end
6
72
  end
7
73
  end
data/spec/spec_helper.rb CHANGED
@@ -1,13 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require File.join(__dir__, "..", 'dev', 'setup')
4
+ require Pathname.new(__dir__).realpath.join('coverage_helper').to_s
4
5
 
5
- require 'coverage_helper'
6
6
  require 'light-service/testing'
7
7
 
8
- require "light-service-ext"
9
-
10
8
  RSpec.configure do |config|
9
+ config.before do
10
+ # rubocop:disable Style/ClassVars
11
+ LightServiceExt.class_variable_set(:@@configuration, LightServiceExt::Configuration.new)
12
+ # rubocop:enable Style/ClassVars
13
+ end
14
+
11
15
  # Enable flags like --only-failures and --next-failure
12
16
  config.example_status_persistence_file_path = ".rspec_status"
13
17
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: light-service-ext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Desmond O'Leary
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-15 00:00:00.000000000 Z
11
+ date: 2023-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: light-service
@@ -78,6 +78,20 @@ dependencies:
78
78
  - - ">="
79
79
  - !ruby/object:Gem::Version
80
80
  version: 2.6.3
81
+ - !ruby/object:Gem::Dependency
82
+ name: activesupport
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '5'
88
+ type: :runtime
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '5'
81
95
  - !ruby/object:Gem::Dependency
82
96
  name: rake
83
97
  requirement: !ruby/object:Gem::Requirement
@@ -164,24 +178,28 @@ files:
164
178
  - lib/light-service-ext/application_organizer.rb
165
179
  - lib/light-service-ext/application_validator_action.rb
166
180
  - lib/light-service-ext/around_action_execute_extension.rb
181
+ - lib/light-service-ext/configuration.rb
167
182
  - lib/light-service-ext/constants.rb
168
183
  - lib/light-service-ext/context_error.rb
169
184
  - lib/light-service-ext/error_info.rb
170
185
  - lib/light-service-ext/regex.rb
171
186
  - lib/light-service-ext/version.rb
187
+ - lib/light-service-ext/with_error_handler.rb
172
188
  - light-service-ext.gemspec
173
189
  - sig/light_service_ext.rbs
174
190
  - spec/coverage_helper.rb
175
- - spec/light_service_ext/all_actions_complete_action_spec.rb
176
- - spec/light_service_ext/application_action_spec.rb
177
- - spec/light_service_ext/application_context_spec.rb
178
- - spec/light_service_ext/application_contract_spec.rb
179
- - spec/light_service_ext/application_organizer_spec.rb
180
- - spec/light_service_ext/application_validator_action_spec.rb
181
- - spec/light_service_ext/around_action_execute_extension_spec.rb
182
- - spec/light_service_ext/context_error_spec.rb
183
- - spec/light_service_ext/error_info_spec.rb
184
- - spec/light_service_ext/regex_spec.rb
191
+ - spec/light-service-ext/all_actions_complete_action_spec.rb
192
+ - spec/light-service-ext/application_action_spec.rb
193
+ - spec/light-service-ext/application_context_spec.rb
194
+ - spec/light-service-ext/application_contract_spec.rb
195
+ - spec/light-service-ext/application_organizer_spec.rb
196
+ - spec/light-service-ext/application_validator_action_spec.rb
197
+ - spec/light-service-ext/around_action_execute_extension_spec.rb
198
+ - spec/light-service-ext/configuration_spec.rb
199
+ - spec/light-service-ext/context_error_spec.rb
200
+ - spec/light-service-ext/error_info_spec.rb
201
+ - spec/light-service-ext/regex_spec.rb
202
+ - spec/light-service-ext/with_error_handler_spec.rb
185
203
  - spec/light_service_ext_spec.rb
186
204
  - spec/spec_helper.rb
187
205
  homepage: https://github.com/omnitech-solutions/light-service-ext
@@ -212,15 +230,17 @@ specification_version: 4
212
230
  summary: Extends light-service with opinionated functionality
213
231
  test_files:
214
232
  - spec/coverage_helper.rb
215
- - spec/light_service_ext/all_actions_complete_action_spec.rb
216
- - spec/light_service_ext/application_action_spec.rb
217
- - spec/light_service_ext/application_context_spec.rb
218
- - spec/light_service_ext/application_contract_spec.rb
219
- - spec/light_service_ext/application_organizer_spec.rb
220
- - spec/light_service_ext/application_validator_action_spec.rb
221
- - spec/light_service_ext/around_action_execute_extension_spec.rb
222
- - spec/light_service_ext/context_error_spec.rb
223
- - spec/light_service_ext/error_info_spec.rb
224
- - spec/light_service_ext/regex_spec.rb
233
+ - spec/light-service-ext/all_actions_complete_action_spec.rb
234
+ - spec/light-service-ext/application_action_spec.rb
235
+ - spec/light-service-ext/application_context_spec.rb
236
+ - spec/light-service-ext/application_contract_spec.rb
237
+ - spec/light-service-ext/application_organizer_spec.rb
238
+ - spec/light-service-ext/application_validator_action_spec.rb
239
+ - spec/light-service-ext/around_action_execute_extension_spec.rb
240
+ - spec/light-service-ext/configuration_spec.rb
241
+ - spec/light-service-ext/context_error_spec.rb
242
+ - spec/light-service-ext/error_info_spec.rb
243
+ - spec/light-service-ext/regex_spec.rb
244
+ - spec/light-service-ext/with_error_handler_spec.rb
225
245
  - spec/light_service_ext_spec.rb
226
246
  - spec/spec_helper.rb
@@ -1,77 +0,0 @@
1
- module LightServiceExt
2
- RSpec.describe ApplicationAction do
3
- FakeApplicationAction = Class.new(described_class) do
4
- executed do |context|
5
- value = context.dig(:input, :callback).call
6
- add_params(context, value: value)
7
- end
8
- end
9
-
10
- let(:organizer_class) do
11
- Class.new(ApplicationOrganizer) do
12
- def self.steps
13
- [FakeApplicationAction]
14
- end
15
- end
16
- end
17
-
18
- let(:value) { 'some-value' }
19
- let(:callback) { -> { value } }
20
- let(:input) { { callback: callback } }
21
- let(:ctx) do
22
- LightService::Testing::ContextFactory
23
- .make_from(organizer_class)
24
- .for(FakeApplicationAction)
25
- .with(callback: callback)
26
- end
27
-
28
- subject(:context) do
29
- FakeApplicationAction.execute(ctx)
30
- end
31
-
32
- it 'adds value returned by callback to params' do
33
- expect(context.keys).to include(:input, :errors, :params)
34
-
35
- expect(context[:params]).to eql({ value: value })
36
- end
37
-
38
- describe '.add_params' do
39
- let(:params) { { key: 'some-value' } }
40
- let(:ctx) { ApplicationContext.make_with_defaults }
41
-
42
- subject(:params_added) { described_class.add_params(ctx, **params) }
43
-
44
- it 'adds key value pairs to context params' do
45
- params_added
46
-
47
- expect(ctx[:params].keys).to include(:key)
48
- end
49
- end
50
-
51
- describe '.add_errors' do
52
- let(:ctx) { ApplicationContext.make_with_defaults }
53
-
54
- subject(:errors_added) { described_class.add_errors(ctx, **errors) }
55
-
56
- context 'without errors' do
57
- let(:errors) { {} }
58
-
59
- it 'does not raise error' do
60
- expect { errors_added }.not_to raise_error
61
-
62
- expect(ctx[:errors]).to be_empty
63
- end
64
- end
65
-
66
- context 'with errors' do
67
- let(:errors) { { key: 'not-found' } }
68
-
69
- it 'raises jump when failed error and adds errors to context' do
70
- expect { errors_added }.to raise_error UncaughtThrowError, 'uncaught throw :jump_when_failed'
71
-
72
- expect(ctx[:errors].keys).to include(:key)
73
- end
74
- end
75
- end
76
- end
77
- end