client-api 0.2.0 → 0.2.1
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/lib/client-api/validator.rb +18 -4
- data/lib/client-api/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b3b35e20afa816b35cd7365835102d7f6cc8c03ef3c04b32c782fa2068de357
|
4
|
+
data.tar.gz: a7172042a889d3015d49873127c26e7a4511b0aa41e2e98220d0b6d909807569
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da607fde080b2b1cf7dabb8b109ef3eeb2a6d809742acf41b15bb6aca7a017d927e205d421b3aa8bd80e96df54268e024927d28ad33ff479093f7919b936ca60
|
7
|
+
data.tar.gz: a3121f16f643cb0663f4b16d82cdcb54ce070bc5dd147d9b3de6e8e12b741f7965cb14e55b0cb40f698cbd88f6e80a4c2dbd8cea2a175ed1327aea5f5356de34
|
data/lib/client-api/validator.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "json-schema"
|
2
|
+
require "byebug"
|
2
3
|
|
3
4
|
module ClientApi
|
4
5
|
|
@@ -7,7 +8,7 @@ module ClientApi
|
|
7
8
|
raise_error('key (or) operator is not given!') if data[:key].nil? && data[:operator].nil?
|
8
9
|
raise_error('value (or) type is not given!') if data[:value].nil? && data[:type].nil?
|
9
10
|
|
10
|
-
@resp = res
|
11
|
+
@resp = JSON.parse(res.to_json)
|
11
12
|
key = data[:key].split("->")
|
12
13
|
|
13
14
|
key.map do |method|
|
@@ -27,7 +28,7 @@ module ClientApi
|
|
27
28
|
# datatype validation
|
28
29
|
if (type == 'boolean') || (type == 'bool') && value.nil?
|
29
30
|
expect(%w[TrueClass, FalseClass].any? {|bool| bool.include? @resp.class.to_s}).to eq(true), lambda {"[key]: \"#{data[:key]}\"".blue + "\n datatype shouldn't be \n[type]: \"#{data[:type]}\"\n"}
|
30
|
-
|
31
|
+
elsif (type != nil) && (value != nil)
|
31
32
|
expect(datatype(type, value)).to eq(@resp.class), lambda {"[key]: \"#{data[:key]}\"".blue + "\n datatype shouldn't be \n[type]: \"#{data[:type]}\"\n"}
|
32
33
|
end
|
33
34
|
|
@@ -38,9 +39,23 @@ module ClientApi
|
|
38
39
|
# datatype validation
|
39
40
|
if (type == 'boolean') || (type == 'bool') && value.nil?
|
40
41
|
expect(%w[TrueClass, FalseClass].any? {|bool| bool.include? @resp.class.to_s}).not_to eq(true), lambda {"[key]: \"#{data[:key]}\"".blue + "\n datatype shouldn't be \n[type]: \"#{data[:type]}\"\n"}
|
41
|
-
|
42
|
+
elsif (type != nil) && (value != nil)
|
42
43
|
expect(datatype(type, value)).not_to eq(@resp.class), lambda {"[key]: \"#{data[:key]}\"".blue + "\n datatype shouldn't be \n[type]: \"#{data[:type]}\"\n"}
|
43
44
|
end
|
45
|
+
|
46
|
+
when '>', '>=', '<', '<=', 'greater than', 'greater than or equal to', 'less than', 'less than or equal to', 'lesser than', 'lesser than or equal to'
|
47
|
+
|
48
|
+
message = 'is not greater than (or) equal to' if operator == '>=' || operator == 'greater than or equal to'
|
49
|
+
message = 'is not greater than' if operator == '>' || operator == 'greater than'
|
50
|
+
message = 'is not lesser than' if operator == '<=' || operator == 'less than or equal to'
|
51
|
+
message = 'is not lesser than (or) equal to' if operator == '<' || operator == 'less than' || operator == 'lesser than'
|
52
|
+
|
53
|
+
# value validation
|
54
|
+
expect(@resp.to_i.public_send(operator, value)).to eq(true), "[key]: \"#{data[:key]}\"".blue + "\n #{message} \n[value]: \"#{data[:value]}\"\n" if value != nil
|
55
|
+
|
56
|
+
# datatype validation
|
57
|
+
expect(datatype(type, value)).to eq(@resp.class), lambda {"[key]: \"#{data[:key]}\"".blue + "\n datatype shouldn't be \n[type]: \"#{data[:type]}\"\n"} if type != nil
|
58
|
+
|
44
59
|
else
|
45
60
|
raise_error('operator not matching')
|
46
61
|
end
|
@@ -149,7 +164,6 @@ module ClientApi
|
|
149
164
|
end
|
150
165
|
|
151
166
|
if @overall.count(true) == value.count
|
152
|
-
return
|
153
167
|
else
|
154
168
|
expect(value).to eq(@resp)
|
155
169
|
end
|
data/lib/client-api/version.rb
CHANGED