Split out payment and shipping methods from admin enterprises controller as services

This commit is contained in:
Rob Harrington
2015-01-22 12:19:41 +11:00
parent 4829e59663
commit b429be707c
9 changed files with 144 additions and 98 deletions

View File

@@ -0,0 +1,45 @@
describe "EnterprisePaymentMethods service", ->
Enterprise = null
PaymentMethods = null
EnterprisePaymentMethods = null
beforeEach ->
Enterprise =
enterprise:
payment_method_ids: [ 1, 3 ]
PaymentMethods =
paymentMethods: [ { id: 1 }, { id: 2 }, { id: 3 }, { id: 4 } ]
module 'admin.enterprises'
module ($provide) ->
$provide.value 'PaymentMethods', PaymentMethods
$provide.value 'Enterprise', Enterprise
null
inject (_EnterprisePaymentMethods_) ->
EnterprisePaymentMethods = _EnterprisePaymentMethods_
describe "selecting payment methods", ->
it "sets the selected property of each payment method", ->
expect(PaymentMethods.paymentMethods[0].selected).toBe true
expect(PaymentMethods.paymentMethods[1].selected).toBe false
expect(PaymentMethods.paymentMethods[2].selected).toBe true
expect(PaymentMethods.paymentMethods[3].selected).toBe false
describe "determining payment method colour", ->
it "returns 'blue' when at least one payment method is selected", ->
spyOn(EnterprisePaymentMethods, "selectedCount").andReturn 1
expect(EnterprisePaymentMethods.displayColor()).toBe "blue"
it "returns 'red' when no payment methods are selected", ->
spyOn(EnterprisePaymentMethods, "selectedCount").andReturn 0
expect(EnterprisePaymentMethods.displayColor()).toBe "red"
it "returns 'red' when no payment methods exist", ->
EnterprisePaymentMethods.paymentMethods = []
spyOn(EnterprisePaymentMethods, "selectedCount").andReturn 1
expect(EnterprisePaymentMethods.displayColor()).toBe "red"
describe "counting selected payment methods", ->
it "counts only payment methods with selected: true", ->
expect(EnterprisePaymentMethods.selectedCount()).toBe 2

View File

@@ -0,0 +1,45 @@
describe "EnterpriseShippingMethods service", ->
Enterprise = null
ShippingMethods = null
EnterpriseShippingMethods = null
beforeEach ->
Enterprise =
enterprise:
shipping_method_ids: [ 1, 3 ]
ShippingMethods =
shippingMethods: [ { id: 1 }, { id: 2 }, { id: 3 }, { id: 4 } ]
module 'admin.enterprises'
module ($provide) ->
$provide.value 'ShippingMethods', ShippingMethods
$provide.value 'Enterprise', Enterprise
null
inject (_EnterpriseShippingMethods_) ->
EnterpriseShippingMethods = _EnterpriseShippingMethods_
describe "selecting shipping methods", ->
it "sets the selected property of each shipping method", ->
expect(ShippingMethods.shippingMethods[0].selected).toBe true
expect(ShippingMethods.shippingMethods[1].selected).toBe false
expect(ShippingMethods.shippingMethods[2].selected).toBe true
expect(ShippingMethods.shippingMethods[3].selected).toBe false
describe "determining shipping method colour", ->
it "returns 'blue' when at least one shipping method is selected", ->
spyOn(EnterpriseShippingMethods, "selectedCount").andReturn 1
expect(EnterpriseShippingMethods.displayColor()).toBe "blue"
it "returns 'red' when no shipping methods are selected", ->
spyOn(EnterpriseShippingMethods, "selectedCount").andReturn 0
expect(EnterpriseShippingMethods.displayColor()).toBe "red"
it "returns 'red' when no shipping methods exist", ->
EnterpriseShippingMethods.shippingMethods = []
spyOn(EnterpriseShippingMethods, "selectedCount").andReturn 1
expect(EnterpriseShippingMethods.displayColor()).toBe "red"
describe "counting selected shipping methods", ->
it "counts only shipping methods with selected: true", ->
expect(EnterpriseShippingMethods.selectedCount()).toBe 2

View File

@@ -3,10 +3,12 @@ describe "Enterprise service", ->
enterprise = { name: "test ent name" }
beforeEach ->
module 'admin.enterprises'
angular.module('admin.enterprises').value('enterprise', enterprise)
module ($provide) ->
$provide.value 'enterprise', enterprise
null
inject ($injector) ->
Enterprise = $injector.get("Enterprise")
Enterprise = $injector.get("Enterprise")
it "stores enterprise value as Enterprise.enterprise", ->
expect(Enterprise.enterprise).toBe enterprise
expect(Enterprise.enterprise).toBe enterprise