seko 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/.travis.yml +23 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +210 -0
- data/Rakefile +1 -0
- data/lib/seko/client.rb +236 -0
- data/lib/seko/company.rb +33 -0
- data/lib/seko/dispatch.rb +22 -0
- data/lib/seko/filter.rb +9 -0
- data/lib/seko/order.rb +77 -0
- data/lib/seko/product.rb +27 -0
- data/lib/seko/receipt.rb +36 -0
- data/lib/seko/response.rb +33 -0
- data/lib/seko/shipping.rb +26 -0
- data/lib/seko/stock.rb +9 -0
- data/lib/seko/tracking.rb +22 -0
- data/lib/seko/version.rb +3 -0
- data/lib/seko.rb +31 -0
- data/seko.gemspec +27 -0
- data/spec/fixtures/company_submit.json +21 -0
- data/spec/fixtures/dispatch_statuses.json +25 -0
- data/spec/fixtures/grn.json +45 -0
- data/spec/fixtures/order_status.json +11 -0
- data/spec/fixtures/order_submit.json +33 -0
- data/spec/fixtures/order_tracking.json +12 -0
- data/spec/fixtures/order_websubmit.json +29 -0
- data/spec/fixtures/product_submit.json +15 -0
- data/spec/fixtures/receipt_submit.json +26 -0
- data/spec/fixtures/stock.json +29 -0
- data/spec/fixtures/stock_adjustment.json +7 -0
- data/spec/fixtures/stock_movement.json +7 -0
- data/spec/lib/client_spec.rb +364 -0
- data/spec/lib/company_spec.rb +22 -0
- data/spec/lib/dispatch_spec.rb +17 -0
- data/spec/lib/filter_spec.rb +12 -0
- data/spec/lib/order_spec.rb +60 -0
- data/spec/lib/product_spec.rb +23 -0
- data/spec/lib/receipt_spec.rb +36 -0
- data/spec/lib/response_spec.rb +53 -0
- data/spec/lib/stock_spec.rb +12 -0
- data/spec/logs/spec.log +0 -0
- data/spec/spec_helper.rb +176 -0
- metadata +196 -0
@@ -0,0 +1,364 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe Seko::Client do
|
3
|
+
|
4
|
+
let(:token) { 'abc123' }
|
5
|
+
let(:options) { { verbose: true, test_mode: true } }
|
6
|
+
let(:live_options) { { verbose: false, test_mode: false } }
|
7
|
+
let(:client) { Seko::Client.new(token, options) }
|
8
|
+
let(:live_client) { Seko::Client.new(token, live_options) }
|
9
|
+
|
10
|
+
describe '#initialize' do
|
11
|
+
it 'sets the @token and @options' do
|
12
|
+
expect(client.token).to eq(token)
|
13
|
+
expect(client.options).to eq(options)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#send_order_request' do
|
18
|
+
before do
|
19
|
+
stub_post("salesorders/v1/websubmit.json").with(query: {token: token}).
|
20
|
+
to_return(body: success_response.to_json, headers: json_headers)
|
21
|
+
end
|
22
|
+
|
23
|
+
let(:response) { client.send_order_request(order_hash) }
|
24
|
+
|
25
|
+
it 'sends an POST request with an order object' do
|
26
|
+
expect(response.success?).to eq(true)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#order_request' do
|
31
|
+
let(:expected_result) { fixture(:order_websubmit).to_json }
|
32
|
+
|
33
|
+
it 'formats the ruby hash response to a json object' do
|
34
|
+
expect(client.order_request(order_hash)).to eq(expected_result)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe 'inventory methods' do
|
39
|
+
before do
|
40
|
+
stub_get("stock/v1/all.json").with(query: {token: token}).
|
41
|
+
to_return(body: fixture(:stock).to_json, headers: json_headers)
|
42
|
+
end
|
43
|
+
|
44
|
+
let(:response) { client.get_inventory }
|
45
|
+
let(:upc_array) { [100014, 100015, 100016] }
|
46
|
+
let(:raw_response) { read_json(:stock) }
|
47
|
+
|
48
|
+
describe '#get_inventory' do
|
49
|
+
before { response }
|
50
|
+
|
51
|
+
it 'sets service and enpoints on the client' do
|
52
|
+
expect(client.service).to eq('stock')
|
53
|
+
expect(client.endpoint).to eq('all')
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'returns a Seko::Response object' do
|
57
|
+
expect(response).to be_a(Seko::Response)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe '#inventory_request' do
|
62
|
+
it 'makes HTTP request and builds Seko::Response object' do
|
63
|
+
parsed = client.map_results(Seko::Stock.parse(Seko::Response.new(raw_response)))
|
64
|
+
expect(response.parsed).to eq(parsed)
|
65
|
+
expect(JSON.parse(response.raw)).to eq(JSON.parse(raw_response))
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
describe '#upcs' do
|
71
|
+
it 'returns array of upcs' do
|
72
|
+
expect(client.upcs(response.parsed)).to eq(upc_array)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe '#mapped_inventory' do
|
77
|
+
it 'maps inventory into a collection of simple hashes' do
|
78
|
+
expected_collection = [{ quantity: 0 }, { quantity: 10 }, { quantity: 20 }]
|
79
|
+
expect(client.mapped_inventory(upc_array, response.parsed)).to eq(expected_collection)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe '#map_results' do
|
84
|
+
it 'normalizes the quantity and upc fields' do
|
85
|
+
expect(response.parsed.map { |x| x["qty"] }).to eq([0, 10, 20])
|
86
|
+
expect(response.parsed.map { |x| x["upc"] }).to eq(upc_array)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe '#map_keys' do
|
91
|
+
it 'maps verbose keys to simpler keys' do
|
92
|
+
expect(client.send(:map_keys, "FreeQuantity")).to eq('qty')
|
93
|
+
expect(client.send(:map_keys, "ProductCode")).to eq('upc')
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
describe '#submit_product' do
|
100
|
+
let(:product_hash) { { test: '123' } }
|
101
|
+
|
102
|
+
it 'returns a succesful response' do
|
103
|
+
stub_post("products/v1/submit.json").with(query: {token: token}).
|
104
|
+
to_return(status: 200, body: success_response.to_json, headers: json_headers)
|
105
|
+
expect(Seko::Product).to receive(:format).with(product_hash)
|
106
|
+
response = client.submit_product(product_hash)
|
107
|
+
expect(response.success?).to eq(true)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
describe '#submit_receipt' do
|
112
|
+
before do
|
113
|
+
stub_post("receipts/v1/submit.json").with(query: {token: token}).
|
114
|
+
to_return(body: success_response.to_json, headers: json_headers)
|
115
|
+
end
|
116
|
+
|
117
|
+
let(:response) { client.submit_receipt(line_items_array, order_hash[:warehouse]) }
|
118
|
+
|
119
|
+
it 'sends an POST request with a receipt object' do
|
120
|
+
expect(response.success?).to eq(true)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
describe '#submit_company' do
|
125
|
+
before do
|
126
|
+
stub_post("companies/v1/submit.json").with(query: {token: token}).
|
127
|
+
to_return(body: success_response.to_json, headers: json_headers)
|
128
|
+
end
|
129
|
+
|
130
|
+
let(:response) { client.submit_company(company_submit_hash) }
|
131
|
+
|
132
|
+
it 'sends an POST request with a company object' do
|
133
|
+
expect(response.success?).to eq(true)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
describe '#check_grn' do
|
138
|
+
let(:guid) { '5b2dcd8e-52c3-4e27-a712-eaacda2dd8fe' }
|
139
|
+
let(:response) { client.check_grn(guid) }
|
140
|
+
|
141
|
+
before do
|
142
|
+
stub_get("grns/v1/#{guid}.json").with(query: {token: token}).
|
143
|
+
to_return(body: fixture(:grn).to_json, headers: json_headers)
|
144
|
+
end
|
145
|
+
|
146
|
+
it 'gets a GRN response' do
|
147
|
+
expect(response.success?).to eq(true)
|
148
|
+
end
|
149
|
+
|
150
|
+
end
|
151
|
+
|
152
|
+
describe '#order_status' do
|
153
|
+
let(:guid) { 'f66fd245-7b9e-4fd2-9dbf-5631edc875d9' }
|
154
|
+
let(:response) { client.order_status(guid) }
|
155
|
+
|
156
|
+
before do
|
157
|
+
stub_get("salesorders/v1/#{guid}/status.json").with(query: {token: token}).
|
158
|
+
to_return(body: fixture(:order_status).to_json, headers: json_headers)
|
159
|
+
end
|
160
|
+
|
161
|
+
it "gets an order's status" do
|
162
|
+
expect(response.success?).to eq(true)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
describe '#order_tracking' do
|
167
|
+
let(:guid) { 'f66fd245-7b9e-4fd2-9dbf-5631edc875d9' }
|
168
|
+
let(:response) { client.order_tracking(guid) }
|
169
|
+
|
170
|
+
before do
|
171
|
+
stub_get("salesorders/v1/#{guid}/tracking.json").with(query: {token: token}).
|
172
|
+
to_return(body: fixture(:order_tracking).to_json, headers: json_headers)
|
173
|
+
end
|
174
|
+
|
175
|
+
it "gets an order's status" do
|
176
|
+
expect(response.success?).to eq(true)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
describe '#cancel_order' do
|
181
|
+
let(:guid) { 'f66fd245-7b9e-4fd2-9dbf-5631edc875d9' }
|
182
|
+
let(:response) { client.cancel_order(guid, '001') }
|
183
|
+
|
184
|
+
before do
|
185
|
+
stub_post("salesorders/v1/#{guid}/cancel/reasoncode/001.json").with(query: {token: token}).
|
186
|
+
to_return(body: success_response.to_json, headers: json_headers)
|
187
|
+
end
|
188
|
+
|
189
|
+
it "gets an order's status" do
|
190
|
+
expect(response.success?).to eq(true)
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
describe '#stock_adjustments' do
|
195
|
+
let(:from) { '2013-10-31T00:00:00Z' }
|
196
|
+
let(:to) { '2014-10-31T00:00:00Z' }
|
197
|
+
let(:warehouse) { 'DC123' }
|
198
|
+
let(:response) { client.stock_adjustments(Date.parse(from), Date.parse(to), warehouse) }
|
199
|
+
|
200
|
+
before do
|
201
|
+
stub_get("stock/v1/adjustment/#{from}/#{to}.json").with(query: {token: token, dc: warehouse}).
|
202
|
+
to_return(body: fixture(:stock_adjustment).to_json, headers: json_headers)
|
203
|
+
end
|
204
|
+
|
205
|
+
it "gets stock adjustments in timeframe" do
|
206
|
+
expect(response.success?).to eq(true)
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
describe '#stock_movements' do
|
211
|
+
let(:from) { '2013-10-31T00:00:00Z' }
|
212
|
+
let(:to) { '2014-10-31T00:00:00Z' }
|
213
|
+
let(:warehouse) { 'DC123' }
|
214
|
+
let(:response) { client.stock_movements(Date.parse(from), Date.parse(to), warehouse) }
|
215
|
+
|
216
|
+
before do
|
217
|
+
stub_get("stock/v1/movement/#{from}/#{to}.json").with(query: {token: token, dc: warehouse}).
|
218
|
+
to_return(body: fixture(:stock_movement).to_json, headers: json_headers)
|
219
|
+
end
|
220
|
+
|
221
|
+
it "gets stock movements in timeframe" do
|
222
|
+
expect(response.success?).to eq(true)
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
describe '#dispatch_statuses' do
|
227
|
+
let(:from) { '2013-10-31T00:00:00Z' }
|
228
|
+
let(:to) { '2014-10-31T00:00:00Z' }
|
229
|
+
let(:warehouse) { 'DC123' }
|
230
|
+
let(:response) { client.dispatch_statuses(Date.parse(from), Date.parse(to), warehouse) }
|
231
|
+
|
232
|
+
before do
|
233
|
+
stub_get("dispatches/v1/status/#{from}/#{to}.json").with(query: {token: token, dc: warehouse, status: 'Dispatched'}).
|
234
|
+
to_return(body: fixture(:dispatch_statuses).to_json, headers: json_headers)
|
235
|
+
end
|
236
|
+
|
237
|
+
it "gets dispatch statuses in timeframe" do
|
238
|
+
expect(response.success?).to eq(true)
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
describe '#request_uri' do
|
243
|
+
it 'builds the request URI' do
|
244
|
+
expect(client).to receive(:host).and_return('test.com/')
|
245
|
+
expect(client).to receive(:path).and_return('test')
|
246
|
+
expect(client).to receive(:token).and_return('abc123')
|
247
|
+
expect(client.request_uri).to eq("https://test.com/test?token=abc123")
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
describe '#path' do
|
252
|
+
it 'builds the URI path' do
|
253
|
+
expect(client).to receive(:service).and_return('test')
|
254
|
+
expect(client).to receive(:endpoint).and_return('testendpoint')
|
255
|
+
expect(client.path).to eq("/hub/api/test/v1/testendpoint.json")
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
describe 'private methods' do
|
260
|
+
|
261
|
+
describe '#default_options' do
|
262
|
+
it 'returns default options' do
|
263
|
+
expect(client.send(:default_options)).to eq({ verbose: false, test_mode: true })
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
describe '#testing?' do
|
268
|
+
it 'returns a boolean to check test mode' do
|
269
|
+
expect(client.send(:testing?)).to eq(true)
|
270
|
+
expect(live_client.send(:testing?)).to eq(false)
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
describe '#verbose?' do
|
275
|
+
it 'returns a boolean to check whether to log results or not' do
|
276
|
+
expect(client.send(:verbose?)).to eq(true)
|
277
|
+
expect(live_client.send(:verbose?)).to eq(false)
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
describe '#host' do
|
282
|
+
it 'returns host depending of test mode' do
|
283
|
+
expect(client.send(:host)).to eq(Seko::Client::TEST_HOST)
|
284
|
+
expect(live_client.send(:host)).to eq(Seko::Client::LIVE_HOST)
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
describe '#log' do
|
289
|
+
it 'logs messages when verbose mode is set' do
|
290
|
+
expect { client.send(:log, 'test') }.to output(/test/).to_stdout
|
291
|
+
expect { live_client.send(:log, 'test') }.to_not output(/test/).to_stdout
|
292
|
+
end
|
293
|
+
end
|
294
|
+
|
295
|
+
describe '#http' do
|
296
|
+
it 'returns a Net::HTTP object' do
|
297
|
+
expect(client.send(:http)).to be_a(Net::HTTP)
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
describe '#build_request' do
|
302
|
+
|
303
|
+
let(:get_request) { client.send(:build_request, 'Get') }
|
304
|
+
let(:post_request) { client.send(:build_request, 'Post') }
|
305
|
+
|
306
|
+
it 'builds a net/https request' do
|
307
|
+
expect(get_request).to be_a(Net::HTTP::Get)
|
308
|
+
expect(post_request).to be_a(Net::HTTP::Post)
|
309
|
+
expect(get_request.content_type).to eq(Seko::Client::CONTENT_TYPE)
|
310
|
+
end
|
311
|
+
end
|
312
|
+
|
313
|
+
describe '#request' do
|
314
|
+
it 'sets the ssl and verify mode, sends an http request, and returns a response object' do
|
315
|
+
expect(client.send(:http)).to receive(:request).and_return(fake_response)
|
316
|
+
expect(client.send(:request, 'Get')).to be_a(Seko::Response)
|
317
|
+
expect(client.send(:http).use_ssl?).to be(true)
|
318
|
+
expect(client.send(:http).verify_mode).to eq(OpenSSL::SSL::VERIFY_NONE)
|
319
|
+
end
|
320
|
+
end
|
321
|
+
|
322
|
+
describe '#get' do
|
323
|
+
it 'builds and makes a GET request' do
|
324
|
+
expect(client).to receive(:build_request)
|
325
|
+
expect(client).to receive(:request)
|
326
|
+
client.send(:get)
|
327
|
+
end
|
328
|
+
end
|
329
|
+
|
330
|
+
describe '#post' do
|
331
|
+
it 'builds and makes a POST request' do
|
332
|
+
expect(client).to receive(:request)
|
333
|
+
client.send(:post, { test: true })
|
334
|
+
end
|
335
|
+
end
|
336
|
+
|
337
|
+
describe '#parse_response' do
|
338
|
+
let(:json_response) { {test: true}.to_json }
|
339
|
+
|
340
|
+
it 'logs response' do
|
341
|
+
expect(client).to receive(:log).with(json_response)
|
342
|
+
client.send(:parse_response, json_response)
|
343
|
+
end
|
344
|
+
|
345
|
+
it 'parses response into a Seko::Response object' do
|
346
|
+
expect(client.send(:parse_response, json_response)).to be_a(Seko::Response)
|
347
|
+
end
|
348
|
+
end
|
349
|
+
|
350
|
+
describe '#format_from_to' do
|
351
|
+
|
352
|
+
let(:from) { '2013-10-31T00:00:00Z' }
|
353
|
+
let(:to) { '2014-10-31T00:00:00Z' }
|
354
|
+
let(:expected_result) { "#{from}/#{to}" }
|
355
|
+
|
356
|
+
it 'returns a url ready from / to string' do
|
357
|
+
expect(client.send(:format_from_to, Date.parse(from), Date.parse(to))).to eq(expected_result)
|
358
|
+
end
|
359
|
+
|
360
|
+
end
|
361
|
+
|
362
|
+
end
|
363
|
+
|
364
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe Seko::Company do
|
3
|
+
|
4
|
+
before do
|
5
|
+
Seko.configure(configuration)
|
6
|
+
end
|
7
|
+
|
8
|
+
describe '.format' do
|
9
|
+
it 'formats a simple company hash into a fully formed JSON ready hash' do
|
10
|
+
expected_result = fixture(:company_submit)
|
11
|
+
expect(Seko::Company.format(company_submit_hash)).to eq(expected_result)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '.address' do
|
16
|
+
it 'formats a simple address hash into a fully formed JSON ready hash' do
|
17
|
+
expected_result = fixture(:company_submit)["Request"]["List"]["Address"]
|
18
|
+
expect(Seko::Company.address(company_address_hash)).to eq(expected_result)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe Seko::Dispatch do
|
3
|
+
|
4
|
+
describe '.parse_collection' do
|
5
|
+
let(:response) { Seko::Response.new(read_json(:dispatch_statuses)) }
|
6
|
+
let(:guid_array) { [
|
7
|
+
"2b5e52cc-fb6f-4ea4-b8cf-cf64e3a2b8db",
|
8
|
+
"93e92ca2-725a-46f8-90dd-43a16105f78d",
|
9
|
+
"143544ec-f396-4155-95c6-bf59898e0830"
|
10
|
+
] }
|
11
|
+
|
12
|
+
it 'returns the relevant stock info' do
|
13
|
+
expect(Seko::Dispatch.parse(response)).to eq(guid_array)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe Seko::Filter do
|
3
|
+
|
4
|
+
describe '.parse' do
|
5
|
+
let(:unfiltered) { "test | this" }
|
6
|
+
let(:expected) { "test - this" }
|
7
|
+
it 'removes | characters' do
|
8
|
+
expect(Seko::Filter.parse(unfiltered)).to eq (expected)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe Seko::Order do
|
3
|
+
|
4
|
+
let(:email) { "stephen.jones@gmail.com" }
|
5
|
+
|
6
|
+
before do
|
7
|
+
Seko.configure(configuration)
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '.websubmit' do
|
11
|
+
it 'returns a JSON order object for a web order' do
|
12
|
+
expected_result = fixture(:order_websubmit)
|
13
|
+
expect(Seko::Order.websubmit(order_hash)).to eq(expected_result)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '.submit' do
|
18
|
+
it 'returns a JSON order object for a retailer' do
|
19
|
+
expected_result = fixture(:order_submit)
|
20
|
+
expect(Seko::Order.submit(company_order_hash)).to eq(expected_result)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '.format' do
|
25
|
+
|
26
|
+
it 'returns a Seko ready JSON order object' do
|
27
|
+
expected_result = fixture(:order_websubmit)
|
28
|
+
expect(Seko::Order.format(order_hash, 'Web')).to eq(expected_result)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '.address' do
|
34
|
+
|
35
|
+
it 'returns JSON format ready address' do
|
36
|
+
expected_result = fixture(:order_websubmit)["Request"]["DeliveryDetails"]
|
37
|
+
expect(Seko::Order.address(address_hash, email)).to eq(expected_result)
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '.line_items' do
|
43
|
+
|
44
|
+
it 'returns JSON format ready line items array' do
|
45
|
+
expected_result = fixture(:order_websubmit)["Request"]["List"]["SalesOrderLineItem"]
|
46
|
+
expect(Seko::Order.line_items(line_items_array)).to eq(expected_result)
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '.company' do
|
52
|
+
|
53
|
+
it 'returns JSON format ready company' do
|
54
|
+
expected_result = { "ShipToCompany" => fixture(:order_submit)["Request"]["ShipToCompany"] }
|
55
|
+
expect(Seko::Order.company(company_hash)).to eq(expected_result)
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe Seko::Product do
|
3
|
+
|
4
|
+
let(:product_hash) { { upc: 123456, description: "A Test Product" } }
|
5
|
+
|
6
|
+
before do
|
7
|
+
Seko.configure(configuration)
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '.supplier' do
|
11
|
+
it 'reads supplier deatils from config' do
|
12
|
+
expect(Seko.config).to eq(configuration)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '.format' do
|
17
|
+
it 'formats a simple product hash into a fully formed JSON ready hash' do
|
18
|
+
expected_result = fixture(:product_submit)
|
19
|
+
expect(Seko::Product.format(product_hash)).to eq(expected_result)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe Seko::Receipt do
|
3
|
+
|
4
|
+
let(:line_items_array) do
|
5
|
+
[
|
6
|
+
{ id: 1, upc: 100083, quantity: 10 },
|
7
|
+
{ id: 2, upc: 100076, quantity: 15 }
|
8
|
+
]
|
9
|
+
end
|
10
|
+
|
11
|
+
before do
|
12
|
+
Seko.configure(configuration)
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '.line_items' do
|
16
|
+
it 'structures line items into JSON ready hash' do
|
17
|
+
expected_result = fixture(:receipt_submit)["Request"]["List"]["ReceiptLineItem"]
|
18
|
+
expect(Seko::Receipt.line_items(line_items_array)).to eq(expected_result)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '.format' do
|
23
|
+
it 'formats a fully formed JSON ready hash for receipt' do
|
24
|
+
expected_result = fixture(:receipt_submit)
|
25
|
+
expect(Seko::Receipt).to receive(:random_asn).and_return(123456)
|
26
|
+
expect(Seko::Receipt.format(line_items_array, 'DC123')).to eq(expected_result)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '.random_asn' do
|
31
|
+
it 'generates a 10 digit random string' do
|
32
|
+
expect(Seko::Receipt.random_asn).to satisfy { |value| value.size == 10 }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe Seko::Response do
|
3
|
+
|
4
|
+
let(:guid) { 'f66fd245-7b9e-4fd2-9dbf-5631edc875d9' }
|
5
|
+
let(:failed_response) { "{\n \"CallStatus\": {\n \"Success\": false, \"Message\": \"Failed!\" } }" }
|
6
|
+
let(:errant_raw) { "{\n \"CallStatus\": {\n \"Success\": true, \"Message\": {} }, \"GUID\": \"#{guid}\" }" }
|
7
|
+
let(:raw_response) { "{\"Response\": #{errant_raw}}" }
|
8
|
+
let(:parsed_response) { JSON.parse(raw_response) }
|
9
|
+
let(:response) { Seko::Response.new(raw_response) }
|
10
|
+
let(:errant_response) { Seko::Response.new(errant_raw) }
|
11
|
+
let(:failure_response) { Seko::Response.new(failed_response) }
|
12
|
+
|
13
|
+
describe '#initialize' do
|
14
|
+
it 'sets the raw and parsed response' do
|
15
|
+
expect(response.raw).to eq(raw_response)
|
16
|
+
expect(response.parsed).to eq(parsed_response)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#root_response' do
|
21
|
+
it 'fixes an issue in the API were sometimes the "Response" object is present and sometimes it is not' do
|
22
|
+
expect(errant_response.root_response).to eq(response.root_response)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#success?' do
|
27
|
+
it 'checks and returns the proper field in repsonse object for success' do
|
28
|
+
expect(response.success?).to be(true)
|
29
|
+
expect(failure_response.success?).to be(false)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '#failure?' do
|
34
|
+
it 'is the opposite of success' do
|
35
|
+
expect(response.failure?).to be(false)
|
36
|
+
expect(failure_response.failure?).to be(true)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '#message' do
|
41
|
+
it 'returns the message of the repsonse' do
|
42
|
+
expect(failure_response.message).to eq('Failed!')
|
43
|
+
expect(response.message).to eq('')
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '#guid' do
|
48
|
+
it 'returns the GUID from the response' do
|
49
|
+
expect(response.guid).to eq(guid)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe Seko::Stock do
|
3
|
+
|
4
|
+
describe '.parse' do
|
5
|
+
it 'returns the relevant stock info' do
|
6
|
+
expected_result = fixture(:stock)["Response"]["List"]["StockQuantityLineItem"]
|
7
|
+
response = Seko::Response.new(read_json(:stock))
|
8
|
+
expect(Seko::Stock.parse(response)).to eq(expected_result)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
data/spec/logs/spec.log
ADDED
File without changes
|