mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-28 21:07:16 +00:00
Split out payment and shipping methods from admin enterprises controller as services
This commit is contained in:
@@ -9,18 +9,16 @@ describe "enterpriseCtrl", ->
|
||||
module('admin.enterprises')
|
||||
Enterprise =
|
||||
enterprise:
|
||||
payment_method_ids: [ 1, 3 ]
|
||||
shipping_method_ids: [ 2, 4 ]
|
||||
is_primary_producer: true
|
||||
sells: "none"
|
||||
PaymentMethods =
|
||||
paymentMethods: [ { id: 1 }, { id: 2 }, { id: 3 }, { id: 4 } ]
|
||||
paymentMethods: "payment methods"
|
||||
ShippingMethods =
|
||||
shippingMethods: [ { id: 1 }, { id: 2 }, { id: 3 }, { id: 4 } ]
|
||||
shippingMethods: "shipping methods"
|
||||
|
||||
inject ($rootScope, $controller) ->
|
||||
scope = $rootScope
|
||||
ctrl = $controller 'enterpriseCtrl', {$scope: scope, Enterprise: Enterprise, PaymentMethods: PaymentMethods, ShippingMethods: ShippingMethods}
|
||||
ctrl = $controller 'enterpriseCtrl', {$scope: scope, Enterprise: Enterprise, EnterprisePaymentMethods: PaymentMethods, EnterpriseShippingMethods: ShippingMethods}
|
||||
|
||||
describe "initialisation", ->
|
||||
it "stores enterprise", ->
|
||||
@@ -31,57 +29,3 @@ describe "enterpriseCtrl", ->
|
||||
|
||||
it "stores shipping methods", ->
|
||||
expect(scope.ShippingMethods).toBe ShippingMethods.shippingMethods
|
||||
|
||||
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
|
||||
|
||||
it "sets the selected property of each shipping method", ->
|
||||
expect(ShippingMethods.shippingMethods[0].selected).toBe false
|
||||
expect(ShippingMethods.shippingMethods[1].selected).toBe true
|
||||
expect(ShippingMethods.shippingMethods[2].selected).toBe false
|
||||
expect(ShippingMethods.shippingMethods[3].selected).toBe true
|
||||
|
||||
describe "determining payment method colour", ->
|
||||
it "returns 'blue' when at least one payment method is selected", ->
|
||||
scope.PaymentMethods = [ { id: 1 } ]
|
||||
spyOn(scope, "selectedPaymentMethodsCount").andReturn 1
|
||||
expect(scope.paymentMethodsColor()).toBe "blue"
|
||||
|
||||
it "returns 'red' when no payment methods are selected", ->
|
||||
scope.PaymentMethods = [ { id: 1 } ]
|
||||
spyOn(scope, "selectedPaymentMethodsCount").andReturn 0
|
||||
expect(scope.paymentMethodsColor()).toBe "red"
|
||||
|
||||
it "returns 'red' when no payment methods exist", ->
|
||||
scope.PaymentMethods = [ ]
|
||||
spyOn(scope, "selectedPaymentMethodsCount").andReturn 1
|
||||
expect(scope.paymentMethodsColor()).toBe "red"
|
||||
|
||||
describe "counting selected payment methods", ->
|
||||
it "counts only payment methods with selected: true", ->
|
||||
scopePaymentMethods = [ { selected: true }, { selected: false }, { selected: false }, { selected: true } ]
|
||||
expect(scope.selectedPaymentMethodsCount()).toBe 2
|
||||
|
||||
describe "determining shipping method colour", ->
|
||||
it "returns 'blue' when at least one shipping method is selected", ->
|
||||
scope.ShippingMethods = [ { id: 1 } ]
|
||||
spyOn(scope, "selectedShippingMethodsCount").andReturn 1
|
||||
expect(scope.shippingMethodsColor()).toBe "blue"
|
||||
|
||||
it "returns 'red' when no shipping methods are selected", ->
|
||||
scope.ShippingMethods = [ { id: 1 } ]
|
||||
spyOn(scope, "selectedShippingMethodsCount").andReturn 0
|
||||
expect(scope.shippingMethodsColor()).toBe "red"
|
||||
|
||||
it "returns 'red' when no shipping method exist", ->
|
||||
scope.ShippingMethods = [ ]
|
||||
spyOn(scope, "selectedShippingMethodsCount").andReturn 1
|
||||
expect(scope.shippingMethodsColor()).toBe "red"
|
||||
|
||||
describe "counting selected shipping methods", ->
|
||||
it "counts only shipping methods with selected: true", ->
|
||||
scope.ShippingMethods = [ { selected: true }, { selected: true }, { selected: false }, { selected: true } ]
|
||||
expect(scope.selectedShippingMethodsCount()).toBe 3
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user