spree_core 3.2.1 → 3.2.2
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/lib/spree/core/version.rb +1 -1
- data/spree_core.gemspec +1 -1
- metadata +3 -206
- data/spec/fixtures/microdata.html +0 -22
- data/spec/fixtures/microdata_itemref.html +0 -15
- data/spec/fixtures/microdata_no_itemscope.html +0 -20
- data/spec/fixtures/thinking-cat.jpg +0 -0
- data/spec/helpers/base_helper_spec.rb +0 -200
- data/spec/helpers/products_helper_spec.rb +0 -289
- data/spec/lib/calculated_adjustments_spec.rb +0 -7
- data/spec/lib/i18n_spec.rb +0 -123
- data/spec/lib/search/base_spec.rb +0 -86
- data/spec/lib/spree/core/controller_helpers/auth_spec.rb +0 -103
- data/spec/lib/spree/core/controller_helpers/order_spec.rb +0 -110
- data/spec/lib/spree/core/controller_helpers/search_spec.rb +0 -17
- data/spec/lib/spree/core/controller_helpers/store_spec.rb +0 -72
- data/spec/lib/spree/core/controller_helpers/strong_parameters_spec.rb +0 -39
- data/spec/lib/spree/core/delegate_belongs_to_spec.rb +0 -22
- data/spec/lib/spree/core/importer/order_spec.rb +0 -605
- data/spec/lib/spree/core/number_generator_spec.rb +0 -175
- data/spec/lib/spree/core/token_generator_spec.rb +0 -24
- data/spec/lib/spree/core/validators/email_spec.rb +0 -53
- data/spec/lib/spree/core_spec.rb +0 -23
- data/spec/lib/spree/localized_number_spec.rb +0 -48
- data/spec/lib/spree/migrations_spec.rb +0 -36
- data/spec/lib/spree/money_spec.rb +0 -122
- data/spec/lib/tasks/exchanges_spec.rb +0 -136
- data/spec/mailers/order_mailer_spec.rb +0 -122
- data/spec/mailers/reimbursement_mailer_spec.rb +0 -47
- data/spec/mailers/shipment_mailer_spec.rb +0 -81
- data/spec/mailers/test_mailer_spec.rb +0 -38
- data/spec/models/option_type_prototype_spec.rb +0 -9
- data/spec/models/spree/ability_spec.rb +0 -251
- data/spec/models/spree/address_spec.rb +0 -402
- data/spec/models/spree/adjustable/adjuster/base_spec.rb +0 -10
- data/spec/models/spree/adjustable/adjuster/promotion_spec.rb +0 -211
- data/spec/models/spree/adjustable/adjuster/tax_spec.rb +0 -86
- data/spec/models/spree/adjustable/adjustments_updater_spec.rb +0 -26
- data/spec/models/spree/adjustment_spec.rb +0 -189
- data/spec/models/spree/app_configuration_spec.rb +0 -26
- data/spec/models/spree/asset_spec.rb +0 -28
- data/spec/models/spree/calculator/default_tax_spec.rb +0 -152
- data/spec/models/spree/calculator/flat_percent_item_total_spec.rb +0 -25
- data/spec/models/spree/calculator/flat_rate_spec.rb +0 -47
- data/spec/models/spree/calculator/flexi_rate_spec.rb +0 -41
- data/spec/models/spree/calculator/percent_on_line_item_spec.rb +0 -15
- data/spec/models/spree/calculator/price_sack_spec.rb +0 -30
- data/spec/models/spree/calculator/refunds/default_refund_amount_spec.rb +0 -47
- data/spec/models/spree/calculator/shipping.rb +0 -8
- data/spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb +0 -23
- data/spec/models/spree/calculator/shipping/flat_rate_spec.rb +0 -13
- data/spec/models/spree/calculator/shipping/flexi_rate_spec.rb +0 -52
- data/spec/models/spree/calculator/shipping/per_item_spec.rb +0 -20
- data/spec/models/spree/calculator/shipping/price_sack_spec.rb +0 -29
- data/spec/models/spree/calculator/tiered_flat_rate_spec.rb +0 -40
- data/spec/models/spree/calculator/tiered_percent_spec.rb +0 -51
- data/spec/models/spree/calculator_spec.rb +0 -69
- data/spec/models/spree/classification_spec.rb +0 -93
- data/spec/models/spree/concerns/display_money_spec.rb +0 -43
- data/spec/models/spree/concerns/user_methods_spec.rb +0 -82
- data/spec/models/spree/concerns/vat_price_calculation_spec.rb +0 -66
- data/spec/models/spree/country_spec.rb +0 -55
- data/spec/models/spree/credit_card_spec.rb +0 -328
- data/spec/models/spree/customer_return_spec.rb +0 -240
- data/spec/models/spree/exchange_spec.rb +0 -75
- data/spec/models/spree/gateway/bogus_simple.rb +0 -20
- data/spec/models/spree/gateway/bogus_spec.rb +0 -13
- data/spec/models/spree/gateway_spec.rb +0 -61
- data/spec/models/spree/image_spec.rb +0 -8
- data/spec/models/spree/inventory_unit_spec.rb +0 -256
- data/spec/models/spree/line_item_spec.rb +0 -346
- data/spec/models/spree/option_type_spec.rb +0 -14
- data/spec/models/spree/option_value_spec.rb +0 -18
- data/spec/models/spree/order/address_spec.rb +0 -50
- data/spec/models/spree/order/adjustments_spec.rb +0 -29
- data/spec/models/spree/order/callbacks_spec.rb +0 -42
- data/spec/models/spree/order/checkout_spec.rb +0 -770
- data/spec/models/spree/order/currency_updater_spec.rb +0 -32
- data/spec/models/spree/order/finalizing_spec.rb +0 -114
- data/spec/models/spree/order/helpers_spec.rb +0 -5
- data/spec/models/spree/order/payment_spec.rb +0 -214
- data/spec/models/spree/order/risk_assessment_spec.rb +0 -84
- data/spec/models/spree/order/shipments_spec.rb +0 -43
- data/spec/models/spree/order/state_machine_spec.rb +0 -212
- data/spec/models/spree/order/store_credit_spec.rb +0 -426
- data/spec/models/spree/order/tax_spec.rb +0 -84
- data/spec/models/spree/order/totals_spec.rb +0 -24
- data/spec/models/spree/order/updating_spec.rb +0 -18
- data/spec/models/spree/order/validations_spec.rb +0 -15
- data/spec/models/spree/order_contents_spec.rb +0 -297
- data/spec/models/spree/order_inventory_spec.rb +0 -239
- data/spec/models/spree/order_merger_spec.rb +0 -135
- data/spec/models/spree/order_spec.rb +0 -1046
- data/spec/models/spree/order_updater_spec.rb +0 -305
- data/spec/models/spree/payment/gateway_options_spec.rb +0 -127
- data/spec/models/spree/payment/store_credit_spec.rb +0 -60
- data/spec/models/spree/payment_method/store_credit_spec.rb +0 -291
- data/spec/models/spree/payment_method_spec.rb +0 -103
- data/spec/models/spree/payment_spec.rb +0 -919
- data/spec/models/spree/preference_spec.rb +0 -80
- data/spec/models/spree/preferences/configuration_spec.rb +0 -30
- data/spec/models/spree/preferences/preferable_spec.rb +0 -344
- data/spec/models/spree/preferences/scoped_store_spec.rb +0 -58
- data/spec/models/spree/preferences/store_spec.rb +0 -46
- data/spec/models/spree/price_spec.rb +0 -128
- data/spec/models/spree/product/scopes_spec.rb +0 -183
- data/spec/models/spree/product_duplicator_spec.rb +0 -103
- data/spec/models/spree/product_filter_spec.rb +0 -26
- data/spec/models/spree/product_option_type_spec.rb +0 -9
- data/spec/models/spree/product_promotion_rule_spec.rb +0 -9
- data/spec/models/spree/product_property_spec.rb +0 -26
- data/spec/models/spree/product_spec.rb +0 -629
- data/spec/models/spree/promotion/actions/create_adjustment_spec.rb +0 -113
- data/spec/models/spree/promotion/actions/create_item_adjustments_spec.rb +0 -148
- data/spec/models/spree/promotion/actions/create_line_items_spec.rb +0 -86
- data/spec/models/spree/promotion/actions/free_shipping_spec.rb +0 -36
- data/spec/models/spree/promotion/rules/country_spec.rb +0 -36
- data/spec/models/spree/promotion/rules/first_order_spec.rb +0 -75
- data/spec/models/spree/promotion/rules/item_total_spec.rb +0 -282
- data/spec/models/spree/promotion/rules/one_use_per_user_spec.rb +0 -42
- data/spec/models/spree/promotion/rules/option_value_spec.rb +0 -90
- data/spec/models/spree/promotion/rules/product_spec.rb +0 -143
- data/spec/models/spree/promotion/rules/taxon_spec.rb +0 -102
- data/spec/models/spree/promotion/rules/user_logged_in_spec.rb +0 -27
- data/spec/models/spree/promotion/rules/user_spec.rb +0 -45
- data/spec/models/spree/promotion_action_spec.rb +0 -10
- data/spec/models/spree/promotion_category_spec.rb +0 -17
- data/spec/models/spree/promotion_handler/cart_spec.rb +0 -102
- data/spec/models/spree/promotion_handler/coupon_spec.rb +0 -323
- data/spec/models/spree/promotion_handler/free_shipping_spec.rb +0 -48
- data/spec/models/spree/promotion_handler/page_spec.rb +0 -44
- data/spec/models/spree/promotion_rule_spec.rb +0 -29
- data/spec/models/spree/promotion_rule_taxon_spec.rb +0 -9
- data/spec/models/spree/promotion_rule_user_spec.rb +0 -9
- data/spec/models/spree/promotion_spec.rb +0 -679
- data/spec/models/spree/property_prototype_spec.rb +0 -9
- data/spec/models/spree/property_spec.rb +0 -5
- data/spec/models/spree/prototype_spec.rb +0 -5
- data/spec/models/spree/prototype_taxon_spec.rb +0 -9
- data/spec/models/spree/refund_reason_spec.rb +0 -20
- data/spec/models/spree/refund_spec.rb +0 -195
- data/spec/models/spree/reimbursement/credit_spec.rb +0 -36
- data/spec/models/spree/reimbursement/reimbursement_type_engine_spec.rb +0 -140
- data/spec/models/spree/reimbursement/reimbursement_type_validator_spec.rb +0 -83
- data/spec/models/spree/reimbursement_performer_spec.rb +0 -30
- data/spec/models/spree/reimbursement_spec.rb +0 -188
- data/spec/models/spree/reimbursement_tax_calculator_spec.rb +0 -63
- data/spec/models/spree/reimbursement_type/credit_spec.rb +0 -53
- data/spec/models/spree/reimbursement_type/exchange_spec.rb +0 -46
- data/spec/models/spree/reimbursement_type/original_payment_spec.rb +0 -55
- data/spec/models/spree/reimbursement_type/store_credit_spec.rb +0 -101
- data/spec/models/spree/return_authorization_reason_spec.rb +0 -7
- data/spec/models/spree/return_authorization_spec.rb +0 -230
- data/spec/models/spree/return_item/eligibility_validator/default_spec.rb +0 -77
- data/spec/models/spree/return_item/eligibility_validator/inventory_shipped_spec.rb +0 -58
- data/spec/models/spree/return_item/eligibility_validator/no_reimbursements_spec.rb +0 -61
- data/spec/models/spree/return_item/eligibility_validator/order_completed_spec.rb +0 -32
- data/spec/models/spree/return_item/eligibility_validator/rma_required_spec.rb +0 -29
- data/spec/models/spree/return_item/eligibility_validator/time_since_purchase_spec.rb +0 -35
- data/spec/models/spree/return_item/exchange_variant_eligibility/same_option_value_spec.rb +0 -65
- data/spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb +0 -43
- data/spec/models/spree/return_item_spec.rb +0 -731
- data/spec/models/spree/returns_calculator_spec.rb +0 -14
- data/spec/models/spree/role_spec.rb +0 -7
- data/spec/models/spree/shipment_spec.rb +0 -742
- data/spec/models/spree/shipping_calculator_spec.rb +0 -45
- data/spec/models/spree/shipping_category_spec.rb +0 -19
- data/spec/models/spree/shipping_method_spec.rb +0 -95
- data/spec/models/spree/shipping_rate_spec.rb +0 -140
- data/spec/models/spree/state_spec.rb +0 -29
- data/spec/models/spree/stock/availability_validator_spec.rb +0 -36
- data/spec/models/spree/stock/content_item_spec.rb +0 -31
- data/spec/models/spree/stock/coordinator_spec.rb +0 -61
- data/spec/models/spree/stock/differentiator_spec.rb +0 -39
- data/spec/models/spree/stock/estimator_spec.rb +0 -202
- data/spec/models/spree/stock/inventory_unit_builder_spec.rb +0 -38
- data/spec/models/spree/stock/package_spec.rb +0 -182
- data/spec/models/spree/stock/packer_spec.rb +0 -70
- data/spec/models/spree/stock/prioritizer_spec.rb +0 -125
- data/spec/models/spree/stock/quantifier_spec.rb +0 -126
- data/spec/models/spree/stock/splitter/backordered_spec.rb +0 -29
- data/spec/models/spree/stock/splitter/base_spec.rb +0 -21
- data/spec/models/spree/stock/splitter/shipping_category_spec.rb +0 -47
- data/spec/models/spree/stock/splitter/weight_spec.rb +0 -32
- data/spec/models/spree/stock_item_spec.rb +0 -432
- data/spec/models/spree/stock_location_spec.rb +0 -243
- data/spec/models/spree/stock_movement_spec.rb +0 -120
- data/spec/models/spree/stock_transfer_spec.rb +0 -50
- data/spec/models/spree/store_credit_event_spec.rb +0 -101
- data/spec/models/spree/store_credit_spec.rb +0 -786
- data/spec/models/spree/store_spec.rb +0 -78
- data/spec/models/spree/tax_category_spec.rb +0 -32
- data/spec/models/spree/tax_rate_spec.rb +0 -561
- data/spec/models/spree/taxon_spec.rb +0 -85
- data/spec/models/spree/taxonomy_spec.rb +0 -18
- data/spec/models/spree/tracker_spec.rb +0 -21
- data/spec/models/spree/user_spec.rb +0 -203
- data/spec/models/spree/variant_spec.rb +0 -818
- data/spec/models/spree/zone_member_spec.rb +0 -38
- data/spec/models/spree/zone_spec.rb +0 -472
- data/spec/spec_helper.rb +0 -79
- data/spec/support/big_decimal.rb +0 -5
- data/spec/support/concerns/adjustment_source.rb +0 -23
- data/spec/support/concerns/default_price.rb +0 -37
- data/spec/support/rake.rb +0 -13
- data/spec/support/test_gateway.rb +0 -2
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
require 'spree/testing_support/url_helpers'
|
|
3
|
-
|
|
4
|
-
class FakesController < ApplicationController
|
|
5
|
-
include Spree::Core::ControllerHelpers::Auth
|
|
6
|
-
def index; render plain: 'index'; end
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
describe Spree::Core::ControllerHelpers::Auth, type: :controller do
|
|
10
|
-
controller(FakesController) {}
|
|
11
|
-
include Spree::TestingSupport::UrlHelpers
|
|
12
|
-
|
|
13
|
-
describe '#current_ability' do
|
|
14
|
-
it 'returns Spree::Ability instance' do
|
|
15
|
-
expect(controller.current_ability.class).to eq Spree::Ability
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
describe '#redirect_back_or_default' do
|
|
20
|
-
controller(FakesController) do
|
|
21
|
-
def index; redirect_back_or_default('/'); end
|
|
22
|
-
end
|
|
23
|
-
it 'redirects to session url' do
|
|
24
|
-
session[:spree_user_return_to] = '/redirect'
|
|
25
|
-
get :index
|
|
26
|
-
expect(response).to redirect_to('/redirect')
|
|
27
|
-
end
|
|
28
|
-
it 'redirects to HTTP_REFERER' do
|
|
29
|
-
request.env["HTTP_REFERER"] = '/dummy_redirect'
|
|
30
|
-
get :index
|
|
31
|
-
expect(response).to redirect_to('/dummy_redirect')
|
|
32
|
-
end
|
|
33
|
-
it 'redirects to default page' do
|
|
34
|
-
get :index
|
|
35
|
-
expect(response).to redirect_to('/')
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
describe '#set_guest_token' do
|
|
40
|
-
controller(FakesController) do
|
|
41
|
-
def index
|
|
42
|
-
set_guest_token
|
|
43
|
-
render plain: 'index'
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
it 'sends cookie header' do
|
|
47
|
-
get :index
|
|
48
|
-
expect(response.cookies['guest_token']).not_to be_nil
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
describe '#store_location' do
|
|
53
|
-
it 'sets session return url' do
|
|
54
|
-
allow(controller).to receive_messages(request: double(fullpath: '/redirect'))
|
|
55
|
-
controller.store_location
|
|
56
|
-
expect(session[:spree_user_return_to]).to eq '/redirect'
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
describe '#try_spree_current_user' do
|
|
61
|
-
it 'calls spree_current_user when define spree_current_user method' do
|
|
62
|
-
expect(controller).to receive(:spree_current_user)
|
|
63
|
-
controller.try_spree_current_user
|
|
64
|
-
end
|
|
65
|
-
it 'calls current_spree_user when define current_spree_user method' do
|
|
66
|
-
expect(controller).to receive(:current_spree_user)
|
|
67
|
-
controller.try_spree_current_user
|
|
68
|
-
end
|
|
69
|
-
it 'returns nil' do
|
|
70
|
-
expect(controller.try_spree_current_user).to eq nil
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
describe '#redirect_unauthorized_access' do
|
|
75
|
-
controller(FakesController) do
|
|
76
|
-
def index; redirect_unauthorized_access; end
|
|
77
|
-
end
|
|
78
|
-
context 'when logged in' do
|
|
79
|
-
before do
|
|
80
|
-
allow(controller).to receive_messages(try_spree_current_user: double('User', id: 1, last_incomplete_spree_order: nil))
|
|
81
|
-
end
|
|
82
|
-
it 'redirects forbidden path' do
|
|
83
|
-
get :index
|
|
84
|
-
expect(response).to redirect_to(spree.forbidden_path)
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
context 'when guest user' do
|
|
88
|
-
before do
|
|
89
|
-
allow(controller).to receive_messages(try_spree_current_user: nil)
|
|
90
|
-
end
|
|
91
|
-
it 'redirects login path' do
|
|
92
|
-
allow(controller).to receive_messages(spree_login_path: '/login')
|
|
93
|
-
get :index
|
|
94
|
-
expect(response).to redirect_to('/login')
|
|
95
|
-
end
|
|
96
|
-
it 'redirects root path' do
|
|
97
|
-
allow(controller).to receive_message_chain(:spree, :root_path).and_return('/root_path')
|
|
98
|
-
get :index
|
|
99
|
-
expect(response).to redirect_to('/root_path')
|
|
100
|
-
end
|
|
101
|
-
end
|
|
102
|
-
end
|
|
103
|
-
end
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
class FakesController < ApplicationController
|
|
4
|
-
include Spree::Core::ControllerHelpers::Order
|
|
5
|
-
end
|
|
6
|
-
|
|
7
|
-
describe Spree::Core::ControllerHelpers::Order, type: :controller do
|
|
8
|
-
controller(FakesController) {}
|
|
9
|
-
|
|
10
|
-
let(:user) { create(:user) }
|
|
11
|
-
let(:order) { create(:order, user: user) }
|
|
12
|
-
let(:store) { create(:store) }
|
|
13
|
-
|
|
14
|
-
describe '#simple_current_order' do
|
|
15
|
-
before { allow(controller).to receive_messages(try_spree_current_user: user) }
|
|
16
|
-
it "returns an empty order" do
|
|
17
|
-
expect(controller.simple_current_order.item_count).to eq 0
|
|
18
|
-
end
|
|
19
|
-
it 'returns Spree::Order instance' do
|
|
20
|
-
allow(controller).to receive_messages(cookies: double(signed: { guest_token: order.guest_token }))
|
|
21
|
-
expect(controller.simple_current_order).to eq order
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
describe '#current_order' do
|
|
26
|
-
before {
|
|
27
|
-
allow(controller).to receive_messages(current_store: store)
|
|
28
|
-
allow(controller).to receive_messages(try_spree_current_user: user)
|
|
29
|
-
}
|
|
30
|
-
context 'create_order_if_necessary option is false' do
|
|
31
|
-
let!(:order) { create :order, user: user }
|
|
32
|
-
it 'returns current order' do
|
|
33
|
-
expect(controller.current_order).to eq order
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
context 'create_order_if_necessary option is true' do
|
|
37
|
-
it 'creates new order' do
|
|
38
|
-
expect {
|
|
39
|
-
controller.current_order(create_order_if_necessary: true)
|
|
40
|
-
}.to change(Spree::Order, :count).to(1)
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
it 'assigns the current_store id' do
|
|
44
|
-
controller.current_order(create_order_if_necessary: true)
|
|
45
|
-
expect(Spree::Order.last.store_id).to eq store.id
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
context 'gets using the guest_token' do
|
|
50
|
-
let!(:order) { create :order, user: user }
|
|
51
|
-
let!(:guest_order) { create :order, user: nil, email: nil, guest_token: 'token' }
|
|
52
|
-
|
|
53
|
-
before do
|
|
54
|
-
expect(controller).to receive(:current_order_params).and_return(
|
|
55
|
-
currency: Spree::Config[:currency], guest_token: 'token', store_id: guest_order.store_id, user_id: user.id,
|
|
56
|
-
)
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
specify 'without the guest token being bound to any user yet' do
|
|
60
|
-
expect(controller.current_order).to eq guest_order
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
describe '#associate_user' do
|
|
66
|
-
before do
|
|
67
|
-
allow(controller).to receive_messages(current_order: order, try_spree_current_user: user)
|
|
68
|
-
end
|
|
69
|
-
context "user's email is blank" do
|
|
70
|
-
let(:user) { create(:user, email: '') }
|
|
71
|
-
it 'calls Spree::Order#associate_user! method' do
|
|
72
|
-
expect_any_instance_of(Spree::Order).to receive(:associate_user!)
|
|
73
|
-
controller.associate_user
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
context "user isn't blank" do
|
|
77
|
-
it 'does not calls Spree::Order#associate_user! method' do
|
|
78
|
-
expect_any_instance_of(Spree::Order).not_to receive(:associate_user!)
|
|
79
|
-
controller.associate_user
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
describe '#set_current_order' do
|
|
85
|
-
let(:incomplete_order) { create(:order, user: user) }
|
|
86
|
-
before { allow(controller).to receive_messages(try_spree_current_user: user) }
|
|
87
|
-
|
|
88
|
-
context 'when current order not equal to users incomplete orders' do
|
|
89
|
-
before { allow(controller).to receive_messages(current_order: order, last_incomplete_order: incomplete_order, cookies: double(signed: { guest_token: 'guest_token' })) }
|
|
90
|
-
|
|
91
|
-
it 'calls Spree::Order#merge! method' do
|
|
92
|
-
expect(order).to receive(:merge!).with(incomplete_order, user)
|
|
93
|
-
controller.set_current_order
|
|
94
|
-
end
|
|
95
|
-
end
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
describe '#current_currency' do
|
|
99
|
-
it 'returns current currency' do
|
|
100
|
-
Spree::Config[:currency] = 'USD'
|
|
101
|
-
expect(controller.current_currency).to eq 'USD'
|
|
102
|
-
end
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
describe '#ip_address' do
|
|
106
|
-
it 'returns remote ip' do
|
|
107
|
-
expect(controller.ip_address).to eq request.remote_ip
|
|
108
|
-
end
|
|
109
|
-
end
|
|
110
|
-
end
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
class FakesController < ApplicationController
|
|
4
|
-
include Spree::Core::ControllerHelpers::Search
|
|
5
|
-
end
|
|
6
|
-
|
|
7
|
-
describe Spree::Core::ControllerHelpers::Search, type: :controller do
|
|
8
|
-
controller(FakesController) {}
|
|
9
|
-
|
|
10
|
-
describe '#build_searcher' do
|
|
11
|
-
it 'returns Spree::Core::Search::Base instance' do
|
|
12
|
-
allow(controller).to receive_messages(try_spree_current_user: create(:user),
|
|
13
|
-
current_currency: 'USD')
|
|
14
|
-
expect(controller.build_searcher({}).class).to eq Spree::Core::Search::Base
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
class FakesController < ApplicationController
|
|
4
|
-
include Spree::Core::ControllerHelpers::Auth
|
|
5
|
-
include Spree::Core::ControllerHelpers::Order
|
|
6
|
-
include Spree::Core::ControllerHelpers::Store
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
describe Spree::Core::ControllerHelpers::Store, type: :controller do
|
|
10
|
-
controller(FakesController) {}
|
|
11
|
-
|
|
12
|
-
describe '#current_store' do
|
|
13
|
-
let!(:store) { create :store, default: true }
|
|
14
|
-
it 'returns current store' do
|
|
15
|
-
expect(controller.current_store).to eq store
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
describe "#current_price_options" do
|
|
20
|
-
subject(:current_price_options) { controller.current_price_options }
|
|
21
|
-
|
|
22
|
-
context "when there is a default tax zone" do
|
|
23
|
-
let(:default_zone) { Spree::Zone.new }
|
|
24
|
-
|
|
25
|
-
before do
|
|
26
|
-
allow(Spree::Zone).to receive(:default_tax).and_return(default_zone)
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
context "when there is no current order" do
|
|
30
|
-
it "returns the default tax zone" do
|
|
31
|
-
is_expected.to include(tax_zone: default_zone)
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
context "when there is a current order" do
|
|
36
|
-
let(:other_zone) { Spree::Zone.new }
|
|
37
|
-
let(:current_order) { Spree::Order.new }
|
|
38
|
-
|
|
39
|
-
before do
|
|
40
|
-
allow(current_order).to receive(:tax_zone).and_return(other_zone)
|
|
41
|
-
allow(controller).to receive(:current_order).and_return(current_order)
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
it { is_expected.to include(tax_zone: other_zone) }
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
context "when there is no default tax zone" do
|
|
49
|
-
before do
|
|
50
|
-
allow(Spree::Zone).to receive(:default_tax).and_return(nil)
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
context "when there is no current order" do
|
|
54
|
-
it "return nil when asked for the current tax zone" do
|
|
55
|
-
expect(current_price_options[:tax_zone]).to be_nil
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
context "when there is a current order" do
|
|
60
|
-
let(:other_zone) { Spree::Zone.new }
|
|
61
|
-
let(:current_order) { Spree::Order.new }
|
|
62
|
-
|
|
63
|
-
before do
|
|
64
|
-
allow(current_order).to receive(:tax_zone).and_return(other_zone)
|
|
65
|
-
allow(controller).to receive(:current_order).and_return(current_order)
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
it { is_expected.to include(tax_zone: other_zone) }
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
end
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
class FakesController < ApplicationController
|
|
4
|
-
include Spree::Core::ControllerHelpers::StrongParameters
|
|
5
|
-
end
|
|
6
|
-
|
|
7
|
-
describe Spree::Core::ControllerHelpers::StrongParameters, type: :controller do
|
|
8
|
-
controller(FakesController) {}
|
|
9
|
-
|
|
10
|
-
describe '#permitted_attributes' do
|
|
11
|
-
it 'returns Spree::PermittedAttributes module' do
|
|
12
|
-
expect(controller.permitted_attributes).to eq Spree::PermittedAttributes
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
describe '#permitted_payment_attributes' do
|
|
17
|
-
it 'returns Array class' do
|
|
18
|
-
expect(controller.permitted_payment_attributes.class).to eq Array
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
describe '#permitted_checkout_attributes' do
|
|
23
|
-
it 'returns Array class' do
|
|
24
|
-
expect(controller.permitted_checkout_attributes.class).to eq Array
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
describe '#permitted_order_attributes' do
|
|
29
|
-
it 'returns Array class' do
|
|
30
|
-
expect(controller.permitted_order_attributes.class).to eq Array
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
describe '#permitted_product_attributes' do
|
|
35
|
-
it 'returns Array class' do
|
|
36
|
-
expect(controller.permitted_product_attributes.class).to eq Array
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
# This is a bit of a insane spec I have to admit
|
|
4
|
-
# Chosed the spree_payment_methods table because it has a `name` column
|
|
5
|
-
# already. Stubs wouldn't work here (the delegation runs before this spec is
|
|
6
|
-
# loaded) and adding a column here might make the test even crazy so here we go
|
|
7
|
-
module Spree
|
|
8
|
-
class DelegateBelongsToStubModel < Spree::Base
|
|
9
|
-
self.table_name = "spree_payment_methods"
|
|
10
|
-
belongs_to :product
|
|
11
|
-
delegate_belongs_to :product, :name
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
describe DelegateBelongsToStubModel do
|
|
15
|
-
context "model has column attr delegated to associated object" do
|
|
16
|
-
it "doesnt touch the associated object" do
|
|
17
|
-
expect(subject).not_to receive(:product)
|
|
18
|
-
subject.name
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
@@ -1,605 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
module Spree
|
|
4
|
-
module Core
|
|
5
|
-
describe Importer::Order do
|
|
6
|
-
let!(:country) { create(:country) }
|
|
7
|
-
let!(:state) { country.states.first || create(:state, country: country) }
|
|
8
|
-
let!(:stock_location) { create(:stock_location, admin_name: 'Admin Name') }
|
|
9
|
-
|
|
10
|
-
let(:user) { stub_model(LegacyUser, email: 'fox@mudler.com') }
|
|
11
|
-
let(:shipping_method) { create(:shipping_method) }
|
|
12
|
-
let(:payment_method) { create(:check_payment_method) }
|
|
13
|
-
|
|
14
|
-
let(:product) do
|
|
15
|
-
product = Spree::Product.create(name: 'Test',
|
|
16
|
-
sku: 'TEST-1',
|
|
17
|
-
price: 33.22, available_on: Time.current - 1.day)
|
|
18
|
-
product.shipping_category = create(:shipping_category)
|
|
19
|
-
product.save
|
|
20
|
-
product
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
let(:variant) do
|
|
24
|
-
variant = product.master
|
|
25
|
-
variant.stock_items.each { |si| si.update_attribute(:count_on_hand, 10) }
|
|
26
|
-
variant
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
let(:sku) { variant.sku }
|
|
30
|
-
let(:variant_id) { variant.id }
|
|
31
|
-
|
|
32
|
-
let(:line_items) { [{ variant_id: variant.id, quantity: 5 }] }
|
|
33
|
-
let(:ship_address) do
|
|
34
|
-
{
|
|
35
|
-
address1: '123 Testable Way',
|
|
36
|
-
firstname: 'Fox',
|
|
37
|
-
lastname: 'Mulder',
|
|
38
|
-
city: 'Washington',
|
|
39
|
-
country_id: country.id,
|
|
40
|
-
state_id: state.id,
|
|
41
|
-
zipcode: '66666',
|
|
42
|
-
phone: '666-666-6666'
|
|
43
|
-
}
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
it 'can import an order number' do
|
|
47
|
-
params = { number: '123-456-789' }
|
|
48
|
-
order = Importer::Order.import(user, params)
|
|
49
|
-
expect(order.number).to eq '123-456-789'
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
it 'optionally add completed at' do
|
|
53
|
-
params = {
|
|
54
|
-
email: 'test@test.com',
|
|
55
|
-
completed_at: Time.current,
|
|
56
|
-
line_items_attributes: line_items
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
order = Importer::Order.import(user, params)
|
|
60
|
-
expect(order).to be_completed
|
|
61
|
-
expect(order.state).to eq 'complete'
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
it "assigns order[email] over user email to order" do
|
|
65
|
-
params = { email: 'wooowww@test.com' }
|
|
66
|
-
order = Importer::Order.import(user, params)
|
|
67
|
-
expect(order.email).to eq params[:email]
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
context "assigning a user to an order" do
|
|
71
|
-
let(:other_user) { stub_model(LegacyUser, email: 'dana@scully.com') }
|
|
72
|
-
|
|
73
|
-
context "as an admin" do
|
|
74
|
-
before { allow(user).to receive_messages has_spree_role?: true }
|
|
75
|
-
|
|
76
|
-
context "a user's id is not provided" do
|
|
77
|
-
# this is a regression spec for an issue we ran into at Bonobos
|
|
78
|
-
it "doesn't unassociate the admin from the order" do
|
|
79
|
-
params = {}
|
|
80
|
-
order = Importer::Order.import(user, params)
|
|
81
|
-
expect(order.user_id).to eq(user.id)
|
|
82
|
-
end
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
context "as a user" do
|
|
87
|
-
before { allow(user).to receive_messages has_spree_role?: false }
|
|
88
|
-
it "does not assign the order to the other user" do
|
|
89
|
-
params = { user_id: other_user.id }
|
|
90
|
-
order = Importer::Order.import(user, params)
|
|
91
|
-
expect(order.user_id).to eq(user.id)
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
it 'can build an order from API with just line items' do
|
|
97
|
-
params = { line_items_attributes: line_items }
|
|
98
|
-
|
|
99
|
-
expect(Importer::Order).to receive(:ensure_variant_id_from_params).and_return(variant_id: variant.id,
|
|
100
|
-
quantity: 5)
|
|
101
|
-
order = Importer::Order.import(user, params)
|
|
102
|
-
expect(order.user).to eq(nil)
|
|
103
|
-
line_item = order.line_items.first
|
|
104
|
-
expect(line_item.quantity).to eq(5)
|
|
105
|
-
expect(line_item.variant_id).to eq(variant_id)
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
it 'handles line_item building exceptions' do
|
|
109
|
-
line_items.first[:variant_id] = 'XXX'
|
|
110
|
-
params = { line_items_attributes: line_items }
|
|
111
|
-
|
|
112
|
-
expect { Importer::Order.import(user, params) }.to raise_error /XXX/
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
it 'handles line_item updating exceptions' do
|
|
116
|
-
line_items.first[:currency] = 'GBP'
|
|
117
|
-
params = { line_items_attributes: line_items }
|
|
118
|
-
|
|
119
|
-
expect { Importer::Order.import(user, params) }.to raise_error /Validation failed/
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
it 'can build an order from API with variant sku' do
|
|
123
|
-
params = { line_items_attributes: [{ sku: sku, quantity: 5 }] }
|
|
124
|
-
|
|
125
|
-
order = Importer::Order.import(user, params)
|
|
126
|
-
|
|
127
|
-
line_item = order.line_items.first
|
|
128
|
-
expect(line_item.variant_id).to eq(variant_id)
|
|
129
|
-
expect(line_item.quantity).to eq(5)
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
it 'handles exceptions when sku is not found' do
|
|
133
|
-
params = { line_items_attributes: [{ sku: 'XXX', quantity: 5 }] }
|
|
134
|
-
expect { Importer::Order.import(user, params) }.to raise_error /XXX/
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
it 'can build an order from API shipping address' do
|
|
138
|
-
params = {
|
|
139
|
-
ship_address_attributes: ship_address,
|
|
140
|
-
line_items_attributes: line_items
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
order = Importer::Order.import(user, params)
|
|
144
|
-
expect(order.ship_address.address1).to eq '123 Testable Way'
|
|
145
|
-
end
|
|
146
|
-
|
|
147
|
-
it 'can build an order from API with country attributes' do
|
|
148
|
-
ship_address.delete(:country_id)
|
|
149
|
-
ship_address[:country] = { 'iso' => 'US' }
|
|
150
|
-
params = {
|
|
151
|
-
ship_address_attributes: ship_address,
|
|
152
|
-
line_items_attributes: line_items
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
order = Importer::Order.import(user, params)
|
|
156
|
-
expect(order.ship_address.country.iso).to eq 'US'
|
|
157
|
-
end
|
|
158
|
-
|
|
159
|
-
it 'handles country lookup exceptions' do
|
|
160
|
-
ship_address.delete(:country_id)
|
|
161
|
-
ship_address[:country] = { 'iso' => 'XXX' }
|
|
162
|
-
params = {
|
|
163
|
-
ship_address_attributes: ship_address,
|
|
164
|
-
line_items_attributes: line_items
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
expect { Importer::Order.import(user, params) }.to raise_error /XXX/
|
|
168
|
-
end
|
|
169
|
-
|
|
170
|
-
it 'can build an order from API with state attributes' do
|
|
171
|
-
ship_address.delete(:state_id)
|
|
172
|
-
ship_address[:state] = { 'name' => state.name }
|
|
173
|
-
params = {
|
|
174
|
-
ship_address_attributes: ship_address,
|
|
175
|
-
line_items_attributes: line_items
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
order = Importer::Order.import(user, params)
|
|
179
|
-
expect(order.ship_address.state.name).to eq state.name
|
|
180
|
-
end
|
|
181
|
-
|
|
182
|
-
context "with a different currency" do
|
|
183
|
-
before { variant.price_in("GBP").update_attribute(:price, 18.99) }
|
|
184
|
-
|
|
185
|
-
it "sets the order currency" do
|
|
186
|
-
params = { currency: "GBP" }
|
|
187
|
-
order = Importer::Order.import(user, params)
|
|
188
|
-
expect(order.currency).to eq "GBP"
|
|
189
|
-
end
|
|
190
|
-
|
|
191
|
-
it "can handle it when a line order price is specified" do
|
|
192
|
-
params = {
|
|
193
|
-
currency: "GBP",
|
|
194
|
-
line_items_attributes: line_items
|
|
195
|
-
}
|
|
196
|
-
line_items.first.merge! currency: "GBP", price: 1.99
|
|
197
|
-
order = Importer::Order.import(user, params)
|
|
198
|
-
expect(order.currency).to eq "GBP"
|
|
199
|
-
expect(order.line_items.first.price).to eq 1.99
|
|
200
|
-
expect(order.line_items.first.currency).to eq "GBP"
|
|
201
|
-
end
|
|
202
|
-
end
|
|
203
|
-
|
|
204
|
-
context "state passed is not associated with country" do
|
|
205
|
-
let(:params) do
|
|
206
|
-
{
|
|
207
|
-
ship_address_attributes: ship_address,
|
|
208
|
-
line_items_attributes: line_items
|
|
209
|
-
}
|
|
210
|
-
end
|
|
211
|
-
|
|
212
|
-
let(:other_state) { create(:state, name: "Uhuhuh", country: create(:country)) }
|
|
213
|
-
|
|
214
|
-
before do
|
|
215
|
-
ship_address.delete(:state_id)
|
|
216
|
-
ship_address[:state] = { 'name' => other_state.name }
|
|
217
|
-
end
|
|
218
|
-
|
|
219
|
-
it 'sets states name instead of state id' do
|
|
220
|
-
order = Importer::Order.import(user, params)
|
|
221
|
-
expect(order.ship_address.state_name).to eq other_state.name
|
|
222
|
-
end
|
|
223
|
-
end
|
|
224
|
-
|
|
225
|
-
it 'sets state name if state record not found' do
|
|
226
|
-
ship_address.delete(:state_id)
|
|
227
|
-
ship_address[:state] = { 'name' => 'XXX' }
|
|
228
|
-
params = {
|
|
229
|
-
ship_address_attributes: ship_address,
|
|
230
|
-
line_items_attributes: line_items
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
order = Importer::Order.import(user, params)
|
|
234
|
-
expect(order.ship_address.state_name).to eq 'XXX'
|
|
235
|
-
end
|
|
236
|
-
|
|
237
|
-
context 'variant not deleted' do
|
|
238
|
-
it 'ensures variant id from api' do
|
|
239
|
-
hash = { sku: variant.sku }
|
|
240
|
-
Importer::Order.ensure_variant_id_from_params(hash)
|
|
241
|
-
expect(hash[:variant_id]).to eq variant.id
|
|
242
|
-
end
|
|
243
|
-
end
|
|
244
|
-
|
|
245
|
-
context 'variant was deleted' do
|
|
246
|
-
it 'raise error as variant shouldnt be found' do
|
|
247
|
-
variant.product.destroy
|
|
248
|
-
hash = { sku: variant.sku }
|
|
249
|
-
expect { Importer::Order.ensure_variant_id_from_params(hash) }.to raise_error("Ensure order import variant: Variant w/SKU #{ hash[:sku] } not found.")
|
|
250
|
-
end
|
|
251
|
-
end
|
|
252
|
-
|
|
253
|
-
it 'ensures_country_id for country fields' do
|
|
254
|
-
[:name, :iso, :iso_name, :iso3].each do |field|
|
|
255
|
-
address = { country: { field => country.send(field) } }
|
|
256
|
-
Importer::Order.ensure_country_id_from_params(address)
|
|
257
|
-
expect(address[:country_id]).to eq country.id
|
|
258
|
-
end
|
|
259
|
-
end
|
|
260
|
-
|
|
261
|
-
it "raises with proper message when cant find country" do
|
|
262
|
-
address = { country: { "name" => "NoNoCountry" } }
|
|
263
|
-
expect { Importer::Order.ensure_country_id_from_params(address) }.to raise_error /NoNoCountry/
|
|
264
|
-
end
|
|
265
|
-
|
|
266
|
-
it 'ensures_state_id for state fields' do
|
|
267
|
-
[:name, :abbr].each do |field|
|
|
268
|
-
address = { country_id: country.id, state: { field => state.send(field) } }
|
|
269
|
-
Importer::Order.ensure_state_id_from_params(address)
|
|
270
|
-
expect(address[:state_id]).to eq state.id
|
|
271
|
-
end
|
|
272
|
-
end
|
|
273
|
-
|
|
274
|
-
context "shipments" do
|
|
275
|
-
let(:params) do
|
|
276
|
-
{
|
|
277
|
-
line_items_attributes: line_items,
|
|
278
|
-
shipments_attributes: [
|
|
279
|
-
{
|
|
280
|
-
tracking: '123456789',
|
|
281
|
-
cost: '14.99',
|
|
282
|
-
shipping_method: shipping_method.name,
|
|
283
|
-
stock_location: stock_location.name,
|
|
284
|
-
inventory_units: 3.times.map { { sku: sku } }
|
|
285
|
-
},
|
|
286
|
-
{
|
|
287
|
-
tracking: '123456789',
|
|
288
|
-
cost: '14.99',
|
|
289
|
-
shipping_method: shipping_method.name,
|
|
290
|
-
stock_location: stock_location.name,
|
|
291
|
-
inventory_units: 2.times.map { { sku: sku } }
|
|
292
|
-
}
|
|
293
|
-
]
|
|
294
|
-
}
|
|
295
|
-
end
|
|
296
|
-
|
|
297
|
-
it 'ensures variant exists and is not deleted' do
|
|
298
|
-
expect(Importer::Order).to receive(:ensure_variant_id_from_params).exactly(6).times { line_items.first }
|
|
299
|
-
Importer::Order.import(user, params)
|
|
300
|
-
end
|
|
301
|
-
|
|
302
|
-
it 'builds them properly' do
|
|
303
|
-
order = Importer::Order.import(user, params)
|
|
304
|
-
shipment = order.shipments.first
|
|
305
|
-
|
|
306
|
-
expect(shipment.cost.to_f).to eq 14.99
|
|
307
|
-
expect(shipment.inventory_units.first.variant_id).to eq product.master.id
|
|
308
|
-
expect(shipment.tracking).to eq '123456789'
|
|
309
|
-
expect(shipment.shipping_rates.first.cost).to eq 14.99
|
|
310
|
-
expect(shipment.selected_shipping_rate).to eq(shipment.shipping_rates.first)
|
|
311
|
-
expect(shipment.stock_location).to eq stock_location
|
|
312
|
-
expect(order.shipment_total.to_f).to eq 29.98
|
|
313
|
-
end
|
|
314
|
-
|
|
315
|
-
it "allocates inventory units to the correct shipments" do
|
|
316
|
-
order = Importer::Order.import(user, params)
|
|
317
|
-
|
|
318
|
-
expect(order.inventory_units.count).to eq 5
|
|
319
|
-
expect(order.shipments.first.inventory_units.count).to eq 3
|
|
320
|
-
expect(order.shipments.last.inventory_units.count).to eq 2
|
|
321
|
-
end
|
|
322
|
-
|
|
323
|
-
it "accepts admin name for stock location" do
|
|
324
|
-
params[:shipments_attributes][0][:stock_location] = stock_location.admin_name
|
|
325
|
-
order = Importer::Order.import(user, params)
|
|
326
|
-
shipment = order.shipments.first
|
|
327
|
-
|
|
328
|
-
expect(shipment.stock_location).to eq stock_location
|
|
329
|
-
end
|
|
330
|
-
|
|
331
|
-
it "raises if cant find stock location" do
|
|
332
|
-
params[:shipments_attributes][0][:stock_location] = "doesnt exist"
|
|
333
|
-
expect { Importer::Order.import(user, params) }.to raise_error(StandardError)
|
|
334
|
-
end
|
|
335
|
-
|
|
336
|
-
context 'when a shipping adjustment is present' do
|
|
337
|
-
it 'creates the shipping adjustment' do
|
|
338
|
-
adjustment_attributes = [{ label: 'Shipping Discount', amount: -5.00 }]
|
|
339
|
-
params[:shipments_attributes][0][:adjustments_attributes] = adjustment_attributes
|
|
340
|
-
order = Importer::Order.import(user, params)
|
|
341
|
-
shipment = order.shipments.first
|
|
342
|
-
|
|
343
|
-
expect(shipment.adjustments.first.label).to eq('Shipping Discount')
|
|
344
|
-
expect(shipment.adjustments.first.amount).to eq(-5.00)
|
|
345
|
-
end
|
|
346
|
-
end
|
|
347
|
-
|
|
348
|
-
context 'when completed_at and shipped_at present' do
|
|
349
|
-
let(:params) do
|
|
350
|
-
{
|
|
351
|
-
completed_at: 2.days.ago,
|
|
352
|
-
line_items_attributes: line_items,
|
|
353
|
-
shipments_attributes: [
|
|
354
|
-
{
|
|
355
|
-
tracking: '123456789',
|
|
356
|
-
cost: '4.99',
|
|
357
|
-
shipped_at: 1.day.ago,
|
|
358
|
-
shipping_method: shipping_method.name,
|
|
359
|
-
stock_location: stock_location.name,
|
|
360
|
-
inventory_units: [{ sku: sku }]
|
|
361
|
-
}
|
|
362
|
-
]
|
|
363
|
-
}
|
|
364
|
-
end
|
|
365
|
-
|
|
366
|
-
it 'builds them properly' do
|
|
367
|
-
order = Importer::Order.import(user, params)
|
|
368
|
-
shipment = order.shipments.first
|
|
369
|
-
|
|
370
|
-
expect(shipment.cost.to_f).to eq 4.99
|
|
371
|
-
expect(shipment.inventory_units.first.variant_id).to eq product.master.id
|
|
372
|
-
expect(shipment.tracking).to eq '123456789'
|
|
373
|
-
expect(shipment.shipped_at).to be_present
|
|
374
|
-
expect(shipment.shipping_rates.first.cost).to eq 4.99
|
|
375
|
-
expect(shipment.selected_shipping_rate).to eq(shipment.shipping_rates.first)
|
|
376
|
-
expect(shipment.stock_location).to eq stock_location
|
|
377
|
-
expect(shipment.state).to eq('shipped')
|
|
378
|
-
expect(shipment.inventory_units.all?(&:shipped?)).to be true
|
|
379
|
-
expect(order.shipment_state).to eq('shipped')
|
|
380
|
-
expect(order.shipment_total.to_f).to eq 4.99
|
|
381
|
-
end
|
|
382
|
-
end
|
|
383
|
-
end
|
|
384
|
-
|
|
385
|
-
it 'handles shipment building exceptions' do
|
|
386
|
-
params = {
|
|
387
|
-
shipments_attributes: [
|
|
388
|
-
{
|
|
389
|
-
tracking: '123456789',
|
|
390
|
-
cost: '4.99',
|
|
391
|
-
shipping_method: 'XXX',
|
|
392
|
-
inventory_units: [{ sku: sku }]
|
|
393
|
-
}
|
|
394
|
-
]
|
|
395
|
-
}
|
|
396
|
-
expect { Importer::Order.import(user, params) }.to raise_error /XXX/
|
|
397
|
-
end
|
|
398
|
-
|
|
399
|
-
it 'adds adjustments' do
|
|
400
|
-
params = {
|
|
401
|
-
adjustments_attributes: [
|
|
402
|
-
{
|
|
403
|
-
label: 'Shipping Discount',
|
|
404
|
-
amount: -4.99
|
|
405
|
-
},
|
|
406
|
-
{
|
|
407
|
-
label: 'Promotion Discount',
|
|
408
|
-
amount: -3.00
|
|
409
|
-
}
|
|
410
|
-
]
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
order = Importer::Order.import(user, params)
|
|
414
|
-
expect(order.adjustments.all?(&:closed?)).to be true
|
|
415
|
-
expect(order.adjustments.first.label).to eq 'Shipping Discount'
|
|
416
|
-
expect(order.adjustments.first.amount).to eq -4.99
|
|
417
|
-
end
|
|
418
|
-
|
|
419
|
-
it 'adds line item adjustments from promotion' do
|
|
420
|
-
line_items.first[:adjustments_attributes] = [
|
|
421
|
-
{
|
|
422
|
-
label: 'Line Item Discount',
|
|
423
|
-
amount: -4.99,
|
|
424
|
-
promotion: true
|
|
425
|
-
}
|
|
426
|
-
]
|
|
427
|
-
params = {
|
|
428
|
-
line_items_attributes: line_items,
|
|
429
|
-
adjustments_attributes: [
|
|
430
|
-
{ label: 'Order Discount', amount: -5.99 }
|
|
431
|
-
]
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
order = Importer::Order.import(user, params)
|
|
435
|
-
line_item_adjustment = order.line_item_adjustments.first
|
|
436
|
-
expect(line_item_adjustment.closed?).to be true
|
|
437
|
-
expect(line_item_adjustment.label).to eq 'Line Item Discount'
|
|
438
|
-
expect(line_item_adjustment.amount).to eq -4.99
|
|
439
|
-
expect(order.line_items.first.adjustment_total).to eq -4.99
|
|
440
|
-
end
|
|
441
|
-
|
|
442
|
-
it 'adds line item adjustments from taxation' do
|
|
443
|
-
line_items.first[:adjustments_attributes] = [
|
|
444
|
-
{ label: 'Line Item Tax', amount: -4.99, tax: true }
|
|
445
|
-
]
|
|
446
|
-
params = {
|
|
447
|
-
line_items_attributes: line_items,
|
|
448
|
-
adjustments_attributes: [
|
|
449
|
-
{ label: 'Order Discount', amount: -5.99 }
|
|
450
|
-
]
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
order = Importer::Order.import(user, params)
|
|
454
|
-
|
|
455
|
-
line_item_adjustment = order.line_item_adjustments.first
|
|
456
|
-
expect(line_item_adjustment.closed?).to be true
|
|
457
|
-
expect(line_item_adjustment.label).to eq 'Line Item Tax'
|
|
458
|
-
expect(line_item_adjustment.amount).to eq -4.99
|
|
459
|
-
expect(order.line_items.first.adjustment_total).to eq -4.99
|
|
460
|
-
end
|
|
461
|
-
|
|
462
|
-
it "calculates final order total correctly" do
|
|
463
|
-
params = {
|
|
464
|
-
adjustments_attributes: [
|
|
465
|
-
{ label: 'Promotion Discount', amount: -3.00 }
|
|
466
|
-
],
|
|
467
|
-
line_items_attributes: [
|
|
468
|
-
{
|
|
469
|
-
variant_id: variant.id,
|
|
470
|
-
quantity: 5
|
|
471
|
-
}
|
|
472
|
-
]
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
order = Importer::Order.import(user, params)
|
|
476
|
-
expect(order.item_total).to eq(166.1)
|
|
477
|
-
expect(order.total).to eq(163.1) # = item_total (166.1) - adjustment_total (3.00)
|
|
478
|
-
end
|
|
479
|
-
|
|
480
|
-
it 'handles adjustment building exceptions' do
|
|
481
|
-
params = {
|
|
482
|
-
adjustments_attributes: [
|
|
483
|
-
{
|
|
484
|
-
amount: 'XXX'
|
|
485
|
-
},
|
|
486
|
-
{
|
|
487
|
-
label: 'Promotion Discount',
|
|
488
|
-
amount: '-3.00'
|
|
489
|
-
}
|
|
490
|
-
]
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
expect { Importer::Order.import(user, params) }.to raise_error /XXX/
|
|
494
|
-
end
|
|
495
|
-
|
|
496
|
-
it 'builds a payment using state' do
|
|
497
|
-
params = {
|
|
498
|
-
payments_attributes: [
|
|
499
|
-
{
|
|
500
|
-
amount: '4.99',
|
|
501
|
-
payment_method: payment_method.name,
|
|
502
|
-
state: 'completed'
|
|
503
|
-
}
|
|
504
|
-
]
|
|
505
|
-
}
|
|
506
|
-
order = Importer::Order.import(user, params)
|
|
507
|
-
expect(order.payments.first.amount).to eq 4.99
|
|
508
|
-
end
|
|
509
|
-
|
|
510
|
-
it 'builds a payment using status as fallback' do
|
|
511
|
-
params = {
|
|
512
|
-
payments_attributes: [
|
|
513
|
-
{
|
|
514
|
-
amount: '4.99',
|
|
515
|
-
payment_method: payment_method.name,
|
|
516
|
-
status: 'completed'
|
|
517
|
-
}
|
|
518
|
-
]
|
|
519
|
-
}
|
|
520
|
-
order = Importer::Order.import(user, params)
|
|
521
|
-
expect(order.payments.first.amount).to eq 4.99
|
|
522
|
-
end
|
|
523
|
-
|
|
524
|
-
it 'handles payment building exceptions' do
|
|
525
|
-
params = {
|
|
526
|
-
payments_attributes: [
|
|
527
|
-
{
|
|
528
|
-
amount: '4.99',
|
|
529
|
-
payment_method: 'XXX'
|
|
530
|
-
}
|
|
531
|
-
]
|
|
532
|
-
}
|
|
533
|
-
expect { Importer::Order.import(user, params) }.to raise_error /XXX/
|
|
534
|
-
end
|
|
535
|
-
|
|
536
|
-
it 'build a source payment using years and month' do
|
|
537
|
-
params = {
|
|
538
|
-
payments_attributes: [
|
|
539
|
-
{
|
|
540
|
-
amount: '4.99',
|
|
541
|
-
payment_method: payment_method.name,
|
|
542
|
-
status: 'completed',
|
|
543
|
-
source: {
|
|
544
|
-
name: 'Fox',
|
|
545
|
-
last_digits: "7424",
|
|
546
|
-
cc_type: "visa",
|
|
547
|
-
year: '2022',
|
|
548
|
-
month: "5"
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
]
|
|
552
|
-
}
|
|
553
|
-
|
|
554
|
-
order = Importer::Order.import(user, params)
|
|
555
|
-
expect(order.payments.first.source.last_digits).to eq '7424'
|
|
556
|
-
end
|
|
557
|
-
|
|
558
|
-
it 'handles source building exceptions when do not have years and month' do
|
|
559
|
-
params = {
|
|
560
|
-
payments_attributes: [
|
|
561
|
-
{
|
|
562
|
-
amount: '4.99',
|
|
563
|
-
payment_method: payment_method.name,
|
|
564
|
-
status: 'completed',
|
|
565
|
-
source: {
|
|
566
|
-
name: 'Fox',
|
|
567
|
-
last_digits: "7424",
|
|
568
|
-
cc_type: "visa"
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
]
|
|
572
|
-
}
|
|
573
|
-
|
|
574
|
-
expect { Importer::Order.import(user, params) }.
|
|
575
|
-
to raise_error /Validation failed: Credit card Month is not a number, Credit card Year is not a number/
|
|
576
|
-
end
|
|
577
|
-
|
|
578
|
-
it 'builds a payment with an optional created_at' do
|
|
579
|
-
created_at = 2.days.ago
|
|
580
|
-
params = {
|
|
581
|
-
payments_attributes: [
|
|
582
|
-
{
|
|
583
|
-
amount: '4.99',
|
|
584
|
-
payment_method: payment_method.name,
|
|
585
|
-
state: 'completed',
|
|
586
|
-
created_at: created_at
|
|
587
|
-
}
|
|
588
|
-
]
|
|
589
|
-
}
|
|
590
|
-
order = Importer::Order.import(user, params)
|
|
591
|
-
expect(order.payments.first.created_at).to be_within(1).of created_at
|
|
592
|
-
end
|
|
593
|
-
|
|
594
|
-
context "raises error" do
|
|
595
|
-
it "clears out order from db" do
|
|
596
|
-
params = { payments_attributes: [{ payment_method: "XXX" }] }
|
|
597
|
-
count = Order.count
|
|
598
|
-
|
|
599
|
-
expect { Importer::Order.import(user, params) }.to raise_error(StandardError)
|
|
600
|
-
expect(Order.count).to eq count
|
|
601
|
-
end
|
|
602
|
-
end
|
|
603
|
-
end
|
|
604
|
-
end
|
|
605
|
-
end
|