Created
April 8, 2014 01:15
-
-
Save willrjmarshall/10080013 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Darkswarm.factory 'Order', ($resource, Product, order)-> | |
new class Order | |
constructor: -> | |
@[name] = method for name, method of order # Clone all data from the order JSON object | |
# Here we default to the first shipping method if none is selected | |
@shipping_method_id ||= parseInt(Object.keys(@shipping_methods)[0]) | |
@ship_address_same_as_billing ?= true | |
shippingMethod: -> | |
@shipping_methods[@shipping_method_id] | |
requireShipAddress: -> | |
@shippingMethod().require_ship_address | |
shippingPrice: -> | |
@shippingMethod().price | |
paymentMethod: -> | |
@payment_methods[@payment_method_id] | |
cartTotal: -> | |
@shippingPrice() + @display_total | |
describe 'Order service', -> | |
Order = null | |
orderData = null | |
beforeEach -> | |
orderData = { | |
id: 3102 | |
payment_method_id: null | |
shipping_methods: | |
7: | |
require_ship_address: true | |
price: 0.0 | |
25: | |
require_ship_address: false | |
price: 13 | |
payment_methods: | |
99: | |
test: "foo" | |
} | |
angular.module('Darkswarm').value('order', orderData) | |
module 'Darkswarm' | |
inject ($injector)-> | |
Order = $injector.get("Order") | |
it "defaults the shipping method to the first", -> | |
expect(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 | |
it 'Tracks whether a ship address is required', -> | |
expect(Order.requireShipAddress()).toEqual true | |
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 | |
expect(Order.shippingPrice()).toEqual 13 | |
it 'Gets the current payment method', -> | |
expect(Order.paymentMethod()).toEqual null | |
Order.payment_method_id = 99 | |
expect(Order.paymentMethod()).toEqual {test: "foo"} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment