mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-01 02:03:22 +00:00
Add unit spec for order cycles simple create controller
This commit is contained in:
@@ -1,19 +1,21 @@
|
||||
angular.module('admin.order_cycles').controller "AdminSimpleCreateOrderCycleCtrl", ($scope, OrderCycle, Enterprise, EnterpriseFee) ->
|
||||
$scope.enterprises = Enterprise.index (enterprises) =>
|
||||
$scope.init(enterprises)
|
||||
$scope.enterprise_fees = EnterpriseFee.index()
|
||||
$scope.order_cycle = OrderCycle.order_cycle
|
||||
|
||||
$scope.init = (enterprises) ->
|
||||
enterprise = enterprises[Object.keys(enterprises)[0]]
|
||||
OrderCycle.addSupplier enterprise.id
|
||||
OrderCycle.addDistributor enterprise.id
|
||||
$scope.outgoing_exchange = OrderCycle.order_cycle.outgoing_exchanges[0]
|
||||
|
||||
# All variants start as checked
|
||||
OrderCycle.setExchangeVariants(OrderCycle.order_cycle.incoming_exchanges[0],
|
||||
Enterprise.suppliedVariants(enterprise.id), true)
|
||||
|
||||
OrderCycle.order_cycle.coordinator_id = enterprise.id
|
||||
|
||||
$scope.enterprise_fees = EnterpriseFee.index()
|
||||
|
||||
$scope.order_cycle = OrderCycle.order_cycle
|
||||
|
||||
$scope.loaded = ->
|
||||
Enterprise.loaded && EnterpriseFee.loaded
|
||||
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
describe "AdminSimpleCreateOrderCycleCtrl", ->
|
||||
ctrl = null
|
||||
scope = {}
|
||||
OrderCycle = {}
|
||||
Enterprise = {}
|
||||
EnterpriseFee = {}
|
||||
incoming_exchange = {}
|
||||
outgoing_exchange = {}
|
||||
|
||||
beforeEach ->
|
||||
scope = {}
|
||||
OrderCycle =
|
||||
order_cycle:
|
||||
incoming_exchanges: [incoming_exchange]
|
||||
outgoing_exchanges: [outgoing_exchange]
|
||||
addSupplier: jasmine.createSpy()
|
||||
addDistributor: jasmine.createSpy()
|
||||
setExchangeVariants: jasmine.createSpy()
|
||||
Enterprise =
|
||||
index: jasmine.createSpy()
|
||||
suppliedVariants: jasmine.createSpy().andReturn('supplied variants')
|
||||
EnterpriseFee =
|
||||
index: jasmine.createSpy()
|
||||
|
||||
module('admin.order_cycles')
|
||||
inject ($controller) ->
|
||||
ctrl = $controller 'AdminSimpleCreateOrderCycleCtrl', {$scope: scope, OrderCycle: OrderCycle, Enterprise: Enterprise, EnterpriseFee: EnterpriseFee}
|
||||
|
||||
describe "initialisation", ->
|
||||
enterprise = {id: 123}
|
||||
enterprises = {123: enterprise}
|
||||
|
||||
beforeEach ->
|
||||
scope.init(enterprises)
|
||||
|
||||
it "sets up an incoming and outgoing exchange", ->
|
||||
expect(OrderCycle.addSupplier).toHaveBeenCalledWith(enterprise.id)
|
||||
expect(OrderCycle.addDistributor).toHaveBeenCalledWith(enterprise.id)
|
||||
expect(scope.outgoing_exchange).toEqual outgoing_exchange
|
||||
|
||||
it "selects all variants", ->
|
||||
expect(Enterprise.suppliedVariants).
|
||||
toHaveBeenCalledWith(enterprise.id)
|
||||
|
||||
expect(OrderCycle.setExchangeVariants).
|
||||
toHaveBeenCalledWith(incoming_exchange, 'supplied variants', true)
|
||||
|
||||
it "sets the coordinator", ->
|
||||
expect(OrderCycle.order_cycle.coordinator_id).toEqual enterprise.id
|
||||
Reference in New Issue
Block a user