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