client-api 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d151a6541ddc08498bd506b21fd8578a436d2b2745aa222e962197cd301079eb
4
- data.tar.gz: c8554dae87838761e44411c182621cb00aeb98845bf78d3bcb087848005dfe8a
3
+ metadata.gz: 97f401edf4a282e909f6762a905f1fd61e004d186009a1a87f3739852485738e
4
+ data.tar.gz: 931f5764aaacc5ce10a4194a53fccc7904d2a02e7fec52fbcac4eb602c899a0b
5
5
  SHA512:
6
- metadata.gz: 459b30e070200f9770b9de1f510969d83a90730429d18e71df2c9f3858d64761b36ff16d9146adad5a7058dbd25189a898acaef8f338ee3b2245295284e8a1a6
7
- data.tar.gz: b2b6943c386cd7985ad2794fd1bce6c1794001445dd9a910af56befe6862d2532296ae847764c04357a45849635bde07569384e095e7743e974b22e193655191
6
+ metadata.gz: b439b3185f49058ba3bd0cc305b48ad17c89650ff1c61d85af5512ef4a6ae4e711355f1d8385f80974e4bc5fb19e7703e9fb255dc01f2cfc2345c024b32c6f68
7
+ data.tar.gz: 6c272bd4a6db982e27c692a4b0d9f23c5a965e99c9e3d67b262f1ac51d2a348b7c17e67c16992d1e3c8f84646932bb4e8a6bb275f8e599bbb48baa1d25ce82bc
@@ -4,9 +4,9 @@ module ClientApi
4
4
 
5
5
  def validate(res, *options)
6
6
  options.map do |data|
7
- raise('key is not given!') if data[:key].nil?
8
- raise('operator is not given!') if data[:operator].nil?
9
- raise('value / type / size is not given!') if data[:value].nil? && data[:type].nil? && data[:size].nil?
7
+ raise('"key": ""'.green + ' field is missing'.red) if data[:key].nil?
8
+ raise('"operator":'.green + ' or'.red + ' "size":'.green + ' or'.red + ' "empty":'.green + ' field is not given!'.red) if data[:operator].nil? && data[:size].nil? && data[:empty].nil?
9
+ raise('"value":'.green + ' or'.red + ' "size":'.green + ' or'.red + ' "type":'.green + ' field is not given!'.red) if data[:value].nil? && data[:type].nil? && data[:size].nil? if data[:operator] != nil
10
10
 
11
11
  @resp = JSON.parse(res.to_json)
12
12
  key = data[:key].split("->")
@@ -17,111 +17,163 @@ module ClientApi
17
17
  end
18
18
 
19
19
  value ||= data[:value]
20
- operator = data[:operator]
20
+ operator ||= data[:operator]
21
21
  type ||= data[:type]
22
22
  size ||= data[:size]
23
+ empty ||= data[:empty]
24
+
25
+ if operator != nil
26
+ case operator
27
+ when '=', '==', 'eql', 'eql?', 'equal', 'equal?'
28
+ # value validation
29
+ expect(value).to eq(@resp), lambda {"[key]: \"#{data[:key]}\"".blue + "\n didn't match \n[value]: \"#{data[:value]}\"\n"} if value != nil
30
+
31
+ # datatype validation
32
+ if (type == 'boolean') || (type == 'bool')
33
+ 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"}
34
+ elsif ((type != 'boolean') || (type != 'bool')) && (type != nil)
35
+ expect(datatype(type, value)).to eq(@resp.class), lambda {"[key]: \"#{data[:key]}\"".blue + "\n datatype shouldn't be \n[type]: \"#{data[:type]}\"\n"}
36
+ end
23
37
 
24
- case operator
25
- when '=', '==', 'eql', 'eql?', 'equal', 'equal?'
26
- # value validation
27
- expect(value).to eq(@resp), lambda {"[key]: \"#{data[:key]}\"".blue + "\n didn't match \n[value]: \"#{data[:value]}\"\n"} if value != nil
28
-
29
- # datatype validation
30
- if (type == 'boolean') || (type == 'bool')
31
- 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"}
32
- elsif ((type != 'boolean') || (type != 'bool')) && (type != nil)
33
- expect(datatype(type, value)).to eq(@resp.class), lambda {"[key]: \"#{data[:key]}\"".blue + "\n datatype shouldn't be \n[type]: \"#{data[:type]}\"\n"}
34
- end
38
+ # size validation
39
+ validate_size(size, data) if size != nil
35
40
 
