Add unit spec for order cycles simple create controller

This commit is contained in:
Rohan Mitchell
2014-10-23 10:21:19 +11:00
parent 2ad823a79d
commit 8b616e7d17
2 changed files with 55 additions and 4 deletions

View File

@@ -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

View File

@@ -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