mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Add methods to check for novel suppliers and distributors in an order cycle
This commit is contained in:
@@ -6,11 +6,20 @@ angular.module('admin.orderCycles').factory('OrderCycle', ($resource, $window, $
|
||||
'update': { method: 'PUT'}}
|
||||
|
||||
{
|
||||
order_cycle: {}
|
||||
order_cycle: {incoming_exchanges: [], outgoing_exchanges: []}
|
||||
showProducts: {incoming: false, outgoing: false}
|
||||
|
||||
loaded: false
|
||||
|
||||
exchangeIds: (direction) ->
|
||||
parseInt(exchange.enterprise_id) for exchange in @exchangesByDirection(direction)
|
||||
|
||||
novelSupplier: (enterprise) ->
|
||||
@exchangeIds('incoming').indexOf(enterprise.id) == -1
|
||||
|
||||
novelDistributor: (enterprise) ->
|
||||
@exchangeIds('outgoing').indexOf(enterprise.id) == -1
|
||||
|
||||
exchangeSelectedVariants: (exchange) ->
|
||||
numActiveVariants = 0
|
||||
numActiveVariants++ for id, active of exchange.variants when active
|
||||
|
||||
@@ -470,12 +470,39 @@ describe 'OrderCycle services', ->
|
||||
exchanges: []
|
||||
|
||||
it 'initialises order cycle', ->
|
||||
expect(OrderCycle.order_cycle).toEqual {}
|
||||
expect(OrderCycle.order_cycle).toEqual {incoming_exchanges: [], outgoing_exchanges: []}
|
||||
|
||||
it 'counts selected variants in an exchange', ->
|
||||
result = OrderCycle.exchangeSelectedVariants({variants: {1: true, 2: false, 3: true}})
|
||||
expect(result).toEqual(2)
|
||||
|
||||
describe "fetching exchange ids", ->
|
||||
it "gets enterprise ids as ints", ->
|
||||
OrderCycle.order_cycle.incoming_exchanges = [
|
||||
{enterprise_id: 1}
|
||||
{enterprise_id: '2'}
|
||||
]
|
||||
OrderCycle.order_cycle.outgoing_exchanges = [
|
||||
{enterprise_id: 3}
|
||||
{enterprise_id: '4'}
|
||||
]
|
||||
expect(OrderCycle.exchangeIds('incoming')).toEqual [1, 2]
|
||||
|
||||
describe "checking for novel enterprises", ->
|
||||
it "detects novel suppliers", ->
|
||||
e1 = {id: 1}
|
||||
e2 = {id: 2}
|
||||
OrderCycle.order_cycle.incoming_exchanges = [{enterprise_id: 1}]
|
||||
expect(OrderCycle.novelSupplier(e1)).toBe false
|
||||
expect(OrderCycle.novelSupplier(e2)).toBe true
|
||||
|
||||
it "detects novel distributors", ->
|
||||
e1 = {id: 1}
|
||||
e2 = {id: 2}
|
||||
OrderCycle.order_cycle.outgoing_exchanges = [{enterprise_id: 1}]
|
||||
expect(OrderCycle.novelDistributor(e1)).toBe false
|
||||
expect(OrderCycle.novelDistributor(e2)).toBe true
|
||||
|
||||
describe 'fetching the direction for an exchange', ->
|
||||
it 'returns "incoming" for incoming exchanges', ->
|
||||
exchange = {id: 1}
|
||||
|
||||
Reference in New Issue
Block a user