shipwire 0.0.5 → 2.0.0

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.
Files changed (186) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -3
  3. data/.rspec +2 -0
  4. data/.ruby-version +1 -1
  5. data/Gemfile +0 -1
  6. data/README.md +53 -29
  7. data/Rakefile +2 -3
  8. data/lib/generators/shipwire/install/install_generator.rb +13 -0
  9. data/lib/generators/shipwire/install/templates/config/initializers/shipwire.rb +27 -0
  10. data/lib/shipwire.rb +26 -33
  11. data/lib/shipwire/api.rb +7 -0
  12. data/lib/shipwire/configuration.rb +13 -3
  13. data/lib/shipwire/orders.rb +39 -0
  14. data/lib/shipwire/param_converter.rb +39 -0
  15. data/lib/shipwire/products.rb +53 -0
  16. data/lib/shipwire/products/base.rb +9 -0
  17. data/lib/shipwire/products/insert.rb +9 -0
  18. data/lib/shipwire/products/kit.rb +9 -0
  19. data/lib/shipwire/products/virtual_kit.rb +9 -0
  20. data/lib/shipwire/rate.rb +7 -0
  21. data/lib/shipwire/receivings.rb +50 -0
  22. data/lib/shipwire/request.rb +73 -0
  23. data/lib/shipwire/response.rb +79 -0
  24. data/lib/shipwire/returns.rb +35 -0
  25. data/lib/shipwire/secret.rb +20 -0
  26. data/lib/shipwire/stock.rb +7 -0
  27. data/lib/shipwire/utility.rb +22 -0
  28. data/lib/shipwire/version.rb +1 -1
  29. data/lib/shipwire/webhooks.rb +24 -0
  30. data/shipwire.gemspec +12 -15
  31. data/spec/features/access_spec.rb +61 -0
  32. data/spec/features/orders_spec.rb +280 -0
  33. data/spec/features/product_types_spec.rb +219 -0
  34. data/spec/features/products_spec.rb +282 -0
  35. data/spec/features/rate_spec.rb +50 -0
  36. data/spec/features/receivings_spec.rb +333 -0
  37. data/spec/features/returns_spec.rb +239 -0
  38. data/spec/features/secret_spec.rb +57 -0
  39. data/spec/features/stock_spec.rb +41 -0
  40. data/spec/features/webhooks_spec.rb +106 -0
  41. data/spec/spec_helper.rb +33 -12
  42. data/spec/support/shipwire.rb +10 -0
  43. data/spec/support/vcr.rb +9 -0
  44. data/spec/support/vcr_cassettes/credentials_incorrect.yml +47 -0
  45. data/spec/support/vcr_cassettes/credentials_missing.yml +47 -0
  46. data/spec/support/vcr_cassettes/order.yml +48 -0
  47. data/spec/support/vcr_cassettes/order_cancel.yml +54 -0
  48. data/spec/support/vcr_cassettes/order_cancel_fail.yml +47 -0
  49. data/spec/support/vcr_cassettes/order_find.yml +45 -0
  50. data/spec/support/vcr_cassettes/order_find_fail.yml +45 -0
  51. data/spec/support/vcr_cassettes/order_find_with_params.yml +45 -0
  52. data/spec/support/vcr_cassettes/order_holds.yml +50 -0
  53. data/spec/support/vcr_cassettes/order_holds_fail.yml +45 -0
  54. data/spec/support/vcr_cassettes/order_holds_with_params.yml +50 -0
  55. data/spec/support/vcr_cassettes/order_items.yml +45 -0
  56. data/spec/support/vcr_cassettes/order_items_fail.yml +45 -0
  57. data/spec/support/vcr_cassettes/order_returns.yml +47 -0
  58. data/spec/support/vcr_cassettes/order_returns_fail.yml +47 -0
  59. data/spec/support/vcr_cassettes/order_trackings.yml +45 -0
  60. data/spec/support/vcr_cassettes/order_trackings_fail.yml +45 -0
  61. data/spec/support/vcr_cassettes/order_update.yml +48 -0
  62. data/spec/support/vcr_cassettes/order_update_fail.yml +50 -0
  63. data/spec/support/vcr_cassettes/order_update_with_params.yml +48 -0
  64. data/spec/support/vcr_cassettes/order_with_warnings.yml +96 -0
  65. data/spec/support/vcr_cassettes/orders_list.yml +47 -0
  66. data/spec/support/vcr_cassettes/orders_list_with_params.yml +47 -0
  67. data/spec/support/vcr_cassettes/product.yml +48 -0
  68. data/spec/support/vcr_cassettes/product_base.yml +48 -0
  69. data/spec/support/vcr_cassettes/product_base_find.yml +48 -0
  70. data/spec/support/vcr_cassettes/product_base_find_fail.yml +47 -0
  71. data/spec/support/vcr_cassettes/product_base_retire_id.yml +47 -0
  72. data/spec/support/vcr_cassettes/product_base_retire_nonexistent.yml +47 -0
  73. data/spec/support/vcr_cassettes/product_base_update.yml +48 -0
  74. data/spec/support/vcr_cassettes/product_base_update_fail.yml +48 -0
  75. data/spec/support/vcr_cassettes/product_create_fail_with_invalid_classification.yml +51 -0
  76. data/spec/support/vcr_cassettes/product_find.yml +48 -0
  77. data/spec/support/vcr_cassettes/product_find_fail.yml +47 -0
  78. data/spec/support/vcr_cassettes/product_insert.yml +50 -0
  79. data/spec/support/vcr_cassettes/product_insert_find.yml +48 -0
  80. data/spec/support/vcr_cassettes/product_insert_find_fail.yml +47 -0
  81. data/spec/support/vcr_cassettes/product_insert_retire_id.yml +47 -0
  82. data/spec/support/vcr_cassettes/product_insert_retire_nonexistent.yml +47 -0
  83. data/spec/support/vcr_cassettes/product_insert_update.yml +49 -0
  84. data/spec/support/vcr_cassettes/product_insert_update_fail.yml +48 -0
  85. data/spec/support/vcr_cassettes/product_kit.yml +48 -0
  86. data/spec/support/vcr_cassettes/product_kit_find.yml +48 -0
  87. data/spec/support/vcr_cassettes/product_kit_find_fail.yml +47 -0
  88. data/spec/support/vcr_cassettes/product_kit_retire_id.yml +47 -0
  89. data/spec/support/vcr_cassettes/product_kit_retire_nonexistent.yml +47 -0
  90. data/spec/support/vcr_cassettes/product_kit_update.yml +48 -0
  91. data/spec/support/vcr_cassettes/product_kit_update_fail.yml +47 -0
  92. data/spec/support/vcr_cassettes/product_multiple_create_fail.yml +102 -0
  93. data/spec/support/vcr_cassettes/product_multiple_create_success.yml +100 -0
  94. data/spec/support/vcr_cassettes/product_retire_id.yml +47 -0
  95. data/spec/support/vcr_cassettes/product_retire_nonexistent.yml +47 -0
  96. data/spec/support/vcr_cassettes/product_update.yml +48 -0
  97. data/spec/support/vcr_cassettes/product_update_fail.yml +48 -0
  98. data/spec/support/vcr_cassettes/product_virtual_kit.yml +48 -0
  99. data/spec/support/vcr_cassettes/product_virtual_kit_find.yml +48 -0
  100. data/spec/support/vcr_cassettes/product_virtual_kit_find_fail.yml +47 -0
  101. data/spec/support/vcr_cassettes/product_virtual_kit_retire_id.yml +47 -0
  102. data/spec/support/vcr_cassettes/product_virtual_kit_retire_nonexistent.yml +47 -0
  103. data/spec/support/vcr_cassettes/product_virtual_kit_update.yml +49 -0
  104. data/spec/support/vcr_cassettes/product_virtual_kit_update_fail.yml +47 -0
  105. data/spec/support/vcr_cassettes/products_base_list.yml +49 -0
  106. data/spec/support/vcr_cassettes/products_base_list_with_params.yml +49 -0
  107. data/spec/support/vcr_cassettes/products_insert_list.yml +47 -0
  108. data/spec/support/vcr_cassettes/products_insert_list_with_params.yml +47 -0
  109. data/spec/support/vcr_cassettes/products_kit_list.yml +47 -0
  110. data/spec/support/vcr_cassettes/products_kit_list_with_params.yml +47 -0
  111. data/spec/support/vcr_cassettes/products_list.yml +49 -0
  112. data/spec/support/vcr_cassettes/products_list_with_params.yml +49 -0
  113. data/spec/support/vcr_cassettes/products_virtual_kit_list.yml +47 -0
  114. data/spec/support/vcr_cassettes/products_virtual_kit_list_with_params.yml +47 -0
  115. data/spec/support/vcr_cassettes/rate_find.yml +53 -0
  116. data/spec/support/vcr_cassettes/rate_find_fail.yml +50 -0
  117. data/spec/support/vcr_cassettes/receiving.yml +53 -0
  118. data/spec/support/vcr_cassettes/receiving_cancel.yml +98 -0
  119. data/spec/support/vcr_cassettes/receiving_cancel_label.yml +47 -0
  120. data/spec/support/vcr_cassettes/receiving_cancel_label_nonexistent.yml +47 -0
  121. data/spec/support/vcr_cassettes/receiving_find.yml +46 -0
  122. data/spec/support/vcr_cassettes/receiving_find_fail.yml +45 -0
  123. data/spec/support/vcr_cassettes/receiving_find_with_params.yml +48 -0
  124. data/spec/support/vcr_cassettes/receiving_holds.yml +47 -0
  125. data/spec/support/vcr_cassettes/receiving_holds_fail.yml +45 -0
  126. data/spec/support/vcr_cassettes/receiving_holds_with_params.yml +47 -0
  127. data/spec/support/vcr_cassettes/receiving_instructions_recipients.yml +45 -0
  128. data/spec/support/vcr_cassettes/receiving_instructions_recipients_fail.yml +45 -0
  129. data/spec/support/vcr_cassettes/receiving_items.yml +45 -0
  130. data/spec/support/vcr_cassettes/receiving_items_fail.yml +45 -0
  131. data/spec/support/vcr_cassettes/receiving_shipments.yml +45 -0
  132. data/spec/support/vcr_cassettes/receiving_shipments_fail.yml +45 -0
  133. data/spec/support/vcr_cassettes/receiving_tracking.yml +45 -0
  134. data/spec/support/vcr_cassettes/receiving_tracking_fail.yml +45 -0
  135. data/spec/support/vcr_cassettes/receiving_update.yml +53 -0
  136. data/spec/support/vcr_cassettes/receiving_update_fail.yml +49 -0
  137. data/spec/support/vcr_cassettes/receiving_update_with_params.yml +55 -0
  138. data/spec/support/vcr_cassettes/receivings_list.yml +53 -0
  139. data/spec/support/vcr_cassettes/receivings_list_with_params.yml +46 -0
  140. data/spec/support/vcr_cassettes/return.yml +98 -0
  141. data/spec/support/vcr_cassettes/return_cancel.yml +55 -0
  142. data/spec/support/vcr_cassettes/return_cancel_fail.yml +47 -0
  143. data/spec/support/vcr_cassettes/return_find.yml +47 -0
  144. data/spec/support/vcr_cassettes/return_find_fail.yml +45 -0
  145. data/spec/support/vcr_cassettes/return_find_with_params.yml +47 -0
  146. data/spec/support/vcr_cassettes/return_holds.yml +45 -0
  147. data/spec/support/vcr_cassettes/return_holds_fail.yml +45 -0
  148. data/spec/support/vcr_cassettes/return_holds_with_params.yml +45 -0
  149. data/spec/support/vcr_cassettes/return_items.yml +45 -0
  150. data/spec/support/vcr_cassettes/return_items_fail.yml +45 -0
  151. data/spec/support/vcr_cassettes/return_labels.yml +45 -0
  152. data/spec/support/vcr_cassettes/return_labels_fail.yml +45 -0
  153. data/spec/support/vcr_cassettes/return_trackings.yml +45 -0
  154. data/spec/support/vcr_cassettes/return_trackings_fail.yml +45 -0
  155. data/spec/support/vcr_cassettes/returns_list.yml +47 -0
  156. data/spec/support/vcr_cassettes/returns_list_with_params.yml +47 -0
  157. data/spec/support/vcr_cassettes/secret.yml +47 -0
  158. data/spec/support/vcr_cassettes/secret_find.yml +45 -0
  159. data/spec/support/vcr_cassettes/secret_find_fail.yml +43 -0
  160. data/spec/support/vcr_cassettes/secret_list.yml +45 -0
  161. data/spec/support/vcr_cassettes/secret_remove.yml +45 -0
  162. data/spec/support/vcr_cassettes/stock_with_params.yml +45 -0
  163. data/spec/support/vcr_cassettes/stock_with_params_no_sku.yml +45 -0
  164. data/spec/support/vcr_cassettes/stock_without_params.yml +45 -0
  165. data/spec/support/vcr_cassettes/webhook.yml +47 -0
  166. data/spec/support/vcr_cassettes/webhooks_create_insecure.yml +50 -0
  167. data/spec/support/vcr_cassettes/webhooks_find.yml +47 -0
  168. data/spec/support/vcr_cassettes/webhooks_find_fail.yml +47 -0
  169. data/spec/support/vcr_cassettes/webhooks_list.yml +47 -0
  170. data/spec/support/vcr_cassettes/webhooks_remove.yml +47 -0
  171. data/spec/support/vcr_cassettes/webhooks_update.yml +47 -0
  172. data/spec/support/vcr_cassettes/webhooks_update_fail.yml +49 -0
  173. data/spec/unit/shipwire/response_spec.rb +46 -0
  174. metadata +354 -80
  175. data/.env +0 -4
  176. data/.env.example +0 -4
  177. data/Gemfile.lock +0 -69
  178. data/lib/shipwire/fulfillment.rb +0 -100
  179. data/lib/shipwire/inventory.rb +0 -72
  180. data/lib/shipwire/service_request.rb +0 -42
  181. data/lib/shipwire/shipping_rate.rb +0 -121
  182. data/lib/shipwire/tracking.rb +0 -101
  183. data/spec/shipwire/fulfillment_spec.rb +0 -36
  184. data/spec/shipwire/inventory_spec.rb +0 -25
  185. data/spec/shipwire/shipping_rate_spec.rb +0 -62
  186. data/spec/shipwire/tracking_spec.rb +0 -20
