mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-11 03:40:20 +00:00
Make simple create and edit OC load exchange products on init
Simple create makes a new type of call to exchange products with no exchange_id and no prder_cycle_id, it simply lists supplied products for a given enterprise
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
describe "AdminSimpleCreateOrderCycleCtrl", ->
|
||||
ctrl = null
|
||||
scope = {}
|
||||
scope = null
|
||||
OrderCycle = {}
|
||||
Enterprise = {}
|
||||
Product = {}
|
||||
EnterpriseFee = {}
|
||||
incoming_exchange = {}
|
||||
outgoing_exchange = {}
|
||||
@@ -10,27 +11,32 @@ describe "AdminSimpleCreateOrderCycleCtrl", ->
|
||||
beforeEach ->
|
||||
scope =
|
||||
$watch: jasmine.createSpy('$watch')
|
||||
setOutgoingExchange: jasmine.createSpy('setOutgoingExchange')
|
||||
loadExchangeProducts: jasmine.createSpy('loadExchangeProducts')
|
||||
storeProductsAndSelectAllVariants: jasmine.createSpy('storeProductsAndSelectAllVariants')
|
||||
order_cycle =
|
||||
coordinator_id: 123
|
||||
incoming_exchanges: [incoming_exchange]
|
||||
outgoing_exchanges: [outgoing_exchange]
|
||||
OrderCycle =
|
||||
order_cycle: order_cycle
|
||||
addSupplier: jasmine.createSpy()
|
||||
addDistributor: jasmine.createSpy()
|
||||
setExchangeVariants: jasmine.createSpy()
|
||||
addSupplier: jasmine.createSpy('addSupplier')
|
||||
addDistributor: jasmine.createSpy('addDistributor')
|
||||
setExchangeVariants: jasmine.createSpy('setExchangeVariants')
|
||||
new: jasmine.createSpy().and.returnValue order_cycle
|
||||
Enterprise =
|
||||
get: jasmine.createSpy().and.returnValue {id: 123}
|
||||
index: jasmine.createSpy()
|
||||
suppliedVariants: jasmine.createSpy().and.returnValue('supplied variants')
|
||||
Product =
|
||||
index: jasmine.createSpy()
|
||||
EnterpriseFee =
|
||||
index: jasmine.createSpy()
|
||||
ocInstance = {}
|
||||
|
||||
module('admin.orderCycles')
|
||||
inject ($controller) ->
|
||||
ctrl = $controller 'AdminSimpleCreateOrderCycleCtrl', {$scope: scope, OrderCycle: OrderCycle, Enterprise: Enterprise, EnterpriseFee: EnterpriseFee, ocInstance: ocInstance}
|
||||
ctrl = $controller 'AdminSimpleCreateOrderCycleCtrl', {$scope: scope, OrderCycle: OrderCycle, Enterprise: Enterprise, EnterpriseFee: EnterpriseFee, Product: Product, ocInstance: ocInstance}
|
||||
|
||||
describe "initialisation", ->
|
||||
enterprise = {id: 123}
|
||||
@@ -39,15 +45,26 @@ describe "AdminSimpleCreateOrderCycleCtrl", ->
|
||||
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 "adds enterprise as both the supplier and the distributor", ->
|
||||
expect(OrderCycle.addSupplier).toHaveBeenCalledWith(enterprise.id, scope.loadExchangeProducts)
|
||||
expect(OrderCycle.addDistributor).toHaveBeenCalledWith(enterprise.id, scope.setOutgoingExchange)
|
||||
|
||||
it "loads exchange products", ->
|
||||
incoming_exchange.enterprise_id = enterprise.id
|
||||
|
||||
scope.loadExchangeProducts()
|
||||
|
||||
expect(Product.index).toHaveBeenCalledWith({ enterprise_id: enterprise.id, incoming: true }, scope.storeProductsAndSelectAllVariants)
|
||||
|
||||
it "stores products and selects all variants", ->
|
||||
scope.incoming_exchange = incoming_exchange
|
||||
incoming_exchange.enterprise_id = enterprise.id
|
||||
scope.enterprises = { "#{enterprise.id}": {}}
|
||||
|
||||
scope.storeProductsAndSelectAllVariants()
|
||||
|
||||
it "selects all variants", ->
|
||||
expect(Enterprise.suppliedVariants).
|
||||
toHaveBeenCalledWith(enterprise.id)
|
||||
|
||||
expect(OrderCycle.setExchangeVariants).
|
||||
toHaveBeenCalledWith(incoming_exchange, 'supplied variants', true)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user