test_joska 1.0.5 → 1.0.6
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/Gemfile.lock +1 -1
- data/lib/test_joska/builder.rb +151 -169
- data/lib/test_joska/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: 167d82045de090e54bf4d22262404a77412d66ab6c232afed644c95ea145ae73
|
|
4
|
+
data.tar.gz: d8db4398d986f6da6d237637c79d33f9908cd7cf1a1f70936e5f35925b809bc2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4d6ad98de629069ff818479a472028ef430f9e70e77c4f0b845aaf46f35e811458e99590b52b6ebcdde50479bc41424a06a4b1e2188cdeda0d506bd7777fb878
|
|
7
|
+
data.tar.gz: 38f7fa1564334f01c22d9534b828b2af0b44eab595985f6f72987487805e4aed21af5c0765ed23d993ba62c6ced7ecdef87f29c58552115e66e8996be5da6f6b
|
data/Gemfile.lock
CHANGED
data/lib/test_joska/builder.rb
CHANGED
|
@@ -1,280 +1,262 @@
|
|
|
1
1
|
module TestJoska
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
@@internal_log = "log"
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
# def initialize(options)
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
# @raise_on_error = options["raise_on_error"]
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
# @output_url = options["output_url"]
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
# @URL = options["url_parts"]
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
# @HEAD = options["headers"]
|
|
14
|
+
|
|
15
|
+
# @standard_endpoint = options["standard_endpoint"]
|
|
14
16
|
|
|
15
|
-
|
|
17
|
+
# @standard_environment = options["standard_environment"]
|
|
16
18
|
|
|
17
|
-
|
|
19
|
+
# end
|
|
18
20
|
|
|
19
|
-
|
|
21
|
+
def jsk_get_log
|
|
20
22
|
|
|
21
|
-
|
|
23
|
+
return @@internal_log
|
|
22
24
|
|
|
23
|
-
|
|
25
|
+
end
|
|
24
26
|
|
|
25
|
-
|
|
27
|
+
def jsk_log(message)
|
|
26
28
|
|
|
27
|
-
|
|
29
|
+
p @@internal_log = "#{@@internal_log}#{message}\n"
|
|
28
30
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
@standard_endpoint = options["standard_endpoint"]
|
|
31
|
+
end
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
def jsk_clear_log
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
@@internal_log = ""
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
end
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
def jsk_get_url_log
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
return @url_log
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
end
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
def jsk_clear_url_log
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
@url_log = ""
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def request(method, product, type, details=nil, payload=nil, header_type=nil, endpoint=nil, env=nil)
|
|
50
52
|
|
|
51
|
-
|
|
53
|
+
endpoint = endpoint ? endpoint : @standard_endpoint
|
|
52
54
|
|
|
53
|
-
|
|
55
|
+
url = urlBuilder(product, type, details, endpoint, env)
|
|
54
56
|
|
|
55
|
-
|
|
57
|
+
header_type ? header = @HEAD[header_type] : header = @HEAD[endpoint]
|
|
56
58
|
|
|
57
|
-
|
|
59
|
+
payload = payload.to_json if payload
|
|
58
60
|
|
|
59
|
-
|
|
61
|
+
res = ""
|
|
60
62
|
|
|
61
|
-
|
|
63
|
+
p url
|
|
62
64
|
|
|
63
|
-
|
|
65
|
+
@url_log = "#{@url_log}\n#{method} #{type}: #{url}"
|
|
64
66
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
def request(method, product, type, details=nil, payload=nil, header_type=nil, endpoint=nil, env=nil)
|
|
67
|
+
@url_log = "#{@url_log}\nPayload: #{payload}" if payload && type != "login"
|
|
68
68
|
|
|
69
|
-
|
|
69
|
+
RestClient::Request.execute(method: method, url: url, headers: header, payload: payload, timeout: 90) do |response|
|
|
70
70
|
|
|
71
|
-
|
|
71
|
+
if response.code != 200
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
begin
|
|
74
74
|
|
|
75
|
-
|
|
75
|
+
response = JSON.parse(response)
|
|
76
76
|
|
|
77
|
-
|
|
77
|
+
rescue
|
|
78
78
|
|
|
79
|
-
|
|
79
|
+
p "Não possível converter para json"
|
|
80
80
|
|
|
81
|
-
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
raise "Erro no serviço #{type}, codigo: #{response.code} \nURL: #{url} \nResposta: #{response}"
|
|
82
84
|
|
|
83
|
-
|
|
85
|
+
end
|
|
84
86
|
|
|
85
|
-
|
|
87
|
+
res = response
|
|
86
88
|
|
|
87
|
-
|
|
89
|
+
end
|
|
88
90
|
|
|
89
|
-
|
|
91
|
+
begin
|
|
90
92
|
|
|
91
|
-
|
|
93
|
+
return JSON.parse(res)
|
|
92
94
|
|
|
93
|
-
|
|
95
|
+
rescue
|
|
94
96
|
|
|
95
|
-
|
|
97
|
+
raise "Problema em converter a resposta #{response}" if res != ""
|
|
96
98
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
raise "Erro no serviço #{type}, codigo: #{response.code} \nURL: #{url} \nResposta: #{response}"
|
|
99
|
+
end
|
|
100
100
|
|
|
101
|
-
|
|
101
|
+
end
|
|
102
102
|
|
|
103
|
-
|
|
103
|
+
def urlBuilder(product, type, details, endpoint, env=nil)
|
|
104
104
|
|
|
105
|
-
|
|
105
|
+
env = env ? env : @standard_environment
|
|
106
106
|
|
|
107
|
-
|
|
107
|
+
details = "" if !details
|
|
108
108
|
|
|
109
|
-
|
|
109
|
+
details = [details] if !details.kind_of?(Array)
|
|
110
110
|
|
|
111
|
-
|
|
111
|
+
url = @URL[product]["base"]["#{env}_#{endpoint}"]
|
|
112
112
|
|
|
113
|
-
|
|
113
|
+
if !@URL[product]["path"][type].kind_of?(Array)
|
|
114
114
|
|
|
115
|
-
|
|
115
|
+
return "#{url}#{@URL[product]["path"][type]}#{details[0]}"
|
|
116
116
|
|
|
117
|
-
|
|
117
|
+
else
|
|
118
118
|
|
|
119
|
-
|
|
119
|
+
query_pos = 0
|
|
120
120
|
|
|
121
|
-
|
|
121
|
+
@URL[product]["path"][type].each do |query|
|
|
122
122
|
|
|
123
|
-
|
|
123
|
+
if details[query_pos] && details[query_pos] != ""
|
|
124
124
|
|
|
125
|
-
|
|
125
|
+
query = query[0] if query.kind_of?(Array)
|
|
126
126
|
|
|
127
|
-
|
|
127
|
+
url = "#{url}#{query}#{details[query_pos]}"
|
|
128
128
|
|
|
129
|
-
|
|
129
|
+
else
|
|
130
130
|
|
|
131
|
-
|
|
131
|
+
query.kind_of?(Array) ? url = "#{url}#{query[0]}#{query[1]}" : url = "#{url}#{query}"
|
|
132
132
|
|
|
133
|
-
|
|
133
|
+
end
|
|
134
134
|
|
|
135
|
-
query_pos
|
|
135
|
+
query_pos += 1
|
|
136
136
|
|
|
137
|
-
|
|
137
|
+
end
|
|
138
138
|
|
|
139
|
-
|
|
139
|
+
return url
|
|
140
140
|
|
|
141
|
-
|
|
141
|
+
end
|
|
142
142
|
|
|
143
|
-
|
|
143
|
+
end
|
|
144
144
|
|
|
145
|
-
|
|
145
|
+
def rateTokenBuilder(rateToken)
|
|
146
146
|
|
|
147
|
-
|
|
147
|
+
token_decoded = Base64.decode64(rateToken).gsub(" ", "").gsub("/>", "").gsub("<rateToken", "").gsub("=", "").split('"')
|
|
148
148
|
|
|
149
|
-
|
|
149
|
+
built_token = {}
|
|
150
150
|
|
|
151
|
-
|
|
151
|
+
cur_part = 0
|
|
152
152
|
|
|
153
|
-
|
|
153
|
+
while cur_part < token_decoded.count do
|
|
154
154
|
|
|
155
|
-
|
|
155
|
+
built_token[token_decoded[cur_part]] = token_decoded[cur_part + 1]
|
|
156
156
|
|
|
157
|
-
|
|
157
|
+
cur_part += 2
|
|
158
158
|
|
|
159
159
|
end
|
|
160
160
|
|
|
161
|
-
|
|
161
|
+
built_token
|
|
162
162
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
built_token = {}
|
|
166
|
-
|
|
167
|
-
cur_part = 0
|
|
168
|
-
|
|
169
|
-
while cur_part < token_decoded.count do
|
|
170
|
-
|
|
171
|
-
built_token[token_decoded[cur_part]] = token_decoded[cur_part + 1]
|
|
172
|
-
|
|
173
|
-
cur_part += 2
|
|
174
|
-
|
|
175
|
-
end
|
|
176
|
-
|
|
177
|
-
built_token
|
|
178
|
-
|
|
179
|
-
end
|
|
180
|
-
|
|
181
|
-
def comparePrice(price1, price2, type1, type2)
|
|
163
|
+
end
|
|
182
164
|
|
|
183
|
-
|
|
165
|
+
def comparePrice(price1, price2, type1, type2)
|
|
184
166
|
|
|
185
|
-
|
|
167
|
+
range = price1.abs * 0.001 > 0.10 ? price1.abs * 0.001 : 0.10
|
|
186
168
|
|
|
187
|
-
|
|
169
|
+
if !(price1.abs-range...price1.abs+range).include?(price2.abs)
|
|
188
170
|
|
|
189
|
-
|
|
171
|
+
error_name = "#{type1} - #{type2}"
|
|
190
172
|
|
|
191
|
-
|
|
173
|
+
error_message = "#{type1}: R$#{price1} / #{type2}: R$#{price2}",
|
|
192
174
|
|
|
193
|
-
|
|
175
|
+
tempErrorhandler("price", error_name, error_message)
|
|
194
176
|
|
|
195
|
-
|
|
177
|
+
raise "Diferença de preço encontrada (#{type1} - #{type2})\n#{error_message}" if @raise_on_error
|
|
196
178
|
|
|
197
|
-
|
|
179
|
+
jsk_log("Diferença de preço encontrada (#{type1} - #{type2})\n#{error_message}")
|
|
198
180
|
|
|
199
181
|
end
|
|
200
182
|
|
|
183
|
+
end
|
|
201
184
|
|
|
202
|
-
def compareValues(value1, value2, message, type1, type2)
|
|
203
185
|
|
|
204
|
-
|
|
186
|
+
def compareValues(value1, value2, message, type1, type2)
|
|
205
187
|
|
|
206
|
-
|
|
188
|
+
if value1 != value2
|
|
207
189
|
|
|
208
|
-
|
|
190
|
+
value1 = "null" if value1 == nil
|
|
209
191
|
|
|
210
|
-
|
|
192
|
+
value2 = "null" if value2 == nil
|
|
211
193
|
|
|
212
|
-
|
|
194
|
+
error_name = "#{message} (#{type1} - #{type2})"
|
|
213
195
|
|
|
214
|
-
|
|
196
|
+
error_message = "#{type1}: #{value1} / #{type2}: #{value2}"
|
|
215
197
|
|
|
216
|
-
|
|
198
|
+
tempErrorhandler("value", error_name, error_message)
|
|
217
199
|
|
|
218
|
-
|
|
200
|
+
raise "Conflito: #{message} (#{type1} - #{type2})\n(#{error_message})" if @raise_on_error
|
|
219
201
|
|
|
220
|
-
|
|
202
|
+
jsk_log("Conflito: #{message} (#{type1} - #{type2})\n(#{error_message})")
|
|
221
203
|
|
|
222
204
|
end
|
|
223
205
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
def checkFloat value
|
|
209
|
+
|
|
210
|
+
true if Float value rescue false
|
|
211
|
+
|
|
212
|
+
end
|
|
229
213
|
|
|
230
|
-
|
|
214
|
+
def genericComparator object1, object2, context, type1 = "Barramento", type2 = "Micro serviço"
|
|
231
215
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
end
|
|
241
|
-
|
|
242
|
-
elsif object1.is_a?(Array) && object2.is_a?(Array)
|
|
243
|
-
|
|
244
|
-
if object1.count != object2.count
|
|
245
|
-
|
|
246
|
-
genericComparator(object1[0], object2[0], "#{context}_arrayElement", type1, type2) if object1[0] && object2[0]
|
|
247
|
-
|
|
248
|
-
return compareValues(object1.count, object2.count, "#{context}_arrayCount", type1, type2)
|
|
249
|
-
|
|
250
|
-
end
|
|
251
|
-
|
|
252
|
-
array_count = 0
|
|
253
|
-
|
|
254
|
-
while array_count < object1.count do
|
|
255
|
-
|
|
256
|
-
genericComparator(object1[array_count], object2[array_count], "#{context}_arrayElement", type1, type2)
|
|
257
|
-
|
|
258
|
-
array_count += 1
|
|
259
|
-
|
|
260
|
-
end
|
|
261
|
-
|
|
262
|
-
elsif (checkFloat(object1) && checkFloat(object2)) && (object1.to_s.include?(".") || object2.to_s.include?("."))
|
|
263
|
-
|
|
264
|
-
comparePrice(object1.to_f, object2.to_f, "#{type1}_#{context}", "#{type2}_#{context}")
|
|
265
|
-
|
|
266
|
-
elsif context.split("_").last.include?("Token")
|
|
267
|
-
|
|
268
|
-
genericComparator(rateTokenBuilder(object1), rateTokenBuilder(object2), "#{context}_decoded", type1, type2)
|
|
269
|
-
|
|
270
|
-
else
|
|
271
|
-
|
|
272
|
-
compareValues(object1, object2, context, type1, type2)
|
|
273
|
-
|
|
216
|
+
if object1.is_a?(Hash) && object2.is_a?(Hash)
|
|
217
|
+
|
|
218
|
+
compareValues(object1.keys.count, object2.keys.count, "#{context}_keyCount", type1, type2)
|
|
219
|
+
|
|
220
|
+
(object1.keys | object2.keys).each do |key|
|
|
221
|
+
|
|
222
|
+
genericComparator(object1[key], object2[key], "#{context}_#{key}", type1, type2)
|
|
223
|
+
|
|
274
224
|
end
|
|
275
|
-
|
|
225
|
+
|
|
226
|
+
elsif object1.is_a?(Array) && object2.is_a?(Array)
|
|
227
|
+
|
|
228
|
+
if object1.count != object2.count
|
|
229
|
+
|
|
230
|
+
genericComparator(object1[0], object2[0], "#{context}_arrayElement", type1, type2) if object1[0] && object2[0]
|
|
231
|
+
|
|
232
|
+
return compareValues(object1.count, object2.count, "#{context}_arrayCount", type1, type2)
|
|
233
|
+
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
array_count = 0
|
|
237
|
+
|
|
238
|
+
while array_count < object1.count do
|
|
239
|
+
|
|
240
|
+
genericComparator(object1[array_count], object2[array_count], "#{context}_arrayElement", type1, type2)
|
|
241
|
+
|
|
242
|
+
array_count += 1
|
|
243
|
+
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
elsif (checkFloat(object1) && checkFloat(object2)) && (object1.to_s.include?(".") || object2.to_s.include?("."))
|
|
247
|
+
|
|
248
|
+
comparePrice(object1.to_f, object2.to_f, "#{type1}_#{context}", "#{type2}_#{context}")
|
|
249
|
+
|
|
250
|
+
elsif context.split("_").last.include?("Token")
|
|
251
|
+
|
|
252
|
+
genericComparator(rateTokenBuilder(object1), rateTokenBuilder(object2), "#{context}_decoded", type1, type2)
|
|
253
|
+
|
|
254
|
+
else
|
|
255
|
+
|
|
256
|
+
compareValues(object1, object2, context, type1, type2)
|
|
257
|
+
|
|
276
258
|
end
|
|
277
|
-
|
|
259
|
+
|
|
278
260
|
end
|
|
279
261
|
|
|
280
262
|
end
|
data/lib/test_joska/version.rb
CHANGED