@@ -0,0 +1,282 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe "Product", type: :feature, vcr: true do
4
+ context "list" do
5
+ context "without params" do
6
+ it "is successful" do
7
+ VCR.use_cassette("products_list") do
8
+ response = Shipwire::Products.new.list
9
+
10
+ expect(response.ok?).to be_truthy
11
+ end
12
+ end
13
+ end
14
+
15
+ context "with params" do
16
+ it "is successful" do
17
+ VCR.use_cassette("products_list_with_params") do
18
+ response = Shipwire::Products.new.list(
19
+ sku: "TEST-PRODUCT"
20
+ )
21
+
22
+ expect(response.ok?).to be_truthy
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ context "management" do
29
+ let!(:product) do
30
+ VCR.use_cassette("product") do
31
+ Shipwire::Products.new.create(product_payload)
32
+ end
33
+ end
34
+
35
+ context "create" do
36
+ context "multiple products types" do
37
+ it "is successful" do
38
+ VCR.use_cassette("product_multiple_create_success") do
39
+ payload = [
40
+ product_payload,
41
+ product_payload("insert"),
42
+ product_payload("kit"),
43
+ product_payload("virtual_kit")
44
+ ]
45
+
46
+ response = Shipwire::Products.new.create(payload)
47
+
48
+ expect(response.ok?).to be_truthy
49
+ expect(response.body["resource"]["items"].count).to eq 4
50
+
51
+ # Retire products just created
52
+ items = response.body["resource"]["items"]
53
+ retire_array = items.each_with_object([]) do |item, hsh|
54
+ hsh << item["resource"]["id"]
55
+ end
56
+ Shipwire::Products.new.retire(retire_array)
57
+ end
58
+ end
59
+
60
+ it "parts fail when classification is wrong" do
61
+ VCR.use_cassette("product_multiple_create_fail") do
62
+ payload = [
63
+ product_payload,
64
+ product_payload("insert"),
65
+ product_payload("kit"),
66
+ product_payload("virtual_kit")
67
+ ]
68
+
69
+ payload[0].deeper_merge!(
70
+ classification: "fake"
71
+ )
72
+
73
+ response = Shipwire::Products.new.create(payload)
74
+
75
+ expect(response.ok?).to be_falsy
76
+ expect(response.body["resource"]["items"].count).to eq 3
77
+ expect(response.validation_errors.first).to include(
78
+ "message" =>
79
+ "Product Classification not detected. " +
80
+ "Please pass classification for each product."
81
+ )
82
+
83
+ # Retire products just created
84
+ items = response.body["resource"]["items"]
85
+ retire_array = items.each_with_object([]) do |item, hsh|
86
+ hsh << item["resource"]["id"]
87
+ end
88
+ Shipwire::Products.new.retire(retire_array)
89
+ end
90
+ end
91
+ end
92
+
93
+ it "fails when classification is not valid" do
94
+ VCR.use_cassette("product_create_fail_with_invalid_classification") do
95
+ payload = product_payload.deeper_merge!(
96
+ classification: "fake"
97
+ )
98
+
99
+ response = Shipwire::Products.new.create(payload)
100
+
101
+ expect(response.ok?).to be_falsy
102
+ expect(response.validation_errors.first).to include(
103
+ "message" =>
104
+ "Product Classification not detected. " +
105
+ "Please pass classification for each product."
106
+ )
107
+ end
108
+ end
109
+ end
110
+
111
+ context "find" do
112
+ it "is successful" do
113
+ VCR.use_cassette("product_find") do
114
+ product_id = product.body["resource"]["items"].first["resource"]["id"]
115
+
116
+ response = Shipwire::Products.new.find(product_id)
117
+
118
+ expect(response.ok?).to be_truthy
119
+ end
120
+ end
121
+
122
+ it "fails when id does not exist" do
123
+ VCR.use_cassette("product_find_fail") do
124
+ response = Shipwire::Products.new.find(0)
125
+
126
+ expect(response.ok?).to be_falsy
127
+ expect(response.error_summary).to eq 'Product not found.'
128
+ end
129
+ end
130
+ end
131
+
132
+ context "update" do
133
+ it "is successful" do
134
+ VCR.use_cassette("product_update") do
135
+ product_id = product.body["resource"]["items"].first["resource"]["id"]
136
+
137
+ payload = product_payload.deeper_merge!(
138
+ description: "Super awesome description"
139
+ )
140
+
141
+ response = Shipwire::Products.new.update(product_id, payload)
142
+
143
+ expect(response.ok?).to be_truthy
144
+ end
145
+ end
146
+
147
+ it "fails when id does not exist" do
148
+ VCR.use_cassette("product_update_fail") do
149
+ payload = product_payload.deeper_merge!(
150
+ description: "Super awesome description"
151
+ )
152
+
153
+ response = Shipwire::Products.new.update(0, payload)
154
+
155
+ expect(response.ok?).to be_falsy
156
+ expect(response.error_summary).to eq 'Product not found.'
157
+ end
158
+ end
159
+ end
160
+
161
+ context "retire" do
162
+ context "with string passed" do
163
+ it "is successful" do
164
+ VCR.use_cassette("product_retire_id") do
165
+ product_id =
166
+ product.body["resource"]["items"].first["resource"]["id"]
167
+
168
+ response = Shipwire::Products.new.retire(product_id)
169
+
170
+ expect(response.ok?).to be_truthy
171
+ end
172
+ end
173
+ end
174
+
175
+ context "with array passed" do
176
+ it "is successful" do
177
+ VCR.use_cassette("product_retire_id") do
178
+ product_id =
179
+ product.body["resource"]["items"].first["resource"]["id"]
180
+
181
+ response = Shipwire::Products.new.retire([product_id, 0])
182
+
183
+ expect(response.ok?).to be_truthy
184
+ end
185
+ end
186
+ end
187
+
188
+ context "when product does not exist" do
189
+ it "is successful" do
190
+ VCR.use_cassette("product_retire_nonexistent") do
191
+ response = Shipwire::Products.new.retire(0)
192
+
193
+ expect(response.ok?).to be_truthy
194
+ end
195
+ end
196
+ end
197
+ end
198
+
199
+ # NOTE: This is ugly and massive and I know it. I'm down to change it.
200
+ def product_payload(type = "base")
201
+ payload = {
202
+ sku: FFaker::Product.model,
203
+ externalId: FFaker::Product.model,
204
+ description: FFaker::Product.product,
205
+ classification: "baseProduct",
206
+ category: "OTHER",
207
+ batteryConfiguration: "NOBATTERY",
208
+ values: {
209
+ costValue: 1,
210
+ retailValue: 4
211
+ },
212
+ dimensions: {
213
+ length: 1,
214
+ width: 1,
215
+ height: 1,
216
+ weight: 1
217
+ },
218
+ flags: {
219
+ isPackagedReadyToShip: 1,
220
+ isFragile: 0,
221
+ isDangerous: 0,
222
+ isPerishable: 0,
223
+ isLiquid: 0,
224
+ isMedia: 0,
225
+ isAdult: 0,
226
+ hasInnerPack: 0,
227
+ hasMasterCase: 0,
228
+ hasPallet: 0
229
+ }
230
+ }
231
+
232
+ product_contents = [
233
+ {
234
+ externalId: "TEST-PRODUCT",
235
+ quantity: 1
236
+ },
237
+ {
238
+ externalId: "TEST-PRODUCT2",
239
+ quantity: 1
240
+ }
241
+ ]
242
+
243
+ case type
244
+ when "insert"
245
+ payload.deeper_merge!(
246
+ classification: "marketingInsert",
247
+ dimensions: {
248
+ height: 0.1,
249
+ weight: 0.1
250
+ },
251
+ masterCase: {
252
+ individualItemsPerCase: 1,
253
+ sku: FFaker::Product.model,
254
+ description: FFaker::Product.product,
255
+ dimensions: {
256
+ length: 1,
257
+ width: 1,
258
+ height: 1,
259
+ weight: 1
260
+ }
261
+ },
262
+ inclusionRules: {
263
+ insertWhenWorthCurrency: "USD"
264
+ }
265
+ )
266
+ when "kit"
267
+ payload.deeper_merge!(
268
+ classification: "kit",
269
+ kitContent: product_contents
270
+ )
271
+
272
+ when "virtual_kit"
273
+ payload.deeper_merge!(
274
+ classification: "virtualKit",
275
+ virtualKitContent: product_contents
276
+ )
277
+ end
278
+
279
+ payload
280
+ end
281
+ end
282
+ end
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe "Rate", type: :feature, vcr: true do
4
+ context "find" do
5
+ it "is successful with existing items" do
6
+ VCR.use_cassette("rate_find") do
7
+ response = Shipwire::Rate.new.find(payload)
8
+
9
+ expect(response.ok?).to be_truthy
10
+ expect(response.body["resource"]["rates"].count).to be >= 1
11
+ end
12
+ end
13
+
14
+ it "fails with non existing items" do
15
+ VCR.use_cassette("rate_find_fail") do
16
+ bad_payload = payload
17
+ bad_payload[:order][:items][0][:sku] = 'FAKE-PRODUCT'
18
+
19
+ response = Shipwire::Rate.new.find(bad_payload)
20
+
21
+ expect(response.ok?).to be_falsy
22
+ expect(response.validation_errors.first).to include(
23
+ "message" => "unknown SKU 'FAKE-PRODUCT'"
24
+ )
25
+ end
26
+ end
27
+
28
+ def payload
29
+ {
30
+ options: {
31
+ currency: "USD",
32
+ groupBy: "all"
33
+ },
34
+ order: {
35
+ shipTo: {
36
+ address1: "540 West Boylston St.",
37
+ city: "Worcester",
38
+ postalCode: "01606",
39
+ region: "MA",
40
+ country: "US"
41
+ },
42
+ items: [{
43
+ sku: "TEST-PRODUCT",
44
+ quantity: 1
45
+ }]
46
+ }
47
+ }
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,333 @@
1
+ require 'spec_helper'
2
+ require 'date'
3
+
4
+ RSpec.describe "Receivings", type: :feature, vcr: true do
5
+ # Creating, updating, and canceling take an uncommonly long time on Shipwire's
6
+ # end. Update the timeout to be safe.
7
+ before { Shipwire.configuration.timeout = 10 }
8
+
9
+ context "list" do
10
+ context "without params" do
11
+ it "is successful" do
12
+ VCR.use_cassette("receivings_list") do
13
+ response = Shipwire::Receivings.new.list
14
+
15
+ expect(response.ok?).to be_truthy
16
+ end
17
+ end
18
+ end
19
+
20
+ context "using params" do
21
+ it "is successful" do
22
+ VCR.use_cassette("receivings_list_with_params") do
23
+ response = Shipwire::Receivings.new.list(
24
+ status: "canceled"
25
+ )
26
+
27
+ expect(response.ok?).to be_truthy
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ context "management" do
34
+ let!(:receiving) do
35
+ VCR.use_cassette("receiving") do
36
+ Shipwire::Receivings.new.create(payload)
37
+ end
38
+ end
39
+
40
+ context "find" do
41
+ context "without params" do
42
+ it "is successful" do
43
+ VCR.use_cassette("receiving_find") do
44
+ receiving_id =
45
+ receiving.body["resource"]["items"].first["resource"]["id"]
46
+
47
+ response = Shipwire::Receivings.new.find(receiving_id)
48
+
49
+ expect(response.ok?).to be_truthy
50
+ end
51
+ end
52
+ end
53
+
54
+ context "using params" do
55
+ it "is successful" do
56
+ VCR.use_cassette("receiving_find_with_params") do
57
+ receiving_id =
58
+ receiving.body["resource"]["items"].first["resource"]["id"]
59
+
60
+ response = Shipwire::Receivings.new.find(receiving_id,
61
+ expand: "holds")
62
+
63
+ expect(response.ok?).to be_truthy
64
+ end
65
+ end
66
+ end
67
+
68
+ it "fails when id does not exist" do
69
+ VCR.use_cassette("receiving_find_fail") do
70
+ response = Shipwire::Receivings.new.find(0)
71
+
72
+ expect(response.ok?).to be_falsy
73
+ expect(response.error_summary).to eq 'Receiving Order not found.'
74
+ end
75
+ end
76
+ end
77
+
78
+ context "update" do
79
+ context "without params" do
80
+ it "is successful" do
81
+ VCR.use_cassette("receiving_update") do
82
+ receiving_id =
83
+ receiving.body["resource"]["items"].first["resource"]["id"]
84
+
85
+ payload_updates = { shipFrom: { email: FFaker::Internet.email } }
86
+ payload_update = payload.deeper_merge(payload_updates)
87
+
88
+ response = Shipwire::Receivings.new.update(receiving_id,
89
+ payload_update)
90
+
91
+ expect(response.ok?).to be_truthy
92
+ end
93
+ end
94
+ end
95
+
96
+ context "using params" do
97
+ it "is successful" do
98
+ VCR.use_cassette("receiving_update_with_params") do
99
+ receiving_id =
100
+ receiving.body["resource"]["items"].first["resource"]["id"]
101
+
102
+ payload_updates = { shipFrom: { email: FFaker::Internet.email } }
103
+ payload_update = payload.deeper_merge(payload_updates)
104
+
105
+ response = Shipwire::Receivings.new.update(receiving_id,
106
+ payload_update,
107
+ expand: "all")
108
+
109
+ expect(response.ok?).to be_truthy
110
+ end
111
+ end
112
+ end
113
+
114
+ it "fails when id does not exist" do
115
+ VCR.use_cassette("receiving_update_fail") do
116
+ payload_updates = { shipFrom: { email: FFaker::Internet.email } }
117
+ payload_update = payload.deeper_merge(payload_updates)
118
+
119
+ response = Shipwire::Receivings.new.update(0, payload_update)
120
+
121
+ expect(response.ok?).to be_falsy
122
+ expect(response.error_summary).to eq(
123
+ "Order ID not detected. Please make a POST if you wish to create "\
124
+ "an order."
125
+ )
126
+ end
127
+ end
128
+ end
129
+
130
+ context "labels_cancel" do
131
+ it "is successful" do
132
+ VCR.use_cassette("receiving_cancel_label") do
133
+ receiving_id =
134
+ receiving.body["resource"]["items"].first["resource"]["id"]
135
+
136
+ response = Shipwire::Receivings.new.labels_cancel(receiving_id)
137
+
138
+ expect(response.ok?).to be_truthy
139
+ end
140
+ end
141
+
142
+ it "is successful even when id does not exist" do
143
+ VCR.use_cassette("receiving_cancel_label_nonexistent") do
144
+ response = Shipwire::Receivings.new.labels_cancel(0)
145
+
146
+ expect(response.ok?).to be_truthy
147
+ end
148
+ end
149
+ end
150
+
151
+ context "holds" do
152
+ context "without params" do
153
+ it "is successful" do
154
+ VCR.use_cassette("receiving_holds") do
155
+ receiving_id =
156
+ receiving.body["resource"]["items"].first["resource"]["id"]
157
+
158
+ response = Shipwire::Receivings.new.holds(receiving_id)
159
+
160
+ expect(response.ok?).to be_truthy
161
+ end
162
+ end
163
+ end
164
+
165
+ context "using params" do
166
+ it "is successful" do
167
+ VCR.use_cassette("receiving_holds_with_params") do
168
+ receiving_id =
169
+ receiving.body["resource"]["items"].first["resource"]["id"]
170
+
171
+ response = Shipwire::Receivings.new.holds(receiving_id,
172
+ includeCleared: 0)
173
+
174
+ expect(response.ok?).to be_truthy
175
+ end
176
+ end
177
+ end
178
+
179
+ it "fails when id does not exist" do
180
+ VCR.use_cassette("receiving_holds_fail") do
181
+ response = Shipwire::Receivings.new.holds(0)
182
+
183
+ expect(response.ok?).to be_falsy
184
+ expect(response.error_summary).to eq 'Receiving Order not found.'
185
+ end
186
+ end
187
+ end
188
+
189
+ context "instructions_recipients" do
190
+ it "is successful" do
191
+ VCR.use_cassette("receiving_instructions_recipients") do
192
+ receiving_id =
193
+ receiving.body["resource"]["items"].first["resource"]["id"]
194
+
195
+ response = Shipwire::Receivings.new.instructions(receiving_id)
196
+
197
+ expect(response.ok?).to be_truthy
198
+ end
199
+ end
200
+
201
+ it "fails when id does not exist" do
202
+ VCR.use_cassette("receiving_instructions_recipients_fail") do
203
+ response = Shipwire::Receivings.new.instructions(0)
204
+
205
+ expect(response.ok?).to be_falsy
206
+ expect(response.error_summary).to eq 'Receiving Order not found.'
207
+ end
208
+ end
209
+ end
210
+
211
+ context "items" do
212
+ it "is successful" do
213
+ VCR.use_cassette("receiving_items") do
214
+ receiving_id =
215
+ receiving.body["resource"]["items"].first["resource"]["id"]
216
+
217
+ response = Shipwire::Receivings.new.items(receiving_id)
218
+
219
+ expect(response.ok?).to be_truthy
220
+ end
221
+ end
222
+
223
+ it "fails when id does not exist" do
224
+ VCR.use_cassette("receiving_items_fail") do
225
+ response = Shipwire::Receivings.new.items(0)
226
+
227
+ expect(response.ok?).to be_falsy
228
+ expect(response.error_summary).to eq 'Receiving Order not found.'
229
+ end
230
+ end
231
+ end
232
+
233
+ context "shipments" do
234
+ it "is successful" do
235
+ VCR.use_cassette("receiving_shipments") do
236
+ receiving_id =
237
+ receiving.body["resource"]["items"].first["resource"]["id"]
238
+
239
+ response = Shipwire::Receivings.new.shipments(receiving_id)
240
+
241
+ expect(response.ok?).to be_truthy
242
+ end
243
+ end
244
+
245
+ it "fails when id does not exist" do
246
+ VCR.use_cassette("receiving_shipments_fail") do
247
+ response = Shipwire::Receivings.new.shipments(0)
248
+
249
+ expect(response.ok?).to be_falsy
250
+ expect(response.error_summary).to eq 'Receiving Order not found.'
251
+ end
252
+ end
253
+ end
254
+
255
+ context "trackings" do
256
+ it "is successful" do
257
+ VCR.use_cassette("receiving_tracking") do
258
+ receiving_id =
259
+ receiving.body["resource"]["items"].first["resource"]["id"]
260
+
261
+ response = Shipwire::Receivings.new.trackings(receiving_id)
262
+
263
+ expect(response.ok?).to be_truthy
264
+ end
265
+ end
266
+
267
+ it "fails when id does not exist" do
268
+ VCR.use_cassette("receiving_tracking_fail") do
269
+ response = Shipwire::Receivings.new.trackings(0)
270
+
271
+ expect(response.ok?).to be_falsy
272
+ expect(response.error_summary).to eq 'Receiving Order not found.'
273
+ end
274
+ end
275
+ end
276
+
277
+ context "cancel" do
278
+ it "is successful" do
279
+ VCR.use_cassette("receiving_cancel") do
280
+ receiving_id =
281
+ receiving.body["resource"]["items"].first["resource"]["id"]
282
+
283
+ response = Shipwire::Receivings.new.cancel(receiving_id)
284
+
285
+ expect(response.ok?).to be_truthy
286
+ end
287
+ end
288
+
289
+ it "fails when id does not exist" do
290
+ VCR.use_cassette("receiving_cancel") do
291
+ response = Shipwire::Receivings.new.cancel(0)
292
+
293
+ expect(response.ok?).to be_falsy
294
+ expect(response.error_summary).to eq 'Receiving not found'
295
+ end
296
+ end
297
+ end
298
+
299
+ def payload
300
+ {
301
+ externalId: FFaker::Product.model,
302
+ expectedDate: DateTime.now.to_s,
303
+ arrangement: {
304
+ type: "none"
305
+ },
306
+ items: [{
307
+ sku: "TEST-PRODUCT",
308
+ quantity: 5
309
+ }],
310
+ shipments: [{
311
+ length: 1,
312
+ width: 1,
313
+ height: 1,
314
+ weight: 1,
315
+ type: "box"
316
+ }],
317
+ options: {
318
+ warehouseRegion: "LAX"
319
+ },
320
+ shipFrom: {
321
+ email: FFaker::Internet.email,
322
+ name: FFaker::Name.name,
323
+ address1: "540 West Boylston St.",
324
+ city: "Worcester",
325
+ state: "MA",
326
+ postalCode: "01606",
327
+ country: "US",
328
+ phone: FFaker::PhoneNumber.short_phone_number
329
+ }
330
+ }
331
+ end
332
+ end
333
+ end