Make total number of products in exchange work again.

Currently we are just loading the products from the server and count them.
This can be improved easily in two ways:
- we can switch this to a specific product count call to the server so that we dont load all products all the time
- or we paginate the products result and fetch the total_number from the payload of the first page.
This commit is contained in:
luisramos0
2019-11-11 13:21:33 +00:00
parent 2b3bc6d1ff
commit 3223bf930d
6 changed files with 45 additions and 34 deletions

View File

@@ -13,14 +13,23 @@ describe 'AdminOrderCycleIncomingCtrl', ->
location =
absUrl: ->
'example.com/admin/order_cycles/27/edit'
Enterprise =
totalVariants: jasmine.createSpy('totalVariants').and.returnValue('variants total')
ocInstance = {}
module('admin.orderCycles')
inject ($controller) ->
ctrl = $controller 'AdminOrderCycleIncomingCtrl', {$scope: scope, $location: location, OrderCycle: OrderCycle, Enterprise: Enterprise, EnterpriseFee: EnterpriseFee, ocInstance: ocInstance}
it 'Delegates totalVariants to Enterprise', ->
expect(scope.enterpriseTotalVariants('enterprise')).toEqual('variants total')
expect(Enterprise.totalVariants).toHaveBeenCalledWith('enterprise')
it 'counts total variants in a list of products', ->
products = [
{variants: [{}]},
{variants: [{}]},
{variants: [{}, {}, {}]}
]
expect(scope.countVariants(products)).toEqual(5)
it 'returns zero when products list is null', ->
expect(scope.countVariants(null)).toEqual(0)
it 'returns zero when products list is empty', ->
expect(scope.countVariants([])).toEqual(0)

View File

@@ -56,16 +56,3 @@ describe 'Enterprise service', ->
master_id: 1
variants: [{id: 2}, {id: 3}]
expect(Enterprise.variantsOf(p)).toEqual [2, 3]
it 'counts total variants supplied by an enterprise', ->
enterprise =
supplied_products: [
{variants: []},
{variants: []},
{variants: [{}, {}, {}]}
]
expect(Enterprise.totalVariants(enterprise)).toEqual(5)
it 'returns zero when enterprise is null', ->
expect(Enterprise.totalVariants(null)).toEqual(0)