carousel-ruby-api 0.0.2 → 0.0.3

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 CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- OTI0ZWU1ZWU0NjFjY2QxOTkwN2RhMWM0ODUxMGM5NTY0ZWUyNjVlZA==
5
- data.tar.gz: !binary |-
6
- ZDUzOTJhODViOTUzZDE3MzhhY2FkMmQzMWQ1NjA2MDQ2MmFmOGY4YQ==
2
+ SHA1:
3
+ metadata.gz: 0607f6afe1f613f3d1a4dd544943245a1369622c
4
+ data.tar.gz: 95e533b637628ccd13dcbfbca702b2bd210b5605
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- M2ZkOGYwYWFjMGRiOTYyOGFmZDRhZWNlN2M0Yjg1YmVhNzFhOWMxN2RlMjdm
10
- MDRjOTdiYmE0ODliYzY4NDhkNjMwMWUyNzM4ZmRmNzMyNmU2YTlmNWMzYjE4
11
- NDYzZTkwOWY2YjhhMjI1ODlmODMzZWJhZjgwYTE1ZTgwNzI3N2Q=
12
- data.tar.gz: !binary |-
13
- NjM0MzczY2Q5YjNhMTZkNzYyY2IzYjEzNjlkM2M5OTNkNWI4NTJkZmE4NmU4
14
- MzYzNjUyNWU2NDg5NTI0NjFlM2UyMGUwZDQ0OGU4NmViMzk5OTczMjkxMDA1
15
- ZjQ4ZGFiNThlMDdhOWUxZGZkNzE5MzgyZjg3OTg1NjZjZWU5ZDk=
6
+ metadata.gz: 6869340ee67affff0b03f571933e7a974bd4f8e175a64a376d859cd9d5678335fe7de31c8548e82472b205110df91b70594927ae4a9276f7e8b26602245659a0
7
+ data.tar.gz: 7e2e6c202c7185eaa8eb7ae8c96daa9b19d5fe060765286782962edee818bbb8bde40419b989a2a9836ec7abe16775627f65955ff557cf6c98bc7522a639860a
data/.travis.yml CHANGED
@@ -6,15 +6,8 @@ matrix:
6
6
  allow_failures:
7
7
  - rvm: rbx-19mode
8
8
 
9
- services:
10
- - redis
11
-
12
9
  script:
13
- - bundle exec rake
14
-
15
- # addons:
16
- # code_climate:
17
- # repo_token: f0884115cadbe82b33756e38a9cd32d5129304746a17126d6c7da02e7a69910a
10
+ - CODECLIMATE_REPO_TOKEN=09bd983baf4d0c64d97c20a68baecde00cefb3db009a88792f23e3ce5eadf69a bundle exec rspec
18
11
 
19
12
  notifications:
20
13
  email:
data/README.md CHANGED
@@ -1,7 +1,8 @@
1
1
  # Carousel
2
2
 
