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.
- checksums.yaml +4 -4
- data/.gitignore +3 -3
- data/.rspec +2 -0
- data/.ruby-version +1 -1
- data/Gemfile +0 -1
- data/README.md +53 -29
- data/Rakefile +2 -3
- data/lib/generators/shipwire/install/install_generator.rb +13 -0
- data/lib/generators/shipwire/install/templates/config/initializers/shipwire.rb +27 -0
- data/lib/shipwire.rb +26 -33
- data/lib/shipwire/api.rb +7 -0
- data/lib/shipwire/configuration.rb +13 -3
- data/lib/shipwire/orders.rb +39 -0
- data/lib/shipwire/param_converter.rb +39 -0
- data/lib/shipwire/products.rb +53 -0
- data/lib/shipwire/products/base.rb +9 -0
- data/lib/shipwire/products/insert.rb +9 -0
- data/lib/shipwire/products/kit.rb +9 -0
- data/lib/shipwire/products/virtual_kit.rb +9 -0
- data/lib/shipwire/rate.rb +7 -0
- data/lib/shipwire/receivings.rb +50 -0
- data/lib/shipwire/request.rb +73 -0
- data/lib/shipwire/response.rb +79 -0
- data/lib/shipwire/returns.rb +35 -0
- data/lib/shipwire/secret.rb +20 -0
- data/lib/shipwire/stock.rb +7 -0
- data/lib/shipwire/utility.rb +22 -0
- data/lib/shipwire/version.rb +1 -1
- data/lib/shipwire/webhooks.rb +24 -0
- data/shipwire.gemspec +12 -15
- data/spec/features/access_spec.rb +61 -0
- data/spec/features/orders_spec.rb +280 -0
- data/spec/features/product_types_spec.rb +219 -0
- data/spec/features/products_spec.rb +282 -0
- data/spec/features/rate_spec.rb +50 -0
- data/spec/features/receivings_spec.rb +333 -0
- data/spec/features/returns_spec.rb +239 -0
- data/spec/features/secret_spec.rb +57 -0
- data/spec/features/stock_spec.rb +41 -0
- data/spec/features/webhooks_spec.rb +106 -0
- data/spec/spec_helper.rb +33 -12
- data/spec/support/shipwire.rb +10 -0
- data/spec/support/vcr.rb +9 -0
- data/spec/support/vcr_cassettes/credentials_incorrect.yml +47 -0
- data/spec/support/vcr_cassettes/credentials_missing.yml +47 -0
- data/spec/support/vcr_cassettes/order.yml +48 -0
- data/spec/support/vcr_cassettes/order_cancel.yml +54 -0
- data/spec/support/vcr_cassettes/order_cancel_fail.yml +47 -0
- data/spec/support/vcr_cassettes/order_find.yml +45 -0
- data/spec/support/vcr_cassettes/order_find_fail.yml +45 -0
- data/spec/support/vcr_cassettes/order_find_with_params.yml +45 -0
- data/spec/support/vcr_cassettes/order_holds.yml +50 -0
- data/spec/support/vcr_cassettes/order_holds_fail.yml +45 -0
- data/spec/support/vcr_cassettes/order_holds_with_params.yml +50 -0
- data/spec/support/vcr_cassettes/order_items.yml +45 -0
- data/spec/support/vcr_cassettes/order_items_fail.yml +45 -0
- data/spec/support/vcr_cassettes/order_returns.yml +47 -0
- data/spec/support/vcr_cassettes/order_returns_fail.yml +47 -0
- data/spec/support/vcr_cassettes/order_trackings.yml +45 -0
- data/spec/support/vcr_cassettes/order_trackings_fail.yml +45 -0
- data/spec/support/vcr_cassettes/order_update.yml +48 -0
- data/spec/support/vcr_cassettes/order_update_fail.yml +50 -0
- data/spec/support/vcr_cassettes/order_update_with_params.yml +48 -0
- data/spec/support/vcr_cassettes/order_with_warnings.yml +96 -0
- data/spec/support/vcr_cassettes/orders_list.yml +47 -0
- data/spec/support/vcr_cassettes/orders_list_with_params.yml +47 -0
- data/spec/support/vcr_cassettes/product.yml +48 -0
- data/spec/support/vcr_cassettes/product_base.yml +48 -0
- data/spec/support/vcr_cassettes/product_base_find.yml +48 -0
- data/spec/support/vcr_cassettes/product_base_find_fail.yml +47 -0
- data/spec/support/vcr_cassettes/product_base_retire_id.yml +47 -0
- data/spec/support/vcr_cassettes/product_base_retire_nonexistent.yml +47 -0
- data/spec/support/vcr_cassettes/product_base_update.yml +48 -0
- data/spec/support/vcr_cassettes/product_base_update_fail.yml +48 -0
- data/spec/support/vcr_cassettes/product_create_fail_with_invalid_classification.yml +51 -0
- data/spec/support/vcr_cassettes/product_find.yml +48 -0
- data/spec/support/vcr_cassettes/product_find_fail.yml +47 -0
- data/spec/support/vcr_cassettes/product_insert.yml +50 -0
- data/spec/support/vcr_cassettes/product_insert_find.yml +48 -0
- data/spec/support/vcr_cassettes/product_insert_find_fail.yml +47 -0
- data/spec/support/vcr_cassettes/product_insert_retire_id.yml +47 -0
- data/spec/support/vcr_cassettes/product_insert_retire_nonexistent.yml +47 -0
- data/spec/support/vcr_cassettes/product_insert_update.yml +49 -0
- data/spec/support/vcr_cassettes/product_insert_update_fail.yml +48 -0
- data/spec/support/vcr_cassettes/product_kit.yml +48 -0
- data/spec/support/vcr_cassettes/product_kit_find.yml +48 -0
- data/spec/support/vcr_cassettes/product_kit_find_fail.yml +47 -0
- data/spec/support/vcr_cassettes/product_kit_retire_id.yml +47 -0
- data/spec/support/vcr_cassettes/product_kit_retire_nonexistent.yml +47 -0
- data/spec/support/vcr_cassettes/product_kit_update.yml +48 -0
- data/spec/support/vcr_cassettes/product_kit_update_fail.yml +47 -0
- data/spec/support/vcr_cassettes/product_multiple_create_fail.yml +102 -0
- data/spec/support/vcr_cassettes/product_multiple_create_success.yml +100 -0
- data/spec/support/vcr_cassettes/product_retire_id.yml +47 -0
- data/spec/support/vcr_cassettes/product_retire_nonexistent.yml +47 -0
- data/spec/support/vcr_cassettes/product_update.yml +48 -0
- data/spec/support/vcr_cassettes/product_update_fail.yml +48 -0
- data/spec/support/vcr_cassettes/product_virtual_kit.yml +48 -0
- data/spec/support/vcr_cassettes/product_virtual_kit_find.yml +48 -0
- data/spec/support/vcr_cassettes/product_virtual_kit_find_fail.yml +47 -0
- data/spec/support/vcr_cassettes/product_virtual_kit_retire_id.yml +47 -0
- data/spec/support/vcr_cassettes/product_virtual_kit_retire_nonexistent.yml +47 -0
- data/spec/support/vcr_cassettes/product_virtual_kit_update.yml +49 -0
- data/spec/support/vcr_cassettes/product_virtual_kit_update_fail.yml +47 -0
- data/spec/support/vcr_cassettes/products_base_list.yml +49 -0
- data/spec/support/vcr_cassettes/products_base_list_with_params.yml +49 -0
- data/spec/support/vcr_cassettes/products_insert_list.yml +47 -0
- data/spec/support/vcr_cassettes/products_insert_list_with_params.yml +47 -0
- data/spec/support/vcr_cassettes/products_kit_list.yml +47 -0
- data/spec/support/vcr_cassettes/products_kit_list_with_params.yml +47 -0
- data/spec/support/vcr_cassettes/products_list.yml +49 -0
- data/spec/support/vcr_cassettes/products_list_with_params.yml +49 -0
- data/spec/support/vcr_cassettes/products_virtual_kit_list.yml +47 -0
- data/spec/support/vcr_cassettes/products_virtual_kit_list_with_params.yml +47 -0
- data/spec/support/vcr_cassettes/rate_find.yml +53 -0
- data/spec/support/vcr_cassettes/rate_find_fail.yml +50 -0
- data/spec/support/vcr_cassettes/receiving.yml +53 -0
- data/spec/support/vcr_cassettes/receiving_cancel.yml +98 -0
- data/spec/support/vcr_cassettes/receiving_cancel_label.yml +47 -0
- data/spec/support/vcr_cassettes/receiving_cancel_label_nonexistent.yml +47 -0
- data/spec/support/vcr_cassettes/receiving_find.yml +46 -0
- data/spec/support/vcr_cassettes/receiving_find_fail.yml +45 -0
- data/spec/support/vcr_cassettes/receiving_find_with_params.yml +48 -0
- data/spec/support/vcr_cassettes/receiving_holds.yml +47 -0
- data/spec/support/vcr_cassettes/receiving_holds_fail.yml +45 -0
- data/spec/support/vcr_cassettes/receiving_holds_with_params.yml +47 -0
- data/spec/support/vcr_cassettes/receiving_instructions_recipients.yml +45 -0
- data/spec/support/vcr_cassettes/receiving_instructions_recipients_fail.yml +45 -0
- data/spec/support/vcr_cassettes/receiving_items.yml +45 -0
- data/spec/support/vcr_cassettes/receiving_items_fail.yml +45 -0
- data/spec/support/vcr_cassettes/receiving_shipments.yml +45 -0
- data/spec/support/vcr_cassettes/receiving_shipments_fail.yml +45 -0
- data/spec/support/vcr_cassettes/receiving_tracking.yml +45 -0
- data/spec/support/vcr_cassettes/receiving_tracking_fail.yml +45 -0
- data/spec/support/vcr_cassettes/receiving_update.yml +53 -0
- data/spec/support/vcr_cassettes/receiving_update_fail.yml +49 -0
- data/spec/support/vcr_cassettes/receiving_update_with_params.yml +55 -0
- data/spec/support/vcr_cassettes/receivings_list.yml +53 -0
- data/spec/support/vcr_cassettes/receivings_list_with_params.yml +46 -0
- data/spec/support/vcr_cassettes/return.yml +98 -0
- data/spec/support/vcr_cassettes/return_cancel.yml +55 -0
- data/spec/support/vcr_cassettes/return_cancel_fail.yml +47 -0
- data/spec/support/vcr_cassettes/return_find.yml +47 -0
- data/spec/support/vcr_cassettes/return_find_fail.yml +45 -0
- data/spec/support/vcr_cassettes/return_find_with_params.yml +47 -0
- data/spec/support/vcr_cassettes/return_holds.yml +45 -0
- data/spec/support/vcr_cassettes/return_holds_fail.yml +45 -0
- data/spec/support/vcr_cassettes/return_holds_with_params.yml +45 -0
- data/spec/support/vcr_cassettes/return_items.yml +45 -0
- data/spec/support/vcr_cassettes/return_items_fail.yml +45 -0
- data/spec/support/vcr_cassettes/return_labels.yml +45 -0
- data/spec/support/vcr_cassettes/return_labels_fail.yml +45 -0
- data/spec/support/vcr_cassettes/return_trackings.yml +45 -0
- data/spec/support/vcr_cassettes/return_trackings_fail.yml +45 -0
- data/spec/support/vcr_cassettes/returns_list.yml +47 -0
- data/spec/support/vcr_cassettes/returns_list_with_params.yml +47 -0
- data/spec/support/vcr_cassettes/secret.yml +47 -0
- data/spec/support/vcr_cassettes/secret_find.yml +45 -0
- data/spec/support/vcr_cassettes/secret_find_fail.yml +43 -0
- data/spec/support/vcr_cassettes/secret_list.yml +45 -0
- data/spec/support/vcr_cassettes/secret_remove.yml +45 -0
- data/spec/support/vcr_cassettes/stock_with_params.yml +45 -0
- data/spec/support/vcr_cassettes/stock_with_params_no_sku.yml +45 -0
- data/spec/support/vcr_cassettes/stock_without_params.yml +45 -0
- data/spec/support/vcr_cassettes/webhook.yml +47 -0
- data/spec/support/vcr_cassettes/webhooks_create_insecure.yml +50 -0
- data/spec/support/vcr_cassettes/webhooks_find.yml +47 -0
- data/spec/support/vcr_cassettes/webhooks_find_fail.yml +47 -0
- data/spec/support/vcr_cassettes/webhooks_list.yml +47 -0
- data/spec/support/vcr_cassettes/webhooks_remove.yml +47 -0
- data/spec/support/vcr_cassettes/webhooks_update.yml +47 -0
- data/spec/support/vcr_cassettes/webhooks_update_fail.yml +49 -0
- data/spec/unit/shipwire/response_spec.rb +46 -0
- metadata +354 -80
- data/.env +0 -4
- data/.env.example +0 -4
- data/Gemfile.lock +0 -69
- data/lib/shipwire/fulfillment.rb +0 -100
- data/lib/shipwire/inventory.rb +0 -72
- data/lib/shipwire/service_request.rb +0 -42
- data/lib/shipwire/shipping_rate.rb +0 -121
- data/lib/shipwire/tracking.rb +0 -101
- data/spec/shipwire/fulfillment_spec.rb +0 -36
- data/spec/shipwire/inventory_spec.rb +0 -25
- data/spec/shipwire/shipping_rate_spec.rb +0 -62
- data/spec/shipwire/tracking_spec.rb +0 -20
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
RSpec.describe "Orders", type: :feature, vcr: true do
|
|
4
|
+
context "list" do
|
|
5
|
+
context "without params" do
|
|
6
|
+
it "is successful" do
|
|
7
|
+
VCR.use_cassette("orders_list") do
|
|
8
|
+
response = Shipwire::Orders.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("orders_list_with_params") do
|
|
18
|
+
response = Shipwire::Orders.new.list(
|
|
19
|
+
status: "canceled"
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
expect(response.ok?).to be_truthy
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
context "management" do
|
|
29
|
+
let(:payload) do
|
|
30
|
+
order_number = (0...8).map { (65 + rand(26)).chr }.join
|
|
31
|
+
|
|
32
|
+
{
|
|
33
|
+
orderNo: order_number,
|
|
34
|
+
externalId: order_number,
|
|
35
|
+
items: [
|
|
36
|
+
{
|
|
37
|
+
sku: "TEST-PRODUCT",
|
|
38
|
+
quantity: 1
|
|
39
|
+
}
|
|
40
|
+
],
|
|
41
|
+
options: {
|
|
42
|
+
currency: "USD"
|
|
43
|
+
},
|
|
44
|
+
shipTo: {
|
|
45
|
+
email: FFaker::Internet.email,
|
|
46
|
+
name: FFaker::Name.name,
|
|
47
|
+
address1: "540 West Boylston St.",
|
|
48
|
+
city: "Worcester",
|
|
49
|
+
state: "MA",
|
|
50
|
+
postalCode: "01606",
|
|
51
|
+
country: "US",
|
|
52
|
+
phone: FFaker::PhoneNumber.short_phone_number
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
let(:payload_update) do
|
|
58
|
+
payload.deeper_merge(options: { currency: "MXN" })
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
let!(:order) do
|
|
62
|
+
VCR.use_cassette("order") do
|
|
63
|
+
Shipwire::Orders.new.create(payload)
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
context "create with warnings" do
|
|
68
|
+
it "is successful" do
|
|
69
|
+
VCR.use_cassette("order_with_warnings") do
|
|
70
|
+
response = Shipwire::Orders.new.create(payload)
|
|
71
|
+
|
|
72
|
+
expect(response.ok?).to be_truthy
|
|
73
|
+
expect(response.has_warnings?).to be_truthy
|
|
74
|
+
expect(response.warnings).to include(
|
|
75
|
+
"Order was marked residential; now marked commercial"
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
# Cancel the order
|
|
79
|
+
order_id = order.body["resource"]["items"].first["resource"]["id"]
|
|
80
|
+
|
|
81
|
+
Shipwire::Orders.new.cancel(order_id)
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
context "find" do
|
|
87
|
+
context "without params" do
|
|
88
|
+
it "is successful" do
|
|
89
|
+
VCR.use_cassette("order_find") do
|
|
90
|
+
order_id = order.body["resource"]["items"].first["resource"]["id"]
|
|
91
|
+
|
|
92
|
+
response = Shipwire::Orders.new.find(order_id)
|
|
93
|
+
|
|
94
|
+
expect(response.ok?).to be_truthy
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
context "with params" do
|
|
100
|
+
it "is successful" do
|
|
101
|
+
VCR.use_cassette("order_find_with_params") do
|
|
102
|
+
order_id = order.body["resource"]["items"].first["resource"]["id"]
|
|
103
|
+
|
|
104
|
+
response = Shipwire::Orders.new.find(order_id, expand: "trackings")
|
|
105
|
+
|
|
106
|
+
expect(response.ok?).to be_truthy
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
it "fails when id does not exist" do
|
|
112
|
+
VCR.use_cassette("order_find_fail") do
|
|
113
|
+
response = Shipwire::Orders.new.find(0)
|
|
114
|
+
|
|
115
|
+
expect(response.ok?).to be_falsy
|
|
116
|
+
expect(response.error_summary).to eq 'Order not found.'
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
context "update" do
|
|
122
|
+
context "without params" do
|
|
123
|
+
it "is successful" do
|
|
124
|
+
VCR.use_cassette("order_update") do
|
|
125
|
+
order_id = order.body["resource"]["items"].first["resource"]["id"]
|
|
126
|
+
|
|
127
|
+
response = Shipwire::Orders.new.update(order_id, payload_update)
|
|
128
|
+
|
|
129
|
+
expect(response.ok?).to be_truthy
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
context "with params" do
|
|
135
|
+
it "is successful" do
|
|
136
|
+
VCR.use_cassette("order_update_with_params") do
|
|
137
|
+
order_id = order.body["resource"]["items"].first["resource"]["id"]
|
|
138
|
+
|
|
139
|
+
response = Shipwire::Orders.new.update(order_id,
|
|
140
|
+
payload_update,
|
|
141
|
+
expand: "all")
|
|
142
|
+
|
|
143
|
+
expect(response.ok?).to be_truthy
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
it "fails when id does not exist" do
|
|
149
|
+
VCR.use_cassette("order_update_fail") do
|
|
150
|
+
response = Shipwire::Orders.new.update(0, payload_update)
|
|
151
|
+
|
|
152
|
+
expect(response.ok?).to be_falsy
|
|
153
|
+
expect(response.error_summary).to eq(
|
|
154
|
+
"Order ID not detected. Please make a POST if you wish to create "\
|
|
155
|
+
"an order."
|
|
156
|
+
)
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
context "items" do
|
|
162
|
+
it "is successful" do
|
|
163
|
+
VCR.use_cassette("order_items") do
|
|
164
|
+
order_id = order.body["resource"]["items"].first["resource"]["id"]
|
|
165
|
+
|
|
166
|
+
response = Shipwire::Orders.new.items(order_id)
|
|
167
|
+
|
|
168
|
+
expect(response.ok?).to be_truthy
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
it "fails when id does not exist" do
|
|
173
|
+
VCR.use_cassette("order_items_fail") do
|
|
174
|
+
response = Shipwire::Orders.new.items(0)
|
|
175
|
+
|
|
176
|
+
expect(response.ok?).to be_falsy
|
|
177
|
+
expect(response.error_summary).to eq 'Order not found.'
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
context "holds" do
|
|
183
|
+
context "without params" do
|
|
184
|
+
it "is successful" do
|
|
185
|
+
VCR.use_cassette("order_holds") do
|
|
186
|
+
order_id = order.body["resource"]["items"].first["resource"]["id"]
|
|
187
|
+
|
|
188
|
+
response = Shipwire::Orders.new.holds(order_id)
|
|
189
|
+
|
|
190
|
+
expect(response.ok?).to be_truthy
|
|
191
|
+
end
|
|
192
|
+
end
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
context "with params" do
|
|
196
|
+
it "is successful" do
|
|
197
|
+
VCR.use_cassette("order_holds_with_params") do
|
|
198
|
+
order_id = order.body["resource"]["items"].first["resource"]["id"]
|
|
199
|
+
|
|
200
|
+
response = Shipwire::Orders.new.holds(order_id, includeCleared: 1)
|
|
201
|
+
|
|
202
|
+
expect(response.ok?).to be_truthy
|
|
203
|
+
end
|
|
204
|
+
end
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
it "fails when id does not exist" do
|
|
208
|
+
VCR.use_cassette("order_holds_fail") do
|
|
209
|
+
response = Shipwire::Orders.new.holds(0)
|
|
210
|
+
|
|
211
|
+
expect(response.ok?).to be_falsy
|
|
212
|
+
expect(response.error_summary).to eq 'Order not found.'
|
|
213
|
+
end
|
|
214
|
+
end
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
context "returns" do
|
|
218
|
+
it "is successful" do
|
|
219
|
+
VCR.use_cassette("order_returns") do
|
|
220
|
+
order_id = order.body["resource"]["items"].first["resource"]["id"]
|
|
221
|
+
|
|
222
|
+
response = Shipwire::Orders.new.returns(order_id)
|
|
223
|
+
|
|
224
|
+
expect(response.ok?).to be_truthy
|
|
225
|
+
end
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
it "fails when id does not exist" do
|
|
229
|
+
VCR.use_cassette("order_returns_fail") do
|
|
230
|
+
response = Shipwire::Orders.new.returns(0)
|
|
231
|
+
|
|
232
|
+
expect(response.ok?).to be_falsy
|
|
233
|
+
expect(response.error_summary).to eq 'Order not found.'
|
|
234
|
+
end
|
|
235
|
+
end
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
context "trackings" do
|
|
239
|
+
it "is successful" do
|
|
240
|
+
VCR.use_cassette("order_trackings") do
|
|
241
|
+
order_id = order.body["resource"]["items"].first["resource"]["id"]
|
|
242
|
+
|
|
243
|
+
response = Shipwire::Orders.new.trackings(order_id)
|
|
244
|
+
|
|
245
|
+
expect(response.ok?).to be_truthy
|
|
246
|
+
end
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
it "fails when id does not exist" do
|
|
250
|
+
VCR.use_cassette("order_trackings_fail") do
|
|
251
|
+
response = Shipwire::Orders.new.trackings(0)
|
|
252
|
+
|
|
253
|
+
expect(response.ok?).to be_falsy
|
|
254
|
+
expect(response.error_summary).to eq 'Order not found.'
|
|
255
|
+
end
|
|
256
|
+
end
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
context "cancel" do
|
|
260
|
+
it "is successful" do
|
|
261
|
+
VCR.use_cassette("order_cancel") do
|
|
262
|
+
order_id = order.body["resource"]["items"].first["resource"]["id"]
|
|
263
|
+
|
|
264
|
+
response = Shipwire::Orders.new.cancel(order_id)
|
|
265
|
+
|
|
266
|
+
expect(response.ok?).to be_truthy
|
|
267
|
+
end
|
|
268
|
+
end
|
|
269
|
+
|
|
270
|
+
it "fails when id does not exist" do
|
|
271
|
+
VCR.use_cassette("order_cancel_fail") do
|
|
272
|
+
response = Shipwire::Orders.new.cancel(0)
|
|
273
|
+
|
|
274
|
+
expect(response.ok?).to be_falsy
|
|
275
|
+
expect(response.error_summary).to eq 'Order not found'
|
|
276
|
+
end
|
|
277
|
+
end
|
|
278
|
+
end
|
|
279
|
+
end
|
|
280
|
+
end
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
RSpec.describe "Product", type: :feature, vcr: true do
|
|
4
|
+
%w(base insert kit virtual_kit).each do |product_type|
|
|
5
|
+
context "type #{product_type}" do
|
|
6
|
+
let(:product_class) do
|
|
7
|
+
type = Shipwire::Utility.camelize(product_type)
|
|
8
|
+
|
|
9
|
+
Object.const_get("Shipwire::Products::#{type}")
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
context "list" do
|
|
13
|
+
context "without params" do
|
|
14
|
+
it "is successful" do
|
|
15
|
+
VCR.use_cassette("products_#{product_type}_list") do
|
|
16
|
+
response = product_class.new.list
|
|
17
|
+
|
|
18
|
+
expect(response.ok?).to be_truthy
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
context "with params" do
|
|
24
|
+
it "is successful" do
|
|
25
|
+
VCR.use_cassette("products_#{product_type}_list_with_params") do
|
|
26
|
+
response = product_class.new.list(
|
|
27
|
+
sku: "TEST-PRODUCT"
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
expect(response.ok?).to be_truthy
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
context "management" do
|
|
37
|
+
let!(:product) do
|
|
38
|
+
VCR.use_cassette("product_#{product_type}") do
|
|
39
|
+
product_class.new.create(payload(product_type))
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
context "find" do
|
|
44
|
+
it "is successful" do
|
|
45
|
+
VCR.use_cassette("product_#{product_type}_find") do
|
|
46
|
+
product_id =
|
|
47
|
+
product.body["resource"]["items"].first["resource"]["id"]
|
|
48
|
+
|
|
49
|
+
response = product_class.new.find(product_id)
|
|
50
|
+
|
|
51
|
+
expect(response.ok?).to be_truthy
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it "fails when id does not exist" do
|
|
56
|
+
VCR.use_cassette("product_#{product_type}_find_fail") do
|
|
57
|
+
response = product_class.new.find(0)
|
|
58
|
+
|
|
59
|
+
expect(response.ok?).to be_falsy
|
|
60
|
+
expect(response.error_summary).to eq 'Product not found.'
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
context "update" do
|
|
66
|
+
it "is successful" do
|
|
67
|
+
VCR.use_cassette("product_#{product_type}_update") do
|
|
68
|
+
product_id =
|
|
69
|
+
product.body["resource"]["items"].first["resource"]["id"]
|
|
70
|
+
|
|
71
|
+
payload = payload(product_type).deeper_merge!(
|
|
72
|
+
description: "Super awesome description"
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
response = product_class.new.update(product_id, payload)
|
|
76
|
+
|
|
77
|
+
expect(response.ok?).to be_truthy
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
it "fails when id does not exist" do
|
|
82
|
+
VCR.use_cassette("product_#{product_type}_update_fail") do
|
|
83
|
+
payload = payload(product_type).deeper_merge!(
|
|
84
|
+
description: "Super awesome description"
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
response = product_class.new.update(0, payload)
|
|
88
|
+
|
|
89
|
+
expect(response.ok?).to be_falsy
|
|
90
|
+
expect(response.error_summary).to eq 'Product not found.'
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
context "retire" do
|
|
96
|
+
context "with string passed" do
|
|
97
|
+
it "is successful" do
|
|
98
|
+
VCR.use_cassette("product_#{product_type}_retire_id") do
|
|
99
|
+
product_id =
|
|
100
|
+
product.body["resource"]["items"].first["resource"]["id"]
|
|
101
|
+
|
|
102
|
+
response = product_class.new.retire(product_id)
|
|
103
|
+
|
|
104
|
+
expect(response.ok?).to be_truthy
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
context "with array passed" do
|
|
110
|
+
it "is successful" do
|
|
111
|
+
VCR.use_cassette("product_#{product_type}_retire_id") do
|
|
112
|
+
product_id =
|
|
113
|
+
product.body["resource"]["items"].first["resource"]["id"]
|
|
114
|
+
|
|
115
|
+
response = product_class.new.retire([product_id, 0])
|
|
116
|
+
|
|
117
|
+
expect(response.ok?).to be_truthy
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
context "when product does not exist" do
|
|
123
|
+
it "is successful" do
|
|
124
|
+
VCR.use_cassette("product_#{product_type}_retire_nonexistent") do
|
|
125
|
+
response = product_class.new.retire(0)
|
|
126
|
+
|
|
127
|
+
expect(response.ok?).to be_truthy
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
# NOTE: This is ugly and massive and I know it. I'm down to change it.
|
|
134
|
+
def payload(type)
|
|
135
|
+
payload = {
|
|
136
|
+
sku: FFaker::Product.model,
|
|
137
|
+
externalId: FFaker::Product.model,
|
|
138
|
+
description: FFaker::Product.product,
|
|
139
|
+
category: "OTHER",
|
|
140
|
+
batteryConfiguration: "NOBATTERY",
|
|
141
|
+
values: {
|
|
142
|
+
costValue: 1,
|
|
143
|
+
retailValue: 4
|
|
144
|
+
},
|
|
145
|
+
dimensions: {
|
|
146
|
+
length: 1,
|
|
147
|
+
width: 1,
|
|
148
|
+
height: 1,
|
|
149
|
+
weight: 1
|
|
150
|
+
},
|
|
151
|
+
flags: {
|
|
152
|
+
isPackagedReadyToShip: 1,
|
|
153
|
+
isFragile: 0,
|
|
154
|
+
isDangerous: 0,
|
|
155
|
+
isPerishable: 0,
|
|
156
|
+
isLiquid: 0,
|
|
157
|
+
isMedia: 0,
|
|
158
|
+
isAdult: 0,
|
|
159
|
+
hasInnerPack: 0,
|
|
160
|
+
hasMasterCase: 0,
|
|
161
|
+
hasPallet: 0
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
# First of all, to create a Kit or Virtual Kit, the base products HAVE
|
|
166
|
+
# to exist. They will not be created here. Kits require 2 ore more
|
|
167
|
+
# products.
|
|
168
|
+
# Next, `externalId` is NOT the same as the product SKU. An externalId
|
|
169
|
+
# currently cannot be set using the Shipwire website. It can only be
|
|
170
|
+
# set by creating a product through the API or updating an existing
|
|
171
|
+
# product using the API and setting a value for externalID.
|
|
172
|
+
# Otherwise instead of `externalID` you can use `productID` which is
|
|
173
|
+
# the unique Shipwire ID for that product
|
|
174
|
+
product_contents = [
|
|
175
|
+
{
|
|
176
|
+
externalId: "TEST-PRODUCT",
|
|
177
|
+
quantity: 1
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
externalId: "TEST-PRODUCT2",
|
|
181
|
+
quantity: 1
|
|
182
|
+
}
|
|
183
|
+
]
|
|
184
|
+
|
|
185
|
+
case type
|
|
186
|
+
when "insert"
|
|
187
|
+
payload.deeper_merge!(
|
|
188
|
+
dimensions: {
|
|
189
|
+
height: 0.1,
|
|
190
|
+
weight: 0.1
|
|
191
|
+
},
|
|
192
|
+
masterCase: {
|
|
193
|
+
individualItemsPerCase: 1,
|
|
194
|
+
sku: FFaker::Product.model,
|
|
195
|
+
description: FFaker::Product.product,
|
|
196
|
+
dimensions: {
|
|
197
|
+
length: 1,
|
|
198
|
+
width: 1,
|
|
199
|
+
height: 1,
|
|
200
|
+
weight: 1
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
inclusionRules: {
|
|
204
|
+
insertWhenWorthCurrency: "USD"
|
|
205
|
+
}
|
|
206
|
+
)
|
|
207
|
+
when "kit"
|
|
208
|
+
payload.deeper_merge!(kitContent: product_contents)
|
|
209
|
+
|
|
210
|
+
when "virtual_kit"
|
|
211
|
+
payload.deeper_merge!(virtualKitContent: product_contents)
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
payload
|
|
215
|
+
end
|
|
216
|
+
end
|
|
217
|
+
end
|
|
218
|
+
end
|
|
219
|
+
end
|