channeladvisor 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -0
- data/.rspec +2 -0
- data/.travis.yml +6 -0
- data/.yardopts +8 -0
- data/Gemfile +31 -0
- data/Guardfile +28 -0
- data/LICENSE +19 -0
- data/README.md +40 -0
- data/Rakefile +69 -0
- data/channeladvisor.gemspec +29 -0
- data/lib/channeladvisor.rb +27 -0
- data/lib/channeladvisor/account_authorization.rb +14 -0
- data/lib/channeladvisor/address.rb +39 -0
- data/lib/channeladvisor/admin.rb +75 -0
- data/lib/channeladvisor/base.rb +34 -0
- data/lib/channeladvisor/client.rb +3 -0
- data/lib/channeladvisor/configuration.rb +11 -0
- data/lib/channeladvisor/error.rb +30 -0
- data/lib/channeladvisor/line_item.rb +38 -0
- data/lib/channeladvisor/order.rb +179 -0
- data/lib/channeladvisor/order_status.rb +14 -0
- data/lib/channeladvisor/payment.rb +15 -0
- data/lib/channeladvisor/services.rb +11 -0
- data/lib/channeladvisor/services/admin_service.rb +47 -0
- data/lib/channeladvisor/services/base_service.rb +26 -0
- data/lib/channeladvisor/services/inventory_service.rb +90 -0
- data/lib/channeladvisor/services/order_service.rb +117 -0
- data/lib/channeladvisor/services/shipping_service.rb +164 -0
- data/lib/channeladvisor/shipment.rb +71 -0
- data/lib/channeladvisor/shopping_cart.rb +26 -0
- data/lib/channeladvisor/version.rb +3 -0
- data/spec/fixtures/requests/admin_service/get_authorization_list.xml +1 -0
- data/spec/fixtures/requests/admin_service/get_authorization_list_with_local_id.xml +1 -0
- data/spec/fixtures/requests/admin_service/ping.xml +1 -0
- data/spec/fixtures/requests/admin_service/request_access.xml +1 -0
- data/spec/fixtures/requests/inventory_service/ping.xml +1 -0
- data/spec/fixtures/requests/inventory_service/update_inventory_item_quantity_and_price_list/with_one_item/price_only.xml +1 -0
- data/spec/fixtures/requests/inventory_service/update_inventory_item_quantity_and_price_list/with_one_item/quantity_and_price.xml +1 -0
- data/spec/fixtures/requests/inventory_service/update_inventory_item_quantity_and_price_list/with_one_item/quantity_only.xml +1 -0
- data/spec/fixtures/requests/inventory_service/update_inventory_item_quantity_and_price_list/with_two_items/price_only.xml +1 -0
- data/spec/fixtures/requests/inventory_service/update_inventory_item_quantity_and_price_list/with_two_items/quantity_and_price.xml +1 -0
- data/spec/fixtures/requests/inventory_service/update_inventory_item_quantity_and_price_list/with_two_items/quantity_only.xml +1 -0
- data/spec/fixtures/requests/inventory_service/update_item_price.xml +1 -0
- data/spec/fixtures/requests/inventory_service/update_item_quantity.xml +1 -0
- data/spec/fixtures/requests/inventory_service/update_item_quantity_and_price.xml +1 -0
- data/spec/fixtures/requests/order_service/get_order_list/with_checkout_status_filter.xml +1 -0
- data/spec/fixtures/requests/order_service/get_order_list/with_created_from_date.xml +1 -0
- data/spec/fixtures/requests/order_service/get_order_list/with_created_to_date.xml +1 -0
- data/spec/fixtures/requests/order_service/get_order_list/with_detail_level.xml +1 -0
- data/spec/fixtures/requests/order_service/get_order_list/with_distribution_center_code.xml +1 -0
- data/spec/fixtures/requests/order_service/get_order_list/with_export_state.xml +1 -0
- data/spec/fixtures/requests/order_service/get_order_list/with_join_dates.xml +1 -0
- data/spec/fixtures/requests/order_service/get_order_list/with_one_client_order_id.xml +1 -0
- data/spec/fixtures/requests/order_service/get_order_list/with_one_order_id.xml +1 -0
- data/spec/fixtures/requests/order_service/get_order_list/with_order_state_filter.xml +1 -0
- data/spec/fixtures/requests/order_service/get_order_list/with_page_number_filter.xml +1 -0
- data/spec/fixtures/requests/order_service/get_order_list/with_page_size.xml +1 -0
- data/spec/fixtures/requests/order_service/get_order_list/with_payment_status_filter.xml +1 -0
- data/spec/fixtures/requests/order_service/get_order_list/with_refund_status_filter.xml +1 -0
- data/spec/fixtures/requests/order_service/get_order_list/with_shipping_status_filter.xml +1 -0
- data/spec/fixtures/requests/order_service/get_order_list/with_two_client_order_ids.xml +1 -0
- data/spec/fixtures/requests/order_service/get_order_list/with_two_order_ids.xml +1 -0
- data/spec/fixtures/requests/order_service/get_order_list/with_updated_from_date.xml +1 -0
- data/spec/fixtures/requests/order_service/get_order_list/with_updated_to_date.xml +1 -0
- data/spec/fixtures/requests/order_service/get_order_list/without_order_criteria.xml +1 -0
- data/spec/fixtures/requests/order_service/ping.xml +1 -0
- data/spec/fixtures/requests/order_service/set_orders_export_status/with_one_client_order_id.xml +1 -0
- data/spec/fixtures/requests/order_service/set_orders_export_status/with_two_client_order_ids.xml +1 -0
- data/spec/fixtures/requests/shipping_service/get_shipping_carrier_list.xml +1 -0
- data/spec/fixtures/requests/shipping_service/ping.xml +1 -0
- data/spec/fixtures/requests/shipping_service/submit_order_shipment_list/full_shipment/with_one_shipment.xml +1 -0
- data/spec/fixtures/requests/shipping_service/submit_order_shipment_list/full_shipment/with_two_shipments.xml +1 -0
- data/spec/fixtures/requests/shipping_service/submit_order_shipment_list/full_shipment/without_carrier_code.xml +1 -0
- data/spec/fixtures/requests/shipping_service/submit_order_shipment_list/full_shipment/without_class_code.xml +1 -0
- data/spec/fixtures/requests/shipping_service/submit_order_shipment_list/full_shipment/without_client_order_id.xml +1 -0
- data/spec/fixtures/requests/shipping_service/submit_order_shipment_list/full_shipment/without_seller_id.xml +1 -0
- data/spec/fixtures/requests/shipping_service/submit_order_shipment_list/full_shipment/without_tracking_number.xml +1 -0
- data/spec/fixtures/requests/shipping_service/submit_order_shipment_list/partial_shipment/with_one_line_item.xml +1 -0
- data/spec/fixtures/requests/shipping_service/submit_order_shipment_list/partial_shipment/with_two_line_items.xml +1 -0
- data/spec/fixtures/requests/shipping_service/submit_order_shipment_list/partial_shipment/with_two_shipments.xml +1 -0
- data/spec/fixtures/requests/shipping_service/submit_order_shipment_list/partial_shipment/without_carrier_code.xml +1 -0
- data/spec/fixtures/requests/shipping_service/submit_order_shipment_list/partial_shipment/without_class_code.xml +1 -0
- data/spec/fixtures/requests/shipping_service/submit_order_shipment_list/partial_shipment/without_seller_id.xml +1 -0
- data/spec/fixtures/requests/shipping_service/submit_order_shipment_list/partial_shipment/without_tracking_number.xml +1 -0
- data/spec/fixtures/requests/shipping_service/submit_order_shipment_list/with_partial_and_full_shipments.xml +1 -0
- data/spec/fixtures/responses/admin/get_authorization_list/failure.yml +50 -0
- data/spec/fixtures/responses/admin/get_authorization_list/no_authorizations.yml +49 -0
- data/spec/fixtures/responses/admin/get_authorization_list/one_authorization.yml +49 -0
- data/spec/fixtures/responses/admin/get_authorization_list/success.yml +49 -0
- data/spec/fixtures/responses/admin/get_authorization_list/two_authorizations.yml +49 -0
- data/spec/fixtures/responses/admin/ping/failure.yml +50 -0
- data/spec/fixtures/responses/admin/ping/success.yml +218 -0
- data/spec/fixtures/responses/admin/request_access/failure.yml +50 -0
- data/spec/fixtures/responses/admin/request_access/success.yml +49 -0
- data/spec/fixtures/responses/admin_service/get_authorization_list/with_invalid_local_id.yml +219 -0
- data/spec/fixtures/responses/admin_service/get_authorization_list/with_local_id/success.yml +218 -0
- data/spec/fixtures/responses/admin_service/get_authorization_list/with_valid_local_id/multiple_authorizations.yml +49 -0
- data/spec/fixtures/responses/admin_service/get_authorization_list/with_valid_local_id/no_authorizations.yml +49 -0
- data/spec/fixtures/responses/admin_service/get_authorization_list/with_valid_local_id/one_authorization.yml +49 -0
- data/spec/fixtures/responses/admin_service/get_authorization_list/with_valid_local_id/success.yml +218 -0
- data/spec/fixtures/responses/admin_service/get_authorization_list/without_local_id/multiple_authorizations.yml +49 -0
- data/spec/fixtures/responses/admin_service/get_authorization_list/without_local_id/no_authorizations.yml +49 -0
- data/spec/fixtures/responses/admin_service/get_authorization_list/without_local_id/one_authorization.yml +49 -0
- data/spec/fixtures/responses/admin_service/get_authorization_list/without_local_id/success.yml +218 -0
- data/spec/fixtures/responses/admin_service/ping/failure.yml +222 -0
- data/spec/fixtures/responses/admin_service/ping/success.yml +218 -0
- data/spec/fixtures/responses/admin_service/request_access/failure.yml +219 -0
- data/spec/fixtures/responses/admin_service/request_access/success.yml +218 -0
- data/spec/fixtures/responses/http_error.yml +48 -0
- data/spec/fixtures/responses/inventory_service/ping.yml +1356 -0
- data/spec/fixtures/responses/inventory_service/update_inventory_item_quantity_and_price.yml +1356 -0
- data/spec/fixtures/responses/inventory_service/update_inventory_item_quantity_and_price/price_only.yml +144 -0
- data/spec/fixtures/responses/inventory_service/update_inventory_item_quantity_and_price/quantity_and_price.yml +191 -0
- data/spec/fixtures/responses/inventory_service/update_inventory_item_quantity_and_price/quantity_only.yml +1403 -0
- data/spec/fixtures/responses/inventory_service/update_inventory_item_quantity_and_price_list.yml +243 -0
- data/spec/fixtures/responses/inventory_service/update_inventory_item_quantity_and_price_list/with_one_item/price_only.yml +97 -0
- data/spec/fixtures/responses/inventory_service/update_inventory_item_quantity_and_price_list/with_one_item/quantity_and_price.yml +144 -0
- data/spec/fixtures/responses/inventory_service/update_inventory_item_quantity_and_price_list/with_one_item/quantity_only.yml +51 -0
- data/spec/fixtures/responses/inventory_service/update_inventory_item_quantity_and_price_list/with_two_items/price_only.yml +238 -0
- data/spec/fixtures/responses/inventory_service/update_inventory_item_quantity_and_price_list/with_two_items/quantity_and_price.yml +285 -0
- data/spec/fixtures/responses/inventory_service/update_inventory_item_quantity_and_price_list/with_two_items/quantity_only.yml +191 -0
- data/spec/fixtures/responses/order/instance_set_export_status.yml +51 -0
- data/spec/fixtures/responses/order/instance_set_export_status/failure.yml +51 -0
- data/spec/fixtures/responses/order/instance_set_export_status/success/result_false.yml +51 -0
- data/spec/fixtures/responses/order/instance_set_export_status/success/result_true.yml +51 -0
- data/spec/fixtures/responses/order/list.yml +58 -0
- data/spec/fixtures/responses/order/list/failure.yml +56 -0
- data/spec/fixtures/responses/order/list/no_matching_orders.yml +56 -0
- data/spec/fixtures/responses/order/list/one_matching_order.yml +57 -0
- data/spec/fixtures/responses/order/list/two_matching_orders.yml +59 -0
- data/spec/fixtures/responses/order/list/with_criteria.yml +52 -0
- data/spec/fixtures/responses/order/list/with_no_criteria.yml +58 -0
- data/spec/fixtures/responses/order/ping.yml +868 -0
- data/spec/fixtures/responses/order/ping/failure.yml +50 -0
- data/spec/fixtures/responses/order/ping/success.yml +867 -0
- data/spec/fixtures/responses/order/set_export_status/failure.yml +51 -0
- data/spec/fixtures/responses/order/set_export_status/success/with_one_client_order_id.yml +51 -0
- data/spec/fixtures/responses/order/set_export_status/success/with_two_client_order_ids.yml +51 -0
- data/spec/fixtures/responses/order_service/get_order_list/.gitkeep +0 -0
- data/spec/fixtures/responses/order_service/get_order_list/with_checkout_status_filter.yml +875 -0
- data/spec/fixtures/responses/order_service/get_order_list/with_created_from_date.yml +874 -0
- data/spec/fixtures/responses/order_service/get_order_list/with_created_to_date.yml +874 -0
- data/spec/fixtures/responses/order_service/get_order_list/with_detail_level.yml +875 -0
- data/spec/fixtures/responses/order_service/get_order_list/with_distribution_center_code.yml +872 -0
- data/spec/fixtures/responses/order_service/get_order_list/with_export_state.yml +875 -0
- data/spec/fixtures/responses/order_service/get_order_list/with_join_dates.yml +869 -0
- data/spec/fixtures/responses/order_service/get_order_list/with_one_client_order_id.yml +872 -0
- data/spec/fixtures/responses/order_service/get_order_list/with_one_order_id.yml +873 -0
- data/spec/fixtures/responses/order_service/get_order_list/with_order_state_filter.yml +875 -0
- data/spec/fixtures/responses/order_service/get_order_list/with_page_number_filter.yml +875 -0
- data/spec/fixtures/responses/order_service/get_order_list/with_page_size.yml +874 -0
- data/spec/fixtures/responses/order_service/get_order_list/with_payment_status_filter.yml +875 -0
- data/spec/fixtures/responses/order_service/get_order_list/with_refund_status_filter.yml +875 -0
- data/spec/fixtures/responses/order_service/get_order_list/with_shipping_status_filter.yml +875 -0
- data/spec/fixtures/responses/order_service/get_order_list/with_two_client_order_ids.yml +872 -0
- data/spec/fixtures/responses/order_service/get_order_list/with_two_order_ids.yml +875 -0
- data/spec/fixtures/responses/order_service/get_order_list/with_updated_from_date.yml +874 -0
- data/spec/fixtures/responses/order_service/get_order_list/with_updated_to_date.yml +874 -0
- data/spec/fixtures/responses/order_service/get_order_list/without_order_criteria.yml +871 -0
- data/spec/fixtures/responses/order_service/get_order_refund_history/.gitkeep +0 -0
- data/spec/fixtures/responses/order_service/order_merge/.gitkeep +0 -0
- data/spec/fixtures/responses/order_service/order_split/.gitkeep +0 -0
- data/spec/fixtures/responses/order_service/ping/.gitkeep +0 -0
- data/spec/fixtures/responses/order_service/ping/failure.yml +871 -0
- data/spec/fixtures/responses/order_service/ping/success.yml +868 -0
- data/spec/fixtures/responses/order_service/set_orders_export_status/with_one_client_order_id.yml +867 -0
- data/spec/fixtures/responses/order_service/set_orders_export_status/with_two_client_order_id.yml +867 -0
- data/spec/fixtures/responses/order_service/set_seller_order_id/.gitkeep +0 -0
- data/spec/fixtures/responses/order_service/set_seller_order_item_id_list/.gitkeep +0 -0
- data/spec/fixtures/responses/order_service/submit_order/.gitkeep +0 -0
- data/spec/fixtures/responses/order_service/submit_order_refund/.gitkeep +0 -0
- data/spec/fixtures/responses/order_service/update_order_list/.gitkeep +0 -0
- data/spec/fixtures/responses/shipment/get_carriers.yml +53 -0
- data/spec/fixtures/responses/shipment/get_carriers/failure.yml +52 -0
- data/spec/fixtures/responses/shipment/submit.yml +464 -0
- data/spec/fixtures/responses/shipment/submit/failure.yml +462 -0
- data/spec/fixtures/responses/shipment/submit/one_shipment.yml +464 -0
- data/spec/fixtures/responses/shipment/submit/two_shipments.yml +56 -0
- data/spec/fixtures/responses/shipping_service/get_shipping_carrier_list.yml +953 -0
- data/spec/fixtures/responses/shipping_service/ping/failure.yml +55 -0
- data/spec/fixtures/responses/shipping_service/ping/success.yml +460 -0
- data/spec/fixtures/responses/shipping_service/submit_order_shipment_list.yml +55 -0
- data/spec/fixtures/responses/soap_fault.yml +53 -0
- data/spec/lib/channeladvisor/address_spec.rb +107 -0
- data/spec/lib/channeladvisor/admin_spec.rb +216 -0
- data/spec/lib/channeladvisor/line_item_spec.rb +147 -0
- data/spec/lib/channeladvisor/order_spec.rb +623 -0
- data/spec/lib/channeladvisor/order_status_spec.rb +36 -0
- data/spec/lib/channeladvisor/payment_spec.rb +38 -0
- data/spec/lib/channeladvisor/services/admin_service_spec.rb +65 -0
- data/spec/lib/channeladvisor/services/base_service_spec.rb +11 -0
- data/spec/lib/channeladvisor/services/inventory_service_spec.rb +214 -0
- data/spec/lib/channeladvisor/services/order_service_spec.rb +267 -0
- data/spec/lib/channeladvisor/services/shipping_service_spec.rb +288 -0
- data/spec/lib/channeladvisor/shipment_spec.rb +257 -0
- data/spec/lib/channeladvisor/shopping_cart_spec.rb +173 -0
- data/spec/lib/channeladvisor_spec.rb +18 -0
- data/spec/spec_helper.rb +29 -0
- data/spec/support/credentials.rb +15 -0
- data/spec/support/matchers/boolean.rb +17 -0
- data/spec/support/matchers/markup.rb +50 -0
- data/spec/support/rr.rb +38 -0
- data/spec/support/shared_examples.rb +4 -0
- data/spec/support/vcr.rb +38 -0
- metadata +501 -0
@@ -0,0 +1,623 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module ChannelAdvisor
|
4
|
+
describe Order do
|
5
|
+
describe ".new" do
|
6
|
+
let(:attrs) do
|
7
|
+
{
|
8
|
+
:number_of_matches=>"2",
|
9
|
+
:order_time_gmt=> DateTime.parse("2012-05-16T15:44:27+00:00 ((2456064j,56667s,683000000n),+0s,2299161j)"),
|
10
|
+
:last_update_date=> DateTime.parse("2012-05-16T15:44:27+00:00 ((2456064j,56667s,723000000n),+0s,2299161j)"),
|
11
|
+
:total_order_amount=>"44.9200",
|
12
|
+
:order_state=>"Active",
|
13
|
+
:date_cancelled_gmt=>DateTime.new(2012,05,17),
|
14
|
+
:order_id=>"14161613",
|
15
|
+
:client_order_identifier=>"14161613",
|
16
|
+
:seller_order_id=>"EFGH5678",
|
17
|
+
:reseller_id=>"999999",
|
18
|
+
:buyer_email_address=>"test@example.com",
|
19
|
+
:email_opt_in=>false,
|
20
|
+
:flag_description=>nil,
|
21
|
+
:custom_value_list=>{},
|
22
|
+
:buyer_ip_address=>"50.29.99.129",
|
23
|
+
:transaction_notes=>"Example notes",
|
24
|
+
:"@xmlns:q1"=>"http://api.channeladvisor.com/datacontracts/orders",
|
25
|
+
:"@xsi:type"=>"q1:OrderResponseDetailComplete"
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
subject { Order.new(attrs) }
|
30
|
+
|
31
|
+
its(:created_at) { should == attrs[:order_time_gmt] }
|
32
|
+
its(:updated_at) { should == attrs[:last_update_date] }
|
33
|
+
its(:total) { should == attrs[:total_order_amount].to_f }
|
34
|
+
its(:state) { should == attrs[:order_state] }
|
35
|
+
its(:cancelled_on) { should == attrs[:date_cancelled_gmt] }
|
36
|
+
its(:id) { should == attrs[:order_id].to_i }
|
37
|
+
its(:client_id) { should == attrs[:client_order_identifier] }
|
38
|
+
its(:seller_id) { should == attrs[:seller_order_id] }
|
39
|
+
its(:reseller_id) { should == attrs[:reseller_id] }
|
40
|
+
its(:buyer_email) { should == attrs[:buyer_email_address] }
|
41
|
+
its(:email_opt_in) { should == attrs[:email_opt_in] }
|
42
|
+
its(:flag_description) { should == attrs[:flag_description] }
|
43
|
+
its(:custom_values) { should == attrs[:custom_value_list] }
|
44
|
+
its(:buyer_ip_address) { should == attrs[:buyer_ip_address] }
|
45
|
+
its(:transaction_notes) { should == attrs[:transaction_notes] }
|
46
|
+
|
47
|
+
context "with shipping info" do
|
48
|
+
let(:attrs) do
|
49
|
+
{
|
50
|
+
:shipping_info=> {
|
51
|
+
:shipping_instructions => "do some stuff",
|
52
|
+
:estimated_ship_date => DateTime.new(2012,05,18),
|
53
|
+
:delivery_date => DateTime.new(2012,05,21),
|
54
|
+
:shipment_list => {
|
55
|
+
:shipment => {:shipping_carrier => "UPS", :shipping_class => "GND", :tracking_number => "1234567890"}
|
56
|
+
}
|
57
|
+
}
|
58
|
+
}
|
59
|
+
end
|
60
|
+
|
61
|
+
its(:shipping_instructions) { should == attrs[:shipping_info][:shipping_instructions] }
|
62
|
+
its(:estimated_ship_date) { should == attrs[:shipping_info][:estimated_ship_date] }
|
63
|
+
its(:delivery_date) { should == attrs[:shipping_info][:delivery_date] }
|
64
|
+
|
65
|
+
context "with one shipment" do
|
66
|
+
before(:each) do
|
67
|
+
stub.proxy(Shipment).new
|
68
|
+
@order = Order.new(attrs)
|
69
|
+
end
|
70
|
+
|
71
|
+
it "creates a new shipment object from the attributes hash" do
|
72
|
+
shipment = attrs[:shipping_info][:shipment_list][:shipment]
|
73
|
+
Shipment.should have_received.new(shipment)
|
74
|
+
end
|
75
|
+
|
76
|
+
it "creates a @shipments collection with one shipment" do
|
77
|
+
@order.shipments.should have(1).shipment
|
78
|
+
@order.shipments.first.should be_a Shipment
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context "with two shipments" do
|
83
|
+
before(:each) do
|
84
|
+
@shipments = attrs[:shipping_info][:shipment_list] = {
|
85
|
+
:shipment => [
|
86
|
+
{:shipping_carrier => "FedEx", :shipping_class => "Home Delivery", :tracking_number => "999999"},
|
87
|
+
{:shipping_carrier => "UPS", :shipping_class => "Ground", :tracking_number => "1234567"}
|
88
|
+
]
|
89
|
+
}
|
90
|
+
stub.proxy(Shipment).new
|
91
|
+
@order = Order.new(attrs)
|
92
|
+
end
|
93
|
+
|
94
|
+
it "creates a @shipments collection with two shipments" do
|
95
|
+
@order.shipments.should have(2).shipments
|
96
|
+
@order.shipments.each do |shipment|
|
97
|
+
shipment.should be_a Shipment
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
it "creates a new shipment object for each shipment in the attribute hash" do
|
102
|
+
@shipments[:shipment].each do |shipment|
|
103
|
+
Shipment.should have_received.new(shipment)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
|
110
|
+
context "with order_status in the attributes hash" do
|
111
|
+
let(:attrs) do
|
112
|
+
{:order_status => {}}
|
113
|
+
end
|
114
|
+
|
115
|
+
its(:status) { should be_an OrderStatus }
|
116
|
+
|
117
|
+
it "sets @status to an OrderStatus object" do
|
118
|
+
stub(OrderStatus).new
|
119
|
+
Order.new(attrs)
|
120
|
+
OrderStatus.should have_received.new(attrs[:order_status])
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
context "with payment_info in the attributes hash" do
|
125
|
+
let(:attrs) do
|
126
|
+
{:payment_info => {}}
|
127
|
+
end
|
128
|
+
|
129
|
+
its(:payment) { should be_a Payment }
|
130
|
+
|
131
|
+
it "sets @payment to a Payment object" do
|
132
|
+
stub(Payment).new
|
133
|
+
Order.new(attrs)
|
134
|
+
Payment.should have_received.new(attrs[:payment_info])
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
|
139
|
+
context "with billing_address in the attributes hash" do
|
140
|
+
let(:attrs) do
|
141
|
+
{:billing_info => {:billing_stuff => nil}}
|
142
|
+
end
|
143
|
+
|
144
|
+
its(:billing_address) { should be_an Address }
|
145
|
+
|
146
|
+
it "sets @billing_address to an Address object" do
|
147
|
+
stub(Address).new
|
148
|
+
order = Order.new(attrs)
|
149
|
+
Address.should have_received.new(attrs[:billing_info])
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
context "with shipping_address in the attributes hash" do
|
154
|
+
let(:attrs) do
|
155
|
+
{:shipping_info => {:shipping_stuff => nil}}
|
156
|
+
end
|
157
|
+
|
158
|
+
its(:shipping_address) { should be_an Address }
|
159
|
+
|
160
|
+
it "sets @shipping_address to an Address object" do
|
161
|
+
stub(Address).new
|
162
|
+
order = Order.new(attrs)
|
163
|
+
Address.should have_received.new(attrs[:shipping_info])
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
context "with shopping_cart in the attributes hash" do
|
168
|
+
let(:attrs) do
|
169
|
+
{:shopping_cart => {}}
|
170
|
+
end
|
171
|
+
|
172
|
+
its(:shopping_cart) { should be_a ShoppingCart }
|
173
|
+
|
174
|
+
it "sets @shopping_cart to a ShoppingCart object" do
|
175
|
+
stub(ShoppingCart).new
|
176
|
+
Order.new(attrs)
|
177
|
+
ShoppingCart.should have_received.new(attrs[:shopping_cart])
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
describe "#items_ship_cost" do
|
183
|
+
let(:items) { [@item] }
|
184
|
+
|
185
|
+
before(:each) do
|
186
|
+
@order = Order.new
|
187
|
+
@item = Object.new
|
188
|
+
stub(@item).shipping_cost { 1.50 }
|
189
|
+
stub(@order).shopping_cart.stub!.items { items }
|
190
|
+
end
|
191
|
+
|
192
|
+
context "with one item" do
|
193
|
+
it "returns the shipping cost of the order item" do
|
194
|
+
@order.items_ship_cost.should == 1.50
|
195
|
+
end
|
196
|
+
|
197
|
+
context "when item shipping cost is 0.00" do
|
198
|
+
it "returns 0.00" do
|
199
|
+
stub(@item).shipping_cost { 0.00 }
|
200
|
+
@order.items_ship_cost.should == 0.00
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
context "with two items" do
|
206
|
+
let(:items) { [@item, @item] }
|
207
|
+
|
208
|
+
it "returns the cumulative shipping cost of all order items" do
|
209
|
+
@order.items_ship_cost.should == 3.00
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
describe "#invoice_ship_cost" do
|
215
|
+
before(:each) do
|
216
|
+
@order = Order.new
|
217
|
+
invoice = Object.new
|
218
|
+
stub(invoice).type { "Shipping" }
|
219
|
+
stub(invoice).unit_price { unit_price }
|
220
|
+
stub(@order).shopping_cart.stub!.invoices { [invoice] }
|
221
|
+
end
|
222
|
+
|
223
|
+
context "when shipping cost is 0" do
|
224
|
+
let(:unit_price) { 0.00 }
|
225
|
+
|
226
|
+
it "returns nil" do
|
227
|
+
@order.invoice_ship_cost.should == nil
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
context "when shipping cost is not 0" do
|
232
|
+
let(:unit_price) { 5.99 }
|
233
|
+
|
234
|
+
it "returns the shipping cost from the shipping invoice" do
|
235
|
+
@order.invoice_ship_cost.should == 5.99
|
236
|
+
end
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
describe "#total_ship_cost" do
|
241
|
+
before(:each) do
|
242
|
+
@order = Order.new
|
243
|
+
end
|
244
|
+
context "when the invoice shipping cost is nil" do
|
245
|
+
it "returns the items shipping cost" do
|
246
|
+
stub(@order).invoice_ship_cost { nil }
|
247
|
+
stub(@order).items_ship_cost { 5.99 }
|
248
|
+
@order.total_ship_cost.should == 5.99
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
context "when the invoice shipping cost is not nil" do
|
253
|
+
it "returns the invoice shipping cost" do
|
254
|
+
stub(@order).invoice_ship_cost { 2.99 }
|
255
|
+
@order.total_ship_cost.should == 2.99
|
256
|
+
end
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
describe ".ping" do
|
261
|
+
use_vcr_cassette "responses/order/ping"
|
262
|
+
|
263
|
+
it "sends a ping request to the Order Service" do
|
264
|
+
mock.proxy(Services::OrderService).ping
|
265
|
+
Order.ping
|
266
|
+
end
|
267
|
+
|
268
|
+
context "with a success status" do
|
269
|
+
use_vcr_cassette "responses/order/ping/success"
|
270
|
+
|
271
|
+
it "returns true" do
|
272
|
+
Order.ping.should be_true
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
context "with a failure status" do
|
277
|
+
failure = {:code => 1, :message => "Service Unavailable"}
|
278
|
+
use_vcr_cassette "responses/order/ping/failure", :erb => failure
|
279
|
+
|
280
|
+
it "raises a ServiceFailure error" do
|
281
|
+
expect { Order.ping }.to raise_error ServiceFailure, failure[:message]
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
context "with a SOAP fault" do
|
286
|
+
use_vcr_cassette "responses/soap_fault", :match_requests_on => [:method]
|
287
|
+
|
288
|
+
it "raises a SOAP fault error" do
|
289
|
+
ChannelAdvisor.configure { |c| c.developer_key = "WRONG" }
|
290
|
+
expect { Order.ping }.to raise_error SOAPFault, "Server was unable to process request. Authentication failed."
|
291
|
+
end
|
292
|
+
|
293
|
+
it "stores the SOAP fault code" do
|
294
|
+
begin
|
295
|
+
Order.ping
|
296
|
+
rescue SOAPFault => fault
|
297
|
+
fault.code.should == "soap:Server"
|
298
|
+
end
|
299
|
+
end
|
300
|
+
end
|
301
|
+
|
302
|
+
context "with an HTTP error" do
|
303
|
+
http_status = {:code => 500, :message => "Internal Server Error"}
|
304
|
+
use_vcr_cassette "responses/http_error", :match_requests_on => [:method], :erb => http_status
|
305
|
+
|
306
|
+
it "raises an HTTP error" do
|
307
|
+
expect { Order.ping }.to raise_error HTTPError, "Failed with HTTP error #{http_status[:code]}"
|
308
|
+
end
|
309
|
+
|
310
|
+
it "stores the HTTP status code" do
|
311
|
+
begin
|
312
|
+
Order.ping
|
313
|
+
rescue HTTPError => error
|
314
|
+
error.code.should == http_status[:code]
|
315
|
+
end
|
316
|
+
end
|
317
|
+
end
|
318
|
+
end
|
319
|
+
|
320
|
+
describe ".list" do
|
321
|
+
context "with a success status" do
|
322
|
+
context "with no matching orders" do
|
323
|
+
use_vcr_cassette "responses/order/list/no_matching_orders"
|
324
|
+
|
325
|
+
it "returns a collection with zero orders" do
|
326
|
+
orders = Order.list(:order_ids => [00000000])
|
327
|
+
orders.should have(0).orders
|
328
|
+
end
|
329
|
+
end
|
330
|
+
|
331
|
+
context "with one matching order" do
|
332
|
+
use_vcr_cassette "responses/order/list/one_matching_order"
|
333
|
+
before { @orders = Order.list(:order_ids => [14161613]) }
|
334
|
+
|
335
|
+
it "returns a collection with one order" do
|
336
|
+
@orders.should have(1).order
|
337
|
+
end
|
338
|
+
|
339
|
+
it "contains only order objects" do
|
340
|
+
@orders.each do |order|
|
341
|
+
order.should be_an Order
|
342
|
+
end
|
343
|
+
end
|
344
|
+
end
|
345
|
+
|
346
|
+
context "with two matching orders" do
|
347
|
+
use_vcr_cassette "responses/order/list/two_matching_orders"
|
348
|
+
before { @orders = Order.list(:order_ids => [14161613, 14162751]) }
|
349
|
+
|
350
|
+
it "returns a collection with two orders" do
|
351
|
+
@orders.should have(2).orders
|
352
|
+
end
|
353
|
+
|
354
|
+
it "contains only order objects" do
|
355
|
+
@orders.each do |order|
|
356
|
+
order.should be_an Order
|
357
|
+
end
|
358
|
+
end
|
359
|
+
end
|
360
|
+
end
|
361
|
+
|
362
|
+
context "with a failure status" do
|
363
|
+
use_vcr_cassette "responses/order/list/failure"
|
364
|
+
|
365
|
+
it "raises a ServiceFailure error" do
|
366
|
+
message = "Extreme is not a valid value for DetailLevel"
|
367
|
+
expect { Order.list(:detail_level => "Extreme") }.to raise_error ServiceFailure, message
|
368
|
+
end
|
369
|
+
end
|
370
|
+
|
371
|
+
context "with a SOAP fault" do
|
372
|
+
use_vcr_cassette "responses/soap_fault", :match_requests_on => [:method]
|
373
|
+
|
374
|
+
it "raises a SOAP fault error" do
|
375
|
+
ChannelAdvisor.configure { |c| c.developer_key = "WRONG" }
|
376
|
+
expect { Order.list }.to raise_error SOAPFault, "Server was unable to process request. Authentication failed."
|
377
|
+
end
|
378
|
+
|
379
|
+
it "stores the SOAP fault code" do
|
380
|
+
begin
|
381
|
+
Order.list
|
382
|
+
rescue SOAPFault => fault
|
383
|
+
fault.code.should == "soap:Server"
|
384
|
+
end
|
385
|
+
end
|
386
|
+
end
|
387
|
+
|
388
|
+
context "with an HTTP error" do
|
389
|
+
http_status = {:code => 500, :message => "Internal Server Error"}
|
390
|
+
use_vcr_cassette "responses/http_error", :match_requests_on => [:method], :erb => http_status
|
391
|
+
|
392
|
+
it "raises an HTTP error" do
|
393
|
+
expect { Order.list }.to raise_error HTTPError, "Failed with HTTP error #{http_status[:code]}"
|
394
|
+
end
|
395
|
+
|
396
|
+
it "stores the HTTP status code" do
|
397
|
+
begin
|
398
|
+
Order.list
|
399
|
+
rescue HTTPError => error
|
400
|
+
error.code.should == http_status[:code]
|
401
|
+
end
|
402
|
+
end
|
403
|
+
end
|
404
|
+
|
405
|
+
context "with no criteria" do
|
406
|
+
use_vcr_cassette "responses/order/list/with_no_criteria"
|
407
|
+
|
408
|
+
it "sends a list request to the Order Service without criteria" do
|
409
|
+
mock.proxy(Services::OrderService).get_order_list({})
|
410
|
+
Order.list
|
411
|
+
end
|
412
|
+
end
|
413
|
+
|
414
|
+
context "with criteria" do
|
415
|
+
use_vcr_cassette "responses/order/list/with_criteria"
|
416
|
+
|
417
|
+
before(:each) do
|
418
|
+
@criteria = {
|
419
|
+
:created_from => DateTime.new(2012,05,15),
|
420
|
+
:created_to => DateTime.new(2012,05,17),
|
421
|
+
:updated_from => DateTime.new(2012,05,15),
|
422
|
+
:updated_to => DateTime.new(2012,05,17),
|
423
|
+
:join_dates => false,
|
424
|
+
:detail_level => "Low",
|
425
|
+
:export_state => "NotExported",
|
426
|
+
:order_ids => [123456, 567890],
|
427
|
+
:client_order_ids => ["ABCD1234", "EFGH5678"],
|
428
|
+
:state => "Active",
|
429
|
+
:payment_status => "Cleared",
|
430
|
+
:checkout_status => "Completed",
|
431
|
+
:shipping_status => "Unshipped",
|
432
|
+
:refund_status => "NoRefunds",
|
433
|
+
:distribution_center => "ABC",
|
434
|
+
:page_number => 1,
|
435
|
+
:page_size => 25
|
436
|
+
}
|
437
|
+
end
|
438
|
+
|
439
|
+
it "sends criteria to OrderService.get_order_list" do
|
440
|
+
mock.proxy(Services::OrderService).get_order_list(@criteria)
|
441
|
+
Order.list(@criteria)
|
442
|
+
end
|
443
|
+
|
444
|
+
context "with created_between date range criteria" do
|
445
|
+
it "sends only created_from and created_to criteria to OrderService.get_order_list" do
|
446
|
+
date_range = DateTime.new(2012,05,20)..DateTime.new(2012,05,25)
|
447
|
+
new_criteria = @criteria.merge(:created_between => date_range)
|
448
|
+
@criteria.merge!(:created_from => date_range.first, :created_to => date_range.last)
|
449
|
+
|
450
|
+
mock.proxy(Services::OrderService).get_order_list(@criteria)
|
451
|
+
Order.list(new_criteria)
|
452
|
+
end
|
453
|
+
end
|
454
|
+
|
455
|
+
context "with updated_between date range criteria" do
|
456
|
+
it "sends only updated_from and updated_to criteria to OrderService.get_order_list" do
|
457
|
+
date_range = DateTime.new(2012,05,20)..DateTime.new(2012,05,25)
|
458
|
+
new_criteria = @criteria.merge(:updated_between => date_range)
|
459
|
+
@criteria.merge!(:updated_from => date_range.first, :updated_to => date_range.last)
|
460
|
+
|
461
|
+
mock.proxy(Services::OrderService).get_order_list(@criteria)
|
462
|
+
Order.list(new_criteria)
|
463
|
+
end
|
464
|
+
end
|
465
|
+
end
|
466
|
+
end # list
|
467
|
+
|
468
|
+
describe "#set_export_status" do
|
469
|
+
use_vcr_cassette "responses/order/instance_set_export_status"
|
470
|
+
before { @order = Order.new(:order_id => 14162751, :client_order_identifier => "14162751") }
|
471
|
+
|
472
|
+
it "sends the client order ID and export status to OrderService.set_orders_export_status" do
|
473
|
+
mock.proxy(Services::OrderService).set_orders_export_status(["14162751"], false)
|
474
|
+
@order.set_export_status(false)
|
475
|
+
end
|
476
|
+
|
477
|
+
context "with a success status" do
|
478
|
+
context "with a result of true" do
|
479
|
+
use_vcr_cassette "responses/order/instance_set_export_status/success/result_true", :exclusive => true
|
480
|
+
|
481
|
+
it "returns true" do
|
482
|
+
result = @order.set_export_status(false)
|
483
|
+
result.should == true
|
484
|
+
end
|
485
|
+
end
|
486
|
+
|
487
|
+
context "with a result of false" do
|
488
|
+
use_vcr_cassette "responses/order/instance_set_export_status/success/result_false", :exclusive => true
|
489
|
+
|
490
|
+
it "returns false" do
|
491
|
+
order = Order.new(:order_id => 12345678, :client_order_id => "12345678")
|
492
|
+
result = order.set_export_status(false)
|
493
|
+
result.should == false
|
494
|
+
end
|
495
|
+
end
|
496
|
+
end
|
497
|
+
|
498
|
+
context "with a failure status" do
|
499
|
+
failure = {:code => 1, :message => "Service Unavailable"}
|
500
|
+
use_vcr_cassette "responses/order/instance_set_export_status/failure", :erb => failure
|
501
|
+
|
502
|
+
it "raises a ServiceFailure error" do
|
503
|
+
expect { @order.set_export_status(false) }.to raise_error ServiceFailure, failure[:message]
|
504
|
+
end
|
505
|
+
end
|
506
|
+
|
507
|
+
context "with a SOAP fault" do
|
508
|
+
use_vcr_cassette "responses/soap_fault", :match_requests_on => [:method]
|
509
|
+
|
510
|
+
it "raises a SOAP fault error" do
|
511
|
+
ChannelAdvisor.configure { |c| c.developer_key = "WRONG" }
|
512
|
+
expect { Order.list }.to raise_error SOAPFault, "Server was unable to process request. Authentication failed."
|
513
|
+
end
|
514
|
+
|
515
|
+
it "stores the SOAP fault code" do
|
516
|
+
begin
|
517
|
+
@order.set_export_status(false)
|
518
|
+
rescue SOAPFault => fault
|
519
|
+
fault.code.should == "soap:Server"
|
520
|
+
end
|
521
|
+
end
|
522
|
+
end
|
523
|
+
|
524
|
+
context "with an HTTP error" do
|
525
|
+
http_status = {:code => 500, :message => "Internal Server Error"}
|
526
|
+
use_vcr_cassette "responses/http_error", :match_requests_on => [:method], :erb => http_status
|
527
|
+
|
528
|
+
it "raises an HTTP error" do
|
529
|
+
expect { @order.set_export_status(false) }.to raise_error HTTPError, "Failed with HTTP error #{http_status[:code]}"
|
530
|
+
end
|
531
|
+
|
532
|
+
it "stores the HTTP status code" do
|
533
|
+
begin
|
534
|
+
@order.set_export_status(false)
|
535
|
+
rescue HTTPError => error
|
536
|
+
error.code.should == http_status[:code]
|
537
|
+
end
|
538
|
+
end
|
539
|
+
end
|
540
|
+
end # #set_export_status
|
541
|
+
|
542
|
+
describe ".set_export_status" do
|
543
|
+
context "with a success status" do
|
544
|
+
context "with one client order ID" do
|
545
|
+
use_vcr_cassette "responses/order/set_export_status/success/with_one_client_order_id"
|
546
|
+
|
547
|
+
it "sends the client order ID and export status to OrderService.set_orders_export_status" do
|
548
|
+
stub.proxy(Services::OrderService).set_orders_export_status
|
549
|
+
Order.set_export_status("14162751", false)
|
550
|
+
Services::OrderService.should have_received.set_orders_export_status(["14162751"], false)
|
551
|
+
end
|
552
|
+
|
553
|
+
it "returns a hash with one client order ID and boolean result" do
|
554
|
+
result = Order.set_export_status("14162751", false)
|
555
|
+
result.should be_a_boolean
|
556
|
+
end
|
557
|
+
end
|
558
|
+
|
559
|
+
context "with two client order IDs" do
|
560
|
+
use_vcr_cassette "responses/order/set_export_status/success/with_two_client_order_ids"
|
561
|
+
|
562
|
+
let(:client_order_ids) { ["14162751", "14161613"] }
|
563
|
+
|
564
|
+
it "sends the client order IDs and export statuses to OrderService.set_orders_export_status" do
|
565
|
+
stub.proxy(Services::OrderService).set_orders_export_status
|
566
|
+
Order.set_export_status(client_order_ids, false)
|
567
|
+
Services::OrderService.should have_received.set_orders_export_status(client_order_ids, false)
|
568
|
+
end
|
569
|
+
|
570
|
+
it "returns a hash with two client order IDs and boolean results" do
|
571
|
+
results = Order.set_export_status(client_order_ids, false)
|
572
|
+
client_order_ids.each do |client_order_id|
|
573
|
+
results[client_order_id].should be_a_boolean
|
574
|
+
end
|
575
|
+
end
|
576
|
+
end
|
577
|
+
end
|
578
|
+
|
579
|
+
context "with a failure status" do
|
580
|
+
failure = {:code => 1, :message => "Service Unavailable"}
|
581
|
+
use_vcr_cassette "responses/order/set_export_status/failure", :erb => failure
|
582
|
+
|
583
|
+
it "raises a ServiceFailure error" do
|
584
|
+
expect { Order.set_export_status(["14162751"], false) }.to raise_error ServiceFailure, failure[:message]
|
585
|
+
end
|
586
|
+
end
|
587
|
+
|
588
|
+
context "with a SOAP fault" do
|
589
|
+
use_vcr_cassette "responses/soap_fault", :match_requests_on => [:method]
|
590
|
+
|
591
|
+
it "raises a SOAP fault error" do
|
592
|
+
ChannelAdvisor.configure { |c| c.developer_key = "WRONG" }
|
593
|
+
expect { Order.list }.to raise_error SOAPFault, "Server was unable to process request. Authentication failed."
|
594
|
+
end
|
595
|
+
|
596
|
+
it "stores the SOAP fault code" do
|
597
|
+
begin
|
598
|
+
Order.set_export_status(["14162751"], false)
|
599
|
+
rescue SOAPFault => fault
|
600
|
+
fault.code.should == "soap:Server"
|
601
|
+
end
|
602
|
+
end
|
603
|
+
end
|
604
|
+
|
605
|
+
context "with an HTTP error" do
|
606
|
+
http_status = {:code => 500, :message => "Internal Server Error"}
|
607
|
+
use_vcr_cassette "responses/http_error", :match_requests_on => [:method], :erb => http_status
|
608
|
+
|
609
|
+
it "raises an HTTP error" do
|
610
|
+
expect { Order.set_export_status(["14162751"], false) }.to raise_error HTTPError, "Failed with HTTP error #{http_status[:code]}"
|
611
|
+
end
|
612
|
+
|
613
|
+
it "stores the HTTP status code" do
|
614
|
+
begin
|
615
|
+
Order.set_export_status(["14162751"], false)
|
616
|
+
rescue HTTPError => error
|
617
|
+
error.code.should == http_status[:code]
|
618
|
+
end
|
619
|
+
end
|
620
|
+
end
|
621
|
+
end # .set_export_status
|
622
|
+
end # Order
|
623
|
+
end # ChannelAdvisor
|