3
- [![Build Status](https://travis-ci.org/jGRUBBS/carousel-ruby-api.svg?branch=master)](https://travis-ci.org/jGRUBBS/carousel-ruby-api)
4
- [![Code Climate](https://codeclimate.com/github/jGRUBBS/carousel-ruby-api.png)](https://codeclimate.com/github/jGRUBBS/carousel-ruby-api)
3
+ [![Build Status](https://travis-ci.org/jGRUBBS/carousel-ruby-api.svg)](https://travis-ci.org/jGRUBBS/carousel-ruby-api)
4
+ [![Code Climate](https://codeclimate.com/github/jGRUBBS/carousel-ruby-api/badges/gpa.svg)](https://codeclimate.com/github/jGRUBBS/carousel-ruby-api)
5
+ [![Test Coverage](https://codeclimate.com/github/jGRUBBS/carousel-ruby-api/badges/coverage.svg)](https://codeclimate.com/github/jGRUBBS/carousel-ruby-api)
5
6
 
6
7
  Ruby library for interfacing with the Carousel Fulfillment API
7
8
 
data/carousel.gemspec CHANGED
@@ -19,8 +19,10 @@ Gem::Specification.new do |spec|
19
19
  spec.add_dependency "builder"
20
20
  spec.add_dependency "xml-simple"
21
21
 
22
- spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "bundler", "~> 1.7"
23
23
  spec.add_development_dependency "rake"
24
24
  spec.add_development_dependency "rspec"
25
- spec.add_development_dependency "debugger"
25
+ spec.add_development_dependency "webmock"
26
+ spec.add_development_dependency "hashie"
27
+ spec.add_development_dependency "codeclimate-test-reporter"
26
28
  end
@@ -11,7 +11,7 @@ module Carousel
11
11
  PORT = 443
12
12
  KEYS_MAP = { "stockid" => "upc" }
13
13
 
14
- attr_accessor :username, :password, :response, :type, :request_uri, :path
14
+ attr_accessor :username, :password, :options, :response, :type, :request_uri, :path
15
15
 
16
16
  def initialize(username, password, options = {})
17
17
  raise "Username is required" unless username
@@ -30,7 +30,16 @@ module Carousel
30
30
  def get_inventory
31
31
  request = Inventory.new(self).build_inventory_request
32
32
  @path = build_path(Inventory::PATH)
33
- map_results(post(request).response['stock'])
33
+ inventory_response(request)
34
+ end
35
+
36
+ # gets the raw inventory response from the provider
37
+ # then converts provider specific language to match
38
+ # a uniform API, stored on @response, and returns
39
+ def inventory_response(request)
40
+ response = post(request)
41
+ response.response = map_results(response.response['stock'])
42
+ response
34
43
  end
35
44
 
36
45
  def order_request(order)
@@ -13,7 +13,7 @@ module Carousel
13
13
  xml.customerref order[:number]
14
14
  xml.ordernumber order[:number]
15
15
  xml.shippingmethod Shipping.map(order[:shipping_method])
16
- xml.giftnote order[:gift_message] if order[:gift_message].present?
16
+ xml.giftnote order[:gift_message] unless order[:gift_message].nil?
17
17
 
18
18
  build_address xml, order[:shipping_address], :shipping
19
19
  build_address xml, order[:billing_address], :billing
@@ -1,7 +1,7 @@
1
1
  module Carousel
2
2
  class Response
3
3
 
4
- attr_accessor :response
4
+ attr_accessor :response, :raw_response
5
5
 
6
6
  def initialize(raw_response, type)
7
7
  @raw_response = raw_response
@@ -14,14 +14,26 @@ module Carousel
14
14
  end
15
15
 
16
16
  def success?
17
- # FIXME: needs to give actual boolean parsed from response
18
- # @response.parsed["#{@type}_response"]["#{@type}_result"][:status] == '0001'
19
- true
17
+ status == "OK"
18
+ end
19
+
20
+ def status
21
+ if @kind == "stock"
22
+ @response.first["status"]
23
+ else
24
+ @response[@kind][0]["status"][0]
25
+ end
26
+ end
27
+
28
+ def message
29
+ @response["order"][0]["details"][0]
20
30
  end
21
31
 
22
32
  def parse_response(xml_response)
23
- return nil if xml_response.blank?
24
- XmlSimple.xml_in(xml_response)
33
+ return nil if xml_response.nil?
34
+ parsed = XmlSimple.xml_in(xml_response)
35
+ @kind = parsed.first[0]
36
+ parsed
25
37
  end
26
38
 
27
39
  end
@@ -1,3 +1,3 @@
1
1
  module Carousel
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <orders>
3
+ <order number="12345">
4
+ <status>ERROR</status>
5
+ <details>Bad postcode</details>
6
+ </order>
7
+ </orders>
@@ -0,0 +1,5 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <stock>
3
+ <user>the_username</user>
4
+ <password>the_password</password>
5
+ </stock>
@@ -0,0 +1,21 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <stocklines>
3
+ <stock>
4
+ <stockid>1000000003642</stockid>
5
+ <qty>3</qty>
6
+ <status>OK</status>
7
+ <details/>
8
+ </stock>
9
+ <stock>
10
+ <stockid>1000000003659</stockid>
11
+ <qty>2</qty>
12
+ <status>OK</status>
13
+ <details/>
14
+ </stock>
15
+ <stock>
16
+ <stockid>1000000003666</stockid>
17
+ <qty>2</qty>
18
+ <status>OK</status>
19
+ <details/>
20
+ </stock>
21
+ </stocklines>
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <orders>
3
+ <order number="12345">
4
+ <status>OK</status>
5
+ <details></details>
6
+ </order>
7
+ </orders>
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <name>Stephen Jones</name>
3
+ <addressline1>23 Victoria Street</addressline1>
4
+ <addressline2></addressline2>
5
+ <towncity>Windsor</towncity>
6
+ <postcode>SL4 1HE</postcode>
7
+ <country>UK</country>
8
+ <contactphone>0123 336 6676</contactphone>
@@ -0,0 +1,3 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <user>the_username</user>
3
+ <password>the_password</password>
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <orderline number="123456">
3
+ <ordernumber>123456</ordernumber>
4
+ <sku>100083</sku>
5
+ <qty>2</qty>
6
+ </orderline>
@@ -0,0 +1,29 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <orders>
3
+ <order>
4
+ <user>the_username</user>
5
+ <password>the_password</password>
6
+ <customerref>123456</customerref>
7
+ <ordernumber>123456</ordernumber>
8
+ <shippingmethod>ECONOMY</shippingmethod>
9
+ <name>Stephen Jones</name>
10
+ <addressline1>23 Victoria Street</addressline1>
11
+ <addressline2></addressline2>
12
+ <towncity>Windsor</towncity>
13
+ <postcode>SL4 1HE</postcode>
14
+ <country>UK</country>
15
+ <contactphone>0123 336 6676</contactphone>
16
+ <invname>Stephen Jones</invname>
17
+ <invaddressline1>23 Victoria Street</invaddressline1>
18
+ <invaddressline2></invaddressline2>
19
+ <invtowncity>Windsor</invtowncity>
20
+ <invpostcode>SL4 1HE</invpostcode>
21
+ <invcountry>UK</invcountry>
22
+ <invcontactphone>0123 336 6676</invcontactphone>
23
+ <orderline number="123456">
24
+ <ordernumber>123456</ordernumber>
25
+ <sku>100083</sku>
26
+ <qty>2</qty>
27
+ </orderline>
28
+ </order>
29
+ </orders>
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <order>
3
+ <test>test</test>
4
+ </order>
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <invname>Stephen Jones</invname>
3
+ <invaddressline1>23 Victoria Street</invaddressline1>
4
+ <invaddressline2></invaddressline2>
5
+ <invtowncity>Windsor</invtowncity>
6
+ <invpostcode>SL4 1HE</invpostcode>
7
+ <invcountry>UK</invcountry>
8
+ <invcontactphone>0123 336 6676</invcontactphone>
@@ -1,94 +1,290 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Carousel::Client do
4
- before do
5
- @client = Carousel::Client.new("the_username", "the_password")
4
+
5
+ let(:username) { "the_username" }
6
+ let(:password) { "the_password" }
7
+ let(:options) { { verbose: true, test_mode: true } }
8
+ let(:client) { Carousel::Client.new(username, password, options) }
9
+
10
+ describe '#initialize' do
11
+ it 'sets the @username, @password and @options' do
12
+ expect(client.username).to eq(username)
13
+ expect(client.password).to eq(password)
14
+ expect(client.options).to eq(options)
15
+ end
6
16
  end
7
17
 
8
18
  describe '#send_order_request' do
9
- it 'should send order request and return parsed respose' do
10
- Carousel::Order.any_instance.should_receive(:build_order_request).with(order_hash)
11
- @client.should_receive(:post)
12
- @client.send_order_request(order_hash)
19
+
20
+ let(:success_response) { read_xml(:success_order_response) }
21
+ let(:error_response) { read_xml(:error_order_response) }
22
+ let(:response) { client.send_order_request(order_hash) }
23
+
24
+ it 'parses a success response' do
25
+ stub_post("action=order").to_return(body: success_response)
26
+ expect(response.success?).to eq(true)
27
+ end
28
+
29
+ it 'parses an error response' do
30
+ stub_post("action=order").to_return(body: error_response)
31
+ expect(response.success?).to eq(false)
32
+ expect(response.message).to eq('Bad postcode')
33
+ end
34
+ end
35
+
36
+ describe 'inventory methods' do
37
+
38
+ let(:success_response) { read_xml(:success_inventory_response) }
39
+ let(:response) { client.get_inventory }
40
+ let(:expected_upcs) { ['1000000003642', '1000000003659', '1000000003666'] }
41
+ let(:expected_qtys) { ['3', '2', '2'] }
42
+ let(:raw_xml) { read_xml(:inventory_request) }
43
+
44
+ before do
45
+ stub_post("action=stocklines").with(body: raw_xml, headers: xml_headers)
46
+ .to_return(body: success_response)
47
+ end
48
+
49
+ describe '#get_inventory' do
50
+
51
+ it 'parses success response and maps results to simple array of stock hashes' do
52
+ expect(response.response.collect{ |s| s["upc"] }).to eq(expected_upcs)
53
+ expect(response.response.collect{ |s| s["qty"] }).to eq(expected_qtys)
54
+ expect(response.success?).to eq(true)
55
+ end
56
+ end
57
+
58
+ describe '#inventory_response' do
59
+
60
+ it 'gets the raw inventory response from the provider' do
61
+ expect(response.raw_response).to eq(success_response)
62
+ end
63
+
64
+ it 'converts provider specific language to match a uniform API' do
65
+ original_response = client.send(:parse_response, success_response).response["stock"]
66
+ expect(original_response.first.keys).to include('stockid')
67
+ expect(response.response.first.keys).to include('upc')
68
+ end
69
+
70
+ it 'returns a response' do
71
+ expect(response).to be_a(Carousel::Response)
72
+ end
73
+
74
+ end
75
+
76
+ end
77
+
78
+ describe '#order_request' do
79
+ it 'sets the path instance variable' do
80
+ client.order_request(order_hash)
81
+ expect(client.instance_variable_get(:@path)).to eq("/carouselwms/default.asp?action=order")
82
+ end
83
+ it 'returns a built request for Order' do
84
+ order_xml = read_xml(:test_order)
85
+ expect(client.order_request(order_hash)).to eq(order_xml)
86
+ end
87
+ end
88
+
89
+ describe '#build_path' do
90
+ it 'builds and returns the uri path' do
91
+ expect(client).to receive(:env_path).and_return("carouselwms")
92
+ expect(client.build_path("?action=stocklines")).to eq("/carouselwms/default.asp?action=stocklines")
93
+ end
94
+ end
95
+
96
+ describe '#upcs' do
97
+ it 'returns an array of the collected upcs' do
98
+ inventory = [{"upc" => "123"}, {"upc" => "123456"}]
99
+ expect(client.upcs(inventory)).to eq(["123", "123456"])
100
+ end
101
+ end
102
+
103
+ describe '#mapped_inventory' do
104
+ it 'converts provider specific terms into a uniform API' do
105
+ inventory = [{"upc" => "123", "qty" => "3"}, {"upc" => "123456", "qty" => "0"}]
106
+ upcs = ["123"]
107
+ expect(client.mapped_inventory(upcs, inventory)).to eq([{quantity: 3}])
108
+ end
109
+ end
110
+
111
+ describe '#request_uri' do
112
+ it 'returns the request uri based on host and path' do
113
+ client.path = "?action=stocklines"
114
+ expect(client.request_uri).to eq("https://web.carousel.eu?action=stocklines")
13
115
  end
14
116
  end
15
117
 
16
118
  describe 'private#default_options' do
17
- it 'should return a hash' do
18
- @client.send(:default_options).should be_a Hash
119
+ it 'returns the default options for a Client' do
120
+ default_options = {
121
+ verbose: true,
122
+ test_mode: false
123
+ }
124
+ expect(client.send(:default_options)).to eq(default_options)
19
125
  end
20
126
  end
21
127
 
22
128
  describe 'private#testing?' do
23
- it 'should return boolean for test mode' do
24
- @client.send(:testing?).should be_false
25
- @client.instance_variable_set(:@options, { test_mode: true })
26
- @client.send(:testing?).should be_true
129
+ context 'not in testing mode' do
130
+ it 'returns false' do
131
+ client.options[:test_mode] = false
132
+ expect(client.send(:testing?)).to eq(false)
133
+ end
134
+ end
135
+ context 'in testing mode' do
136
+ it 'returns true' do
137
+ expect(client.send(:testing?)).to eq(true)
138
+ end
27
139
  end
28
140
  end
29
141
 
30
142
  describe 'private#verbose?' do
31
- it 'should return boolean for verbose mode' do
32
- @client.send(:verbose?).should be_true
33
- @client.instance_variable_set(:@options, { verbose: false })
34
- @client.send(:verbose?).should be_false
143
+ context 'not in verbose mode' do
144
+ it 'returns false' do
145
+ client.options[:verbose] = false
146
+ expect(client.send(:verbose?)).to eq(false)
147
+ end
148
+ end
149
+ context 'in verbose mode' do
150
+ it 'returns true' do
151
+ expect(client.send(:verbose?)).to eq(true)
152
+ end
35
153
  end
36
154
  end
37
155
 
38
- describe 'private#host' do
39
- it 'should' do
40
- @client.stub(:testing?).and_return(false)
41
- @client.send(:host).should == Carousel::Client::LIVE_HOST
42
- @client.stub(:testing?).and_return(true)
43
- @client.send(:host).should == Carousel::Client::TEST_HOST
156
+ describe 'private#env_path' do
157
+ context 'not in testing mode' do
158
+ it 'returns the LIVE_PATH' do
159
+ client.options[:test_mode] = false
160
+ expect(client.send(:env_path)).to eq(Carousel::Client::LIVE_PATH)
161
+ end
162
+ end
163
+ context 'in testing mode' do
164
+ it 'returns TEST_PATH' do
165
+ expect(client.send(:env_path)).to eq(Carousel::Client::TEST_PATH)
166
+ end
44
167
  end
45
168
  end
46
169
 
47
- describe 'private#path' do
48
- it 'should' do
49
- @client.stub(:testing?).and_return(false)
50
- @client.send(:path).should == Carousel::Client::LIVE_PATH
51
- @client.stub(:testing?).and_return(true)
52
- @client.send(:path).should == Carousel::Client::TEST_PATH
170
+ describe 'private#host' do
171
+ context 'not in testing mode' do
172
+ it 'returns the LIVE_PATH' do
173
+ client.options[:test_mode] = false
174
+ expect(client.send(:host)).to eq(Carousel::Client::LIVE_HOST)
175
+ end
176
+ end
177
+ context 'in testing mode' do
178
+ it 'returns TEST_PATH' do
179
+ expect(client.send(:host)).to eq(Carousel::Client::TEST_HOST)
180
+ end
53
181
  end
54
182
  end
55
183
 
56
184
  describe 'private#log' do
185
+ before do
186
+ @message = "test"
187
+ end
57
188
  context 'not in verbose mode' do
58
- it 'should not log message' do
59
- @client.stub(:verbose?).and_return(false)
60
- @client.should_not_receive(:puts)
61
- @client.send(:log, "message")
189
+ it 'returns nil' do
190
+ expect(client.send(:log, @message)).to eq(nil)
62
191
  end
63
192
  end
64
193
  context 'in verbose mode' do
65
- it 'should' do
66
- @client.stub(:verbose?).and_return(true)
67
- @client.should_receive(:puts).with("message")
68
- @client.send(:log, "message")
194
+ it 'logs the message to STDOUT' do
195
+ client.options[:verbose] = true
196
+ output = capture_stdout { client.send(:log, @message) }
197
+ expect(output).to eq("test\n")
69
198
  end
70
199
  end
71
200
  end
72
201
 
202
+ describe 'private#http' do
203
+ it 'returns an instance of Net::HTTP' do
204
+ http = client.send(:http)
205
+ host = client.send(:host)
206
+ expect(http).to be_an_instance_of(Net::HTTP)
207
+ expect(http.address).to eq(host)
208
+ expect(http.port).to eq(Carousel::Client::PORT)
209
+ end
210
+ end
211
+
212
+ describe 'private#request' do
213
+
214
+ let(:success_response) { read_xml(:success_inventory_response) }
215
+ let(:request) { read_xml(:inventory_request) }
216
+
217
+ it 'sets the ssl and verify mode, sends an http request, and returns a response object' do
218
+ client.path = "?action=stocklines"
219
+ expect(client.send(:http)).to receive(:request).and_return(success_response)
220
+ expect(client.send(:request, request)).to eq(success_response)
221
+ expect(client.send(:http).use_ssl?).to be(true)
222
+ expect(client.send(:http).verify_mode).to eq(OpenSSL::SSL::VERIFY_NONE)
223
+ end
224
+ end
225
+
73
226
  describe 'private#post' do
74
- it 'should use net http to post xml request' do
75
- path = @client.send(:path)
76
- xml_request = "xml_request"
77
- response = Carousel::Response.new("<xml>body</xml>", "new_request")
78
- header = {'Content-Type' => 'text/xml'}
79
- Net::HTTP.any_instance.should_receive(:post).with(path, xml_request, header).and_return(response)
80
- @client.should_receive(:parse_response).with(response, nil)
81
- @client.should_receive(:log).with(response)
82
- @client.send(:post, xml_request)
227
+ let(:request) { read_xml(:inventory_request) }
228
+ let(:response) { read_xml(:success_inventory_response) }
229
+
230
+ before do
231
+ client.path = "?action=stocklines"
232
+ end
233
+
234
+ it 'sends a post request' do
235
+ expect(client).to receive(:request).and_return(fake_response)
236
+ client.send(:post, request)
237
+ end
238
+ it 'parses response into a Carousel::Response object' do
239
+ expect(client).to receive(:request).and_return(fake_response)
240
+ expect(client.send(:post, request)).to be_a(Carousel::Response)
83
241
  end
84
242
  end
85
243
 
86
244
  describe 'private#parse_response' do
87
- it 'should use xml simple to parse the response' do
88
- xml_response = "xml_response"
89
- XmlSimple.should_receive(:xml_in).with(xml_response)
90
- response = @client.send(:parse_response, xml_response)
91
- response.should be_a Carousel::Response
245
+ let(:response) { read_xml(:success_inventory_response) }
246
+
247
+ it 'logs the response' do
248
+ client.options[:verbose] = true
249
+ expect(client).to receive(:log).with(response)
250
+ client.send(:parse_response, response)
251
+ end
252
+
253
+ it 'parses response into a Carousel::Response object' do
254
+ expect(client.send(:parse_response, response)).to be_a(Carousel::Response)
255
+ end
256
+ end
257
+
258
+ describe 'private#map_results' do
259
+ it 'flattens the results and maps them' do
260
+ results = [{test: [1,2,3]}, {example: [2,3,4]}, {test: [1,2,3], stockid: [5,6,7,8]}]
261
+ expected_result = [{test: 1}, {example: 2}, {test: 1, stockid: 5}]
262
+
263
+ expect(client).to receive(:flatten_results).and_return(expected_result)
264
+ expect(client.send(:map_results, results)).to eq(expected_result)
265
+ end
266
+ end
267
+
268
+ describe 'private#flatten_results' do
269
+ it 'sets the value for each hash key to the first item in the value array' do
270
+ results = [{test: [1,2,3]}, {example: [2,3,4]}, {test: [1,2,3], example: [5,6,7,8]}]
271
+ expected_result = [{test: 1}, {example: 2}, {test: 1, example: 5}]
272
+ expect(client.send(:flatten_results, results)).to eq(expected_result)
273
+ end
274
+ end
275
+
276
+ describe 'private#map_keys' do
277
+ context 'with a key in the KEYS_MAP' do
278
+ it 'returns the value for the given key' do
279
+ key = "stockid"
280
+ expect(client.send(:map_keys, key)).to eq(Carousel::Client::KEYS_MAP[key])
281
+ end
282
+ end
283
+ context 'without a key in the KEYS_MAP' do
284
+ it 'returns the key' do
285
+ key = "test"
286
+ expect(client.send(:map_keys, key)).to eq(key)
287
+ end
92
288
  end
93
289
  end
94
290
 
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe Carousel::Country do
4
+
5
+
6
+ describe '.map' do
7
+ context 'with the code in the COUNTRY_MAP' do
8
+ it 'returns the value for the given code' do
9
+ expect(Carousel::Country.map("US")).to eq("US")
10
+ end
11
+ end
12
+ context 'without the code in the COUNTRY_MAP' do
13
+ it 'returns the given code' do
14
+ expect(Carousel::Country.map("AAA")).to eq("AAA")
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe Carousel::Inventory do
4
+
5
+ let(:client) { Carousel::Client.new("the_username", "the_password") }
6
+ let(:inventory_request) { Carousel::Inventory.new(client) }
7
+
8
+ describe '#build_inventory_request' do
9
+ it 'constructs xml for the user' do
10
+ expect(inventory_request.build_inventory_request).to eq(read_xml(:inventory_request))
11
+ end
12
+ end
13
+ end