Fix checkout total display

This commit is contained in:
Rohan Mitchell
2014-08-07 14:51:48 +10:00
parent d1c9980f3f
commit 769e8410cc
4 changed files with 41 additions and 7 deletions

View File

@@ -4,5 +4,6 @@ Darkswarm.factory "ShippingMethods", (shippingMethods)->
shipping_methods_by_id: {}
constructor: ->
for method in @shipping_methods
method.price = parseFloat(method.price)
@shipping_methods_by_id[method.id] = method

View File

@@ -10,27 +10,29 @@ feature "As a consumer I want to check out my cart", js: true do
let(:distributor) { create(:distributor_enterprise) }
let(:supplier) { create(:supplier_enterprise) }
let!(:order_cycle) { create(:simple_order_cycle, distributors: [distributor], coordinator: create(:distributor_enterprise)) }
let!(:order_cycle) { create(:simple_order_cycle, suppliers: [supplier], distributors: [distributor], coordinator: create(:distributor_enterprise), variants: [product.master]) }
let(:enterprise_fee) { create(:enterprise_fee, amount: 1.23) }
let(:product) { create(:simple_product, supplier: supplier) }
let(:order) { create(:order, order_cycle: order_cycle, distributor: distributor) }
before do
add_enterprise_fee enterprise_fee
set_order order
add_product_to_cart
end
it "shows the current distributor oncheckout" do
it "shows the current distributor on checkout" do
visit checkout_path
page.should have_content distributor.name
end
describe "with shipping methods" do
let(:sm1) { create(:shipping_method, require_ship_address: true, name: "Frogs", description: "yellow") }
let(:sm2) { create(:shipping_method, require_ship_address: false, name: "Donkeys", description: "blue") }
let(:sm2) { create(:shipping_method, require_ship_address: false, name: "Donkeys", description: "blue", calculator: Spree::Calculator::FlatRate.new(preferred_amount: 4.56)) }
before do
distributor.shipping_methods << sm1
distributor.shipping_methods << sm2
distributor.shipping_methods << sm1
distributor.shipping_methods << sm2
end
context "on the checkout page" do
@@ -39,6 +41,15 @@ feature "As a consumer I want to check out my cart", js: true do
checkout_as_guest
end
it "shows a breakdown of the order price" do
toggle_shipping
choose sm2.name
page.should have_selector 'orderdetails .cart-total', text: "$11.23"
page.should have_selector 'orderdetails .shipping', text: "$4.56"
page.should have_selector 'orderdetails .total', text: "$15.79"
end
it "shows all shipping methods, but doesn't show ship address when not needed" do
toggle_shipping
page.should have_content "Frogs"
@@ -157,7 +168,7 @@ feature "As a consumer I want to check out my cart", js: true do
# Order should have a payment with the correct amount
o = Spree::Order.complete.first
o.payments.first.amount.should == 10
o.payments.first.amount.should == 11.23
end
it "shows the payment processing failed message when submitted with an invalid credit card" do

View File

@@ -0,0 +1,14 @@
describe "Shipping method service", ->
ShippingMethods = null
shippingMethods = [
{id: 1, price: "1.2"}
]
beforeEach ->
module 'Darkswarm'
angular.module('Darkswarm').value('shippingMethods', shippingMethods)
inject ($injector)->
ShippingMethods = $injector.get("ShippingMethods")
it "converts price to float", ->
expect(ShippingMethods.shipping_methods[0].price).toEqual 1.2

View File

@@ -7,13 +7,21 @@ module ShopWorkflow
have_selector ".price", text: price
end
def add_enterprise_fee(enterprise_fee)
order_cycle.exchanges.outgoing.first.enterprise_fees << enterprise_fee
end
def set_order(order)
ApplicationController.any_instance.stub(:session).and_return({order_id: order.id, access_token: order.token})
end
def add_product_to_cart
create(:line_item, variant: product.master, order: order)
order.reload.save! # Recalculate totals
order.reload
# Recalculate totals
order.save!
order.update_distribution_charge!
end
def toggle_accordion(name)