36
- if size != nil
37
- begin
38
- expect(size).to eq(@resp.count), lambda {"[key]: \"#{data[:key]}\"".blue + "\n" + "size didn't match" + "\n\n" + "[ actual size ]: #{@resp.count}" + "\n" + "[expected size]: #{size}".green}
39
- rescue NoMethodError
40
- expect(size).to eq(0), lambda {"[key]: \"#{data[:key]}\"".blue + "\n" + "size didn't match" + "\n\n" + "[ actual size ]: 0" + "\n" + "[expected size]: #{size}".green}
41
- end
42
- end
41
+ # is empty validation
42
+ validate_empty(empty, data) if empty != nil
43
43
 
44
- when '!', '!=', '!eql', '!eql?', 'not eql', 'not equal', '!equal?'
45
- # value validation
46
- expect(value).not_to eq(@resp), lambda {"[key]: \"#{data[:key]}\"".blue + "\n didn't match \n[value]: \"#{data[:value]}\"\n"} if value != nil
44
+ when '!', '!=', '!eql', '!eql?', 'not eql', 'not equal', '!equal?'
45
+ # value validation
46
+ expect(value).not_to eq(@resp), lambda {"[key]: \"#{data[:key]}\"".blue + "\n didn't match \n[value]: \"#{data[:value]}\"\n"} if value != nil
47
47
 
48
- # datatype validation
49
- if (type == 'boolean') || (type == 'bool')
50
- 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"}
51
- elsif ((type != 'boolean') || (type != 'bool')) && (type != nil)
52
- expect(datatype(type, value)).not_to eq(@resp.class), lambda {"[key]: \"#{data[:key]}\"".blue + "\n datatype shouldn't be \n[type]: \"#{data[:type]}\"\n"}
53
- end
48
+ # datatype validation
49
+ if (type == 'boolean') || (type == 'bool')
50
+ 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"}
51
+ elsif ((type != 'boolean') || (type != 'bool')) && (type != nil)
52
+ expect(datatype(type, value)).not_to eq(@resp.class), lambda {"[key]: \"#{data[:key]}\"".blue + "\n datatype shouldn't be \n[type]: \"#{data[:type]}\"\n"}
53
+ end
54
54
 
55
- if size != nil
56
- begin
57
- expect(size).not_to eq(@resp.count), lambda {"[key]: \"#{data[:key]}\"".blue + "\n" + "size shouldn't match" + "\n\n" + "[ actual size ]: #{@resp.count}" + "\n" + "[size not expected]: #{size}".green}
58
- rescue NoMethodError
59
- expect(size).not_to eq(0), lambda {"[key]: \"#{data[:key]}\"".blue + "\n" + "size shouldn't match" + "\n\n" + "[ actual size ]: 0" + "\n" + "[size not expected]: #{size}".green}
55
+ # size validation
56
+ if size != nil
57
+ begin
58
+ expect(size).not_to eq(@resp.count), lambda {"[key]: \"#{data[:key]}\"".blue + "\n" + "size shouldn't match" + "\n\n" + "[ actual size ]: #{@resp.count}" + "\n" + "[size not expected]: #{size}".green}
59
+ rescue NoMethodError
60
+ expect(size).not_to eq(0), lambda {"[key]: \"#{data[:key]}\"".blue + "\n" + "size shouldn't match" + "\n\n" + "[ actual size ]: 0" + "\n" + "[size not expected]: #{size}".green}
61
+ rescue ArgumentError
62
+ expect(size).not_to eq(0), lambda {"[key]: \"#{data[:key]}\"".blue + "\n" + "size shouldn't match" + "\n\n" + "[ actual size ]: 0" + "\n" + "[size not expected]: #{size}".green}
63
+ end
60
64
  end
