Starting on JSON checkout, moving Order properties to Order.order

This commit is contained in:
Will Marshall
2014-04-09 14:33:45 +10:00
parent 09d22f74ec
commit b5550c048a
7 changed files with 82 additions and 27 deletions

View File

@@ -5,10 +5,20 @@ describe "CheckoutCtrl", ->
beforeEach ->
module("Darkswarm")
order = {}
order = {
submit: ->
}
inject ($controller, $rootScope) ->
scope = $rootScope.$new()
ctrl = $controller 'CheckoutCtrl', {$scope: scope, Order: order}
it "defaults the user accordion to visible", ->
expect(scope.user).toEqual true
expect(scope.accordion.user).toEqual true
it "delegates to the service on submit", ->
event = {
preventDefault: ->
}
spyOn(order, "submit")
scope.purchase(event)
expect(order.submit).toHaveBeenCalled()

View File

@@ -1,6 +1,7 @@
describe 'Order service', ->
Order = null
orderData = null
$httpBackend = null
beforeEach ->
orderData = {
@@ -20,28 +21,34 @@ describe 'Order service', ->
}
angular.module('Darkswarm').value('order', orderData)
module 'Darkswarm'
inject ($injector)->
inject ($injector, _$httpBackend_)->
$httpBackend = _$httpBackend_
Order = $injector.get("Order")
it "defaults the shipping method to the first", ->
expect(Order.shipping_method_id).toEqual 7
expect(Order.order.shipping_method_id).toEqual 7
expect(Order.shippingMethod()).toEqual { require_ship_address : true, price : 0 }
it "defaults to 'same as billing' for address", ->
expect(Order.ship_address_same_as_billing).toEqual true
expect(Order.order.ship_address_same_as_billing).toEqual true
it 'Tracks whether a ship address is required', ->
expect(Order.requireShipAddress()).toEqual true
Order.shipping_method_id = 25
Order.order.shipping_method_id = 25
expect(Order.requireShipAddress()).toEqual false
it 'Gets the current shipping price', ->
expect(Order.shippingPrice()).toEqual 0.0
Order.shipping_method_id = 25
Order.order.shipping_method_id = 25
expect(Order.shippingPrice()).toEqual 13
it 'Gets the current payment method', ->
expect(Order.paymentMethod()).toEqual null
Order.payment_method_id = 99
Order.order.payment_method_id = 99
expect(Order.paymentMethod()).toEqual {test: "foo"}
it "Posts the Order to the server", ->
$httpBackend.expectPUT("/shop/checkout", {order: Order.preprocess()}).respond 200
Order.submit()
$httpBackend.flush()