salestation 5.0.0 → 5.1.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 +4 -4
- data/.gitignore +1 -0
- data/lib/salestation/app/input_verification.rb +1 -1
- data/lib/salestation/rspec/glia_input_validation_error_matcher.rb +46 -10
- data/lib/salestation/rspec.rb +17 -0
- data/salestation.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43663c5f6d78d7238e66e9ac88a06a49facfcaf45a329534e44e20891ea1baa9
|
4
|
+
data.tar.gz: 97661dd29a53ab956cbe0c78522b382d052bd4c6f339208fe126f7d3c51f8526
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee4cf2f592d41548e187277789ec6d3484748dc7cc152f3a9b4e4b63b438314e5fe96ab3aeb92dbd4729a485b4d9e73b518904459309b19f3da7a507595100ce
|
7
|
+
data.tar.gz: 22a1c5415ded67ebc22c5f67ef6332706571a156000aac7e5195101c73be14dc950b5f208fb24b19e27c94b70c3c854dc8a5da485a01b030d578e9ccaac92c57
|
data/.gitignore
CHANGED
@@ -18,7 +18,7 @@ module Salestation
|
|
18
18
|
Errors::InvalidInput.new(errors: result.errors, hints: result.hints)
|
19
19
|
)
|
20
20
|
end
|
21
|
-
elsif dry_validation_version
|
21
|
+
elsif dry_validation_version < Gem::Version.new('2.0')
|
22
22
|
if result.success?
|
23
23
|
request.replace_input(input)
|
24
24
|
else
|
@@ -12,37 +12,73 @@ module Salestation
|
|
12
12
|
def initialize
|
13
13
|
@fields = []
|
14
14
|
@field_error_types = {}
|
15
|
+
@field_error_messages = {}
|
15
16
|
end
|
16
17
|
|
17
|
-
def on(
|
18
|
-
@fields <<
|
18
|
+
def on(*nested_fields)
|
19
|
+
@fields << nested_fields
|
19
20
|
self
|
20
21
|
end
|
21
22
|
|
22
23
|
def with_type(*types)
|
23
|
-
@field_error_types[@fields.last] = types
|
24
|
+
@field_error_types[field_to_key(@fields.last)] = types
|
25
|
+
self
|
26
|
+
end
|
27
|
+
|
28
|
+
def with_message(*messages)
|
29
|
+
@field_error_messages[field_to_key(@fields.last)] = messages
|
24
30
|
self
|
25
31
|
end
|
26
32
|
|
27
33
|
def matches?(actual)
|
28
34
|
@fields.all? do |field|
|
29
|
-
check_field_exists(
|
30
|
-
check_field_error_types(field, actual)
|
35
|
+
check_field_exists(actual, *field) &&
|
36
|
+
check_field_error_types(field, actual) &&
|
37
|
+
check_field_error_messages(field, actual)
|
31
38
|
end
|
32
39
|
end
|
33
40
|
|
34
41
|
private
|
35
42
|
|
36
|
-
def check_field_exists(field,
|
37
|
-
actual[:error_details].key?(field)
|
43
|
+
def check_field_exists(actual, field, *nested_fields)
|
44
|
+
actual[:error_details].key?(field) &&
|
45
|
+
(
|
46
|
+
nested_fields.empty? ||
|
47
|
+
actual[:error_details][field].any? do |nested_hash|
|
48
|
+
check_field_exists(nested_hash, *nested_fields)
|
49
|
+
end
|
50
|
+
)
|
38
51
|
end
|
39
52
|
|
40
53
|
def check_field_error_types(field, actual)
|
41
|
-
return true unless @field_error_types[field]
|
54
|
+
return true unless @field_error_types[field_to_key(field)]
|
55
|
+
|
56
|
+
actual_error_types = fetch_field_attribute_nested(actual, :type, *field)
|
57
|
+
(@field_error_types[field_to_key(field)] - actual_error_types).empty?
|
58
|
+
end
|
59
|
+
|
60
|
+
def check_field_error_messages(field, actual)
|
61
|
+
return true unless @field_error_messages[field_to_key(field)]
|
42
62
|
|
43
|
-
|
63
|
+
actual_error_messages = fetch_field_attribute_nested(actual, :message, *field)
|
64
|
+
(@field_error_messages[field_to_key(field)] - actual_error_messages).empty?
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
def fetch_field_attribute_nested(actual, attribute, field, *nested_fields)
|
69
|
+
if nested_fields.empty?
|
70
|
+
actual[:error_details].fetch(field).map { |f| f.fetch(attribute) }
|
71
|
+
else
|
72
|
+
actual[:error_details][field]
|
73
|
+
.lazy
|
74
|
+
.map { |error_hash| fetch_field_attribute_nested(error_hash, attribute, *nested_fields) }
|
75
|
+
.reject(&:nil?)
|
76
|
+
.first
|
77
|
+
end
|
78
|
+
end
|
44
79
|
|
45
|
-
|
80
|
+
def field_to_key(fields)
|
81
|
+
fields.join('->').to_sym
|
46
82
|
end
|
47
83
|
end
|
48
84
|
end
|
data/lib/salestation/rspec.rb
CHANGED
@@ -44,6 +44,23 @@ module Salestation
|
|
44
44
|
# .on(:phone_number).with_type(Glia::Errors::INVALID_FORMAT_ERROR)
|
45
45
|
# )
|
46
46
|
#
|
47
|
+
# also has support for nested errors:
|
48
|
+
# nesting can be represented by calling `on` method with multiple arguments, for example when
|
49
|
+
# you have a hash like
|
50
|
+
# {
|
51
|
+
# nested: {
|
52
|
+
# name: ''
|
53
|
+
# }
|
54
|
+
# }
|
55
|
+
# Then you can call it like glia_input_validation_error.on(:nested, :name)
|
56
|
+
#
|
57
|
+
# expect(result).to be_failure
|
58
|
+
# .with_invalid_input
|
59
|
+
# .containing(
|
60
|
+
# glia_input_validation_error
|
61
|
+
# .on(:nested, :name).with_type(Glia::Errors::INVALID_VALUE_ERROR)
|
62
|
+
# )
|
63
|
+
#
|
47
64
|
# Everything after be_failure is optional. You could also use `.containing`
|
48
65
|
# multiple times like this:
|
49
66
|
#
|
data/salestation.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: salestation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.
|
4
|
+
version: 5.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Glia TechMovers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-08-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|