61
- end
62
65
 
63
- when '>', '>=', '<', '<=', 'greater than', 'greater than or equal to', 'less than', 'less than or equal to', 'lesser than', 'lesser than or equal to'
64
- message = 'is not greater than (or) equal to' if operator == '>=' || operator == 'greater than or equal to'
65
- message = 'is not greater than' if operator == '>' || operator == 'greater than'
66
- message = 'is not lesser than (or) equal to' if operator == '<=' || operator == 'less than or equal to'
67
- message = 'is not lesser than' if operator == '<' || operator == 'less than' || operator == 'lesser than'
66
+ # is empty validation
67
+ validate_empty(empty, data) if empty != nil
68
+
69
+ when '>', '>=', '<', '<=', 'greater than', 'greater than or equal to', 'less than', 'less than or equal to', 'lesser than', 'lesser than or equal to'
70
+ message = 'is not greater than (or) equal to' if operator == '>=' || operator == 'greater than or equal to'
71
+ message = 'is not greater than' if operator == '>' || operator == 'greater than'
72
+ message = 'is not lesser than (or) equal to' if operator == '<=' || operator == 'less than or equal to'
73
+ message = 'is not lesser than' if operator == '<' || operator == 'less than' || operator == 'lesser than'
74
+
75
+ # value validation
76
+ 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
77
+
78
+ # datatype validation
79
+ 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
80
+
81
+ # size validation
82
+ if size != nil
83
+ begin
84
+ expect(@resp.count.to_i.public_send(operator, size)).to eq(true), lambda {"[key]: \"#{data[:key]}\"".blue + "\n" + "#{message} #{size}" + "\n\n" + "[ actual size ]: #{@resp.count}" + "\n" + "expected size to be #{operator} #{size}".green}
85
+ rescue NoMethodError
86
+ expect(0.public_send(operator, size)).to eq(true), lambda {"[key]: \"#{data[:key]}\"".blue + "\n" + "#{message} #{size}" + "\n\n" + "[ actual size ]: 0" + "\n" + "expected size to be #{operator} #{size}".green}
87
+ rescue ArgumentError
88
+ expect(0.public_send(operator, size)).to eq(true), lambda {"[key]: \"#{data[:key]}\"".blue + "\n" + "#{message} #{size}" + "\n\n" + "[ actual size ]: 0" + "\n" + "expected size to be #{operator} #{size}".green}
89
+ end
90
+ end
68
91
 
69
- # value validation
70
- 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
92
+ # is empty validation
93
+ validate_empty(empty, data) if empty != nil
71
94
 
72
- # datatype validation
73
- 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
95
+ when 'contains', 'has', 'contains?', 'has?', 'include', 'include?'
96
+ # value validation
97
+ expect(@resp.to_s).to include(value.to_s), lambda {"[key]: \"#{data[:key]} => #{@resp}\"".blue + "\n not contains \n[value]: \"#{data[:value]}\"\n"} if value != nil
74
98
 
75
- if size != nil
76
- begin
77
- expect(@resp.count.to_i.public_send(operator, size)).to eq(true), lambda {"[key]: \"#{data[:key]}\"".blue + "\n" + "#{message} #{size}" + "\n\n" + "[ actual size ]: #{@resp.count}" + "\n" + "expected size to be #{operator} #{size}".green}
78
- rescue NoMethodError
79
- expect(0.public_send(operator, size)).to eq(true), lambda {"[key]: \"#{data[:key]}\"".blue + "\n" + "#{message} #{size}" + "\n\n" + "[ actual size ]: 0" + "\n" + "expected size to be #{operator} #{size}".green}
99
+ # datatype validation
100
+ if (type == 'boolean') || (type == 'bool')
101
+ 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"}
102
+ elsif ((type != 'boolean') || (type != 'bool')) && (type != nil)
103
+ expect(datatype(type, value)).to eq(@resp.class), lambda {"[key]: \"#{data[:key]}\"".blue + "\n datatype shouldn't be \n[type]: \"#{data[:type]}\"\n"}
104
+ end
105
+
106
+ # size validation
107
+ if size != nil
108
+ begin
109
+ expect(@resp.count.to_s).to include(size.to_s), lambda {"[key]: \"#{data[:key]} => #{@resp}\"".blue + "\n"+ "size not contains #{size}"+ "\n\n" + "[ actual size ]: #{@resp.count}" + "\n" + "expected size to contain: #{size}".green}
110
+ rescue NoMethodError
111
+ expect(0.to_s).to include(size.to_s), lambda {"[key]: \"#{data[:key]} => #{@resp}\"".blue + "\n"+ "size not contains #{size}"+ "\n\n" + "[ actual size ]: 0" + "\n" + "expected size to contain: #{size}".green}
112
+ rescue ArgumentError
113
+ expect(0.to_s).to include(size.to_s), lambda {"[key]: \"#{data[:key]} => #{@resp}\"".blue + "\n"+ "size not contains #{size}"+ "\n\n" + "[ actual size ]: 0" + "\n" + "expected size to contain: #{size}".green}
114
+ end
80
115
  end
81
- end
82
116
 
83
- when 'contains', 'has', 'contains?', 'has?', 'include', 'include?'
84
- # value validation
85
- expect(@resp.to_s).to include(value.to_s), lambda {"[key]: \"#{data[:key]} => #{@resp}\"".blue + "\n not contains \n[value]: \"#{data[:value]}\"\n"} if value != nil
117
+ # is empty validation
118
+ validate_empty(empty, data) if empty != nil
86
119
 
87
- # datatype validation
88
- if (type == 'boolean') || (type == 'bool')
89
- 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"}
90
- elsif ((type != 'boolean') || (type != 'bool')) && (type != nil)
91
- expect(datatype(type, value)).to eq(@resp.class), lambda {"[key]: \"#{data[:key]}\"".blue + "\n datatype shouldn't be \n[type]: \"#{data[:type]}\"\n"}
92
- end
120
+ when 'not contains', '!contains', 'not include', '!include'
121
+ # value validation
122
+ expect(@resp.to_s).not_to include(value.to_s), lambda {"[key]: \"#{data[:key]} => #{@resp}\"".blue + "\n should not contain \n[value]: \"#{data[:value]}\"\n"} if value != nil
93
123
 
94
- if size != nil
95
- begin
96
- expect(@resp.count.to_s).to include(size.to_s), lambda {"[key]: \"#{data[:key]} => #{@resp}\"".blue + "\n"+ "size not contains #{size}"+ "\n\n" + "[ actual size ]: #{@resp.count}" + "\n" + "expected size to contain: #{size}".green}
97
- rescue NoMethodError
98
- expect(0.to_s).to include(size.to_s), lambda {"[key]: \"#{data[:key]} => #{@resp}\"".blue + "\n"+ "size not contains #{size}"+ "\n\n" + "[ actual size ]: 0" + "\n" + "expected size to contain: #{size}".green}
124
+ # datatype validation
125
+ if (type == 'boolean') || (type == 'bool')
126
+ 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"}
127
+ elsif ((type != 'boolean') || (type != 'bool')) && (type != nil)
128
+ expect(datatype(type, value)).not_to eq(@resp.class), lambda {"[key]: \"#{data[:key]}\"".blue + "\n datatype shouldn't be \n[type]: \"#{data[:type]}\"\n"}
99
129
  end
100
- end
101
130
 
102
- when 'not contains', '!contains', 'not include', '!include'
103
- # value validation
104
- expect(@resp.to_s).not_to include(value.to_s), lambda {"[key]: \"#{data[:key]} => #{@resp}\"".blue + "\n should not contain \n[value]: \"#{data[:value]}\"\n"} if value != nil
131
+ # size validation
132
+ if size != nil
133
+ begin
134
+ expect(@resp.count.to_s).not_to include(size.to_s), lambda {"[key]: \"#{data[:key]} => #{@resp}\"".blue + "\n"+ "size should not contain #{size}"+ "\n\n" + "[ actual size ]: #{@resp.count}" + "\n" + "expected size not to contain: #{size}".green}
135
+ rescue NoMethodError
136
+ expect(0.to_s).not_to include(size.to_s), lambda {"[key]: \"#{data[:key]} => #{@resp}\"".blue + "\n"+ "size should not contain #{size}"+ "\n\n" + "[ actual size ]: 0" + "\n" + "expected size not to contain: #{size}".green}
137
+ rescue ArgumentError
138
+ expect(0.to_s).not_to include(size.to_s), lambda {"[key]: \"#{data[:key]} => #{@resp}\"".blue + "\n"+ "size should not contain #{size}"+ "\n\n" + "[ actual size ]: 0" + "\n" + "expected size not to contain: #{size}".green}
139
+ end
140
+ end
105
141
 
106
- # datatype validation
107
- if (type == 'boolean') || (type == 'bool')
108
- 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"}
109
- elsif ((type != 'boolean') || (type != 'bool')) && (type != nil)
110
- expect(datatype(type, value)).not_to eq(@resp.class), lambda {"[key]: \"#{data[:key]}\"".blue + "\n datatype shouldn't be \n[type]: \"#{data[:type]}\"\n"}
111
- end
142
+ # is empty validation
143
+ validate_empty(empty, data) if empty != nil
112
144
 
113
- if size != nil
114
- begin
115
- expect(@resp.count.to_s).not_to include(size.to_s), lambda {"[key]: \"#{data[:key]} => #{@resp}\"".blue + "\n"+ "size should not contain #{size}"+ "\n\n" + "[ actual size ]: #{@resp.count}" + "\n" + "expected size not to contain: #{size}".green}
116
- rescue NoMethodError
117
- expect(0.to_s).not_to include(size.to_s), lambda {"[key]: \"#{data[:key]} => #{@resp}\"".blue + "\n"+ "size should not contain #{size}"+ "\n\n" + "[ actual size ]: 0" + "\n" + "expected size not to contain: #{size}".green}
118
- end
145
+ else
146
+ raise('operator not matching')
119
147
  end
120
148
 
149
+ elsif ((size != nil) || (empty != nil)) && operator.nil?
150
+ validate_empty(empty, data) if empty != nil
151
+ validate_size(size, data) if size != nil
152
+
121
153
  else
122
- raise('operator not matching')
154
+ raise('invalid validation fields')
123
155
  end
124
156
  end
157
+
158
+ end
159
+
160
+ def validate_size(size, data)
161
+ begin
162
+ expect(size).to eq(@resp.count), lambda {"[key]: \"#{data[:key]}\"".blue + "\n" + "size didn't match" + "\n\n" + "[ actual size ]: #{@resp.count}" + "\n" + "[expected size]: #{size}".green}
163
+ rescue NoMethodError
164
+ expect(size).to eq(0), lambda {"[key]: \"#{data[:key]}\"".blue + "\n" + "size didn't match" + "\n\n" + "[ actual size ]: 0" + "\n" + "[expected size]: #{size}".green}
165
+ rescue ArgumentError
166
+ expect(size).to eq(0), lambda {"[key]: \"#{data[:key]}\"".blue + "\n" + "size didn't match" + "\n\n" + "[ actual size ]: 0" + "\n" + "[expected size]: #{size}".green}
167
+ end
168
+ end
169
+
170
+ def validate_empty(empty, data)
171
+ case empty
172
+ when true
173
+ expect(@resp.empty?).to eq(empty), lambda {"[key]: \"#{data[:key]}\"".blue + "\n is not empty"+"\n"}
174
+ when false
175
+ expect(@resp.empty?).to eq(empty), lambda {"[key]: \"#{data[:key]}\"".blue + "\n is empty"+"\n"}
176
+ end
125
177
  end
126
178
 
127
179
  def validate_schema(param1, param2)
@@ -1,3 +1,3 @@
1
1
  module ClientApi
2
- VERSION = "0.3.1".freeze
2
+ VERSION = "0.3.2".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: client-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Prashanth Sams
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-04 00:00:00.000000000 Z
11
+ date: 2019-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler