mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Merge branch 'master' into product-amount-units
Conflicts: app/assets/javascripts/admin/bulk_product_update.js.coffee spec/spec_helper.rb
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
describe "filtering products", ->
|
||||
describe "filtering products for submission to database", ->
|
||||
it "accepts an object or an array and only returns an array", ->
|
||||
expect(filterSubmitProducts([])).toEqual []
|
||||
expect(filterSubmitProducts({})).toEqual []
|
||||
@@ -276,15 +276,41 @@ describe "AdminBulkProductsCtrl", ->
|
||||
it "gets a list of suppliers and then resets products with a list of data", ->
|
||||
httpBackend.expectGET("/api/users/authorise_api?token=api_key").respond success: "Use of API Authorised"
|
||||
httpBackend.expectGET("/api/enterprises/managed?template=bulk_index&q[is_primary_producer_eq]=true").respond "list of suppliers"
|
||||
httpBackend.expectGET("/api/products/managed?template=bulk_index;page=1;per_page=500").respond "list of products"
|
||||
spyOn scope, "resetProducts"
|
||||
spyOn(scope, "fetchProducts").andReturn "nothing"
|
||||
scope.initialise "api_key"
|
||||
httpBackend.flush()
|
||||
expect(scope.suppliers).toEqual "list of suppliers"
|
||||
expect(scope.resetProducts).toHaveBeenCalledWith "list of products"
|
||||
expect(scope.fetchProducts.calls.length).toEqual 1
|
||||
expect(scope.spree_api_key_ok).toEqual true
|
||||
|
||||
|
||||
describe "fetching products", ->
|
||||
it "makes a standard call to dataFetcher when no filters exist", ->
|
||||
httpBackend.expectGET("/api/products/managed?template=bulk_index;page=1;per_page=500;").respond "list of products"
|
||||
scope.fetchProducts()
|
||||
|
||||
it "calls resetProducts after data has been received", ->
|
||||
spyOn scope, "resetProducts"
|
||||
httpBackend.expectGET("/api/products/managed?template=bulk_index;page=1;per_page=500;").respond "list of products"
|
||||
scope.fetchProducts()
|
||||
httpBackend.flush()
|
||||
expect(scope.resetProducts).toHaveBeenCalledWith "list of products"
|
||||
|
||||
it "applies filters when they are present", ->
|
||||
filter = {property: scope.filterableColumns[1], predicate:scope.filterTypes[0], value:"Product1"}
|
||||
scope.currentFilters.push filter # Don't use addFilter as that is not what we are testing
|
||||
expect(scope.currentFilters).toEqual [filter]
|
||||
httpBackend.expectGET("/api/products/managed?template=bulk_index;page=1;per_page=500;q[name_eq]=Product1;").respond "list of products"
|
||||
scope.fetchProducts()
|
||||
|
||||
it "sets the loading property to true before fetching products and unsets it when loading is complete", ->
|
||||
httpBackend.expectGET("/api/products/managed?template=bulk_index;page=1;per_page=500;").respond "list of products"
|
||||
scope.fetchProducts()
|
||||
expect(scope.loading).toEqual true
|
||||
httpBackend.flush()
|
||||
expect(scope.loading).toEqual false
|
||||
|
||||
|
||||
describe "resetting products", ->
|
||||
beforeEach ->
|
||||
spyOn scope, "unpackProduct"
|
||||
@@ -681,6 +707,7 @@ describe "AdminBulkProductsCtrl", ->
|
||||
]
|
||||
scope.updateProducts "list of dirty products"
|
||||
httpBackend.flush()
|
||||
timeout.flush()
|
||||
expect(scope.displaySuccess).toHaveBeenCalled()
|
||||
|
||||
it "runs displayFailure() when post return data does not match $scope.products", ->
|
||||
@@ -972,6 +999,62 @@ describe "AdminBulkProductsCtrl", ->
|
||||
]
|
||||
|
||||
|
||||
describe "filtering products", ->
|
||||
describe "adding a filter to the filter list", ->
|
||||
it "adds objects sent to addFilter() to $scope.currentFilters", ->
|
||||
spyOn(scope, "fetchProducts").andReturn "nothing"
|
||||
filterObject1 = {property: scope.filterableColumns[0], predicate: scope.filterTypes[0], value: "Product1"}
|
||||
filterObject2 = {property: scope.filterableColumns[0], predicate: scope.filterTypes[0], value: "Product2"}
|
||||
scope.addFilter filterObject1
|
||||
scope.addFilter filterObject2
|
||||
expect(scope.currentFilters).toEqual [filterObject1, filterObject2]
|
||||
|
||||
it "ignores objects sent to addFilter() which do not contain a 'property' with a corresponding key in filterableColumns", ->
|
||||
spyOn(scope, "fetchProducts").andReturn "nothing"
|
||||
filterObject1 = {property: scope.filterableColumns[0], predicate: scope.filterTypes[0], value: "value1"}
|
||||
filterObject2 = {property: scope.filterableColumns[1], predicate: scope.filterTypes[0], value: "value2"}
|
||||
filterObject3 = {property: "some_random_property", predicate: scope.filterTypes[0], value: "value3"}
|
||||
scope.addFilter filterObject1
|
||||
scope.addFilter filterObject2
|
||||
scope.addFilter filterObject3
|
||||
expect(scope.currentFilters).toEqual [filterObject1, filterObject2]
|
||||
|
||||
it "ignores objects sent to addFilter() which do not contain a query with a corresponding key in filterTypes", ->
|
||||
spyOn(scope, "fetchProducts").andReturn "nothing"
|
||||
filterObject1 = {property: scope.filterableColumns[0], predicate: scope.filterTypes[0], value: "value1"}
|
||||
filterObject2 = {property: scope.filterableColumns[0], predicate: scope.filterTypes[1], value: "value2"}
|
||||
filterObject3 = {property: scope.filterableColumns[0], predicate: "something", value: "value3"}
|
||||
scope.addFilter filterObject1
|
||||
scope.addFilter filterObject2
|
||||
scope.addFilter filterObject3
|
||||
expect(scope.currentFilters).toEqual [filterObject1, filterObject2]
|
||||
|
||||
it "calls fetchProducts when adding a new filter", ->
|
||||
spyOn(scope, "fetchProducts").andReturn "nothing"
|
||||
scope.addFilter( { property: scope.filterableColumns[0], predicate: scope.filterTypes[0], value: "value1" } )
|
||||
expect(scope.fetchProducts.calls.length).toEqual(1)
|
||||
|
||||
describe "removing a filter from the filter list", ->
|
||||
filterObject1 = filterObject2 = null
|
||||
|
||||
beforeEach ->
|
||||
filterObject1 = {property: scope.filterableColumns[0], predicate: scope.filterTypes[0], value: "Product1"}
|
||||
filterObject2 = {property: scope.filterableColumns[0], predicate: scope.filterTypes[0], value: "Product2"}
|
||||
scope.currentFilters = [ filterObject1, filterObject2 ]
|
||||
|
||||
it "removes the specified filter from $scope.currentFilters and calls fetchProducts", ->
|
||||
spyOn(scope, "fetchProducts").andReturn "nothing"
|
||||
scope.removeFilter filterObject1
|
||||
expect(scope.currentFilters).toEqual [ filterObject2 ]
|
||||
expect(scope.fetchProducts.calls.length).toEqual 1
|
||||
|
||||
it "ignores filters which do not exist in currentFilters", ->
|
||||
spyOn(scope, "fetchProducts").andReturn "nothing"
|
||||
filterObject3 = {property: scope.filterableColumns[1], predicate: scope.filterTypes[1], value: "SomethingElse"}
|
||||
scope.removeFilter filterObject3
|
||||
expect(scope.currentFilters).toEqual [ filterObject1, filterObject2 ]
|
||||
expect(scope.fetchProducts.calls.length).toEqual 0
|
||||
|
||||
|
||||
describe "converting arrays of objects with ids to an object with ids as keys", ->
|
||||
it "returns an object", ->
|
||||
|
||||
40
spec/javascripts/unit/darkswarm/controllers_spec.js.coffee
Normal file
40
spec/javascripts/unit/darkswarm/controllers_spec.js.coffee
Normal file
@@ -0,0 +1,40 @@
|
||||
describe 'All controllers', ->
|
||||
describe 'ProductsCtrl', ->
|
||||
ctrl = null
|
||||
scope = null
|
||||
event = null
|
||||
rootScope = null
|
||||
Product = null
|
||||
|
||||
beforeEach ->
|
||||
module('Shop')
|
||||
Product =
|
||||
all: ->
|
||||
update: ->
|
||||
data: "testy mctest"
|
||||
|
||||
inject ($controller, $rootScope) ->
|
||||
rootScope = $rootScope
|
||||
scope = $rootScope.$new()
|
||||
ctrl = $controller 'ProductsCtrl', {$scope: scope, Product : Product}
|
||||
|
||||
it 'Fetches products from Product', ->
|
||||
expect(scope.data).toEqual 'testy mctest'
|
||||
|
||||
|
||||
describe 'OrderCycleCtrl', ->
|
||||
ctrl = null
|
||||
scope = null
|
||||
event = null
|
||||
rootScope = null
|
||||
product_ctrl = null
|
||||
OrderCycle = null
|
||||
|
||||
beforeEach ->
|
||||
module 'Shop'
|
||||
scope = {}
|
||||
inject ($controller, $rootScope) ->
|
||||
rootScope = $rootScope
|
||||
scope = $rootScope.$new()
|
||||
ctrl = $controller 'OrderCycleCtrl', {$scope: scope}
|
||||
|
||||
34
spec/javascripts/unit/darkswarm/order_cycle_spec.js.coffee
Normal file
34
spec/javascripts/unit/darkswarm/order_cycle_spec.js.coffee
Normal file
@@ -0,0 +1,34 @@
|
||||
describe 'OrderCycle service', ->
|
||||
$httpBackend = null
|
||||
OrderCycle = null
|
||||
mockProduct = {
|
||||
update: ->
|
||||
}
|
||||
|
||||
beforeEach ->
|
||||
angular.module('Shop').value('orderCycleData', {})
|
||||
module 'Shop', ($provide)->
|
||||
$provide.value "Product", mockProduct
|
||||
null # IMPORTANT
|
||||
# You must return null because module() is a bit dumb
|
||||
|
||||
inject (_OrderCycle_, _$httpBackend_)->
|
||||
$httpBackend = _$httpBackend_
|
||||
OrderCycle = _OrderCycle_
|
||||
|
||||
|
||||
it "posts the order_cycle ID and tells product to update", ->
|
||||
$httpBackend.expectPOST("/shop/order_cycle", {"order_cycle_id" : 10}).respond(200)
|
||||
spyOn(mockProduct, "update")
|
||||
OrderCycle.order_cycle.order_cycle_id = 10
|
||||
OrderCycle.push_order_cycle()
|
||||
$httpBackend.flush()
|
||||
expect(mockProduct.update).toHaveBeenCalled()
|
||||
|
||||
it "updates the orders_close_at attr after update", ->
|
||||
datestring = "2013-12-20T00:00:00+11:00"
|
||||
$httpBackend.expectPOST("/shop/order_cycle").respond({orders_close_at: datestring})
|
||||
OrderCycle.push_order_cycle()
|
||||
$httpBackend.flush()
|
||||
expect(OrderCycle.order_cycle.orders_close_at).toEqual(datestring)
|
||||
|
||||
14
spec/javascripts/unit/darkswarm/product_spec.js.coffee
Normal file
14
spec/javascripts/unit/darkswarm/product_spec.js.coffee
Normal file
@@ -0,0 +1,14 @@
|
||||
describe 'Product service', ->
|
||||
$httpBackend = null
|
||||
Product = null
|
||||
|
||||
beforeEach ->
|
||||
module 'Shop'
|
||||
inject ($injector, _$httpBackend_)->
|
||||
Product = $injector.get("Product")
|
||||
$httpBackend = _$httpBackend_
|
||||
|
||||
it "Fetches products from the backend on init", ->
|
||||
$httpBackend.expectGET("/shop/products").respond([{test : "cats"}])
|
||||
products = Product.all()
|
||||
$httpBackend.flush()
|
||||
@@ -754,4 +754,4 @@ describe 'OrderCycle services', ->
|
||||
expect(data.incoming_exchanges[0].enterprise_fees).toBeUndefined()
|
||||
expect(data.outgoing_exchanges[0].enterprise_fees).toBeUndefined()
|
||||
expect(data.incoming_exchanges[0].enterprise_fee_ids).toEqual [1, 2]
|
||||
expect(data.outgoing_exchanges[0].enterprise_fee_ids).toEqual [3, 4]
|
||||
expect(data.outgoing_exchanges[0].enterprise_fee_ids).toEqual [3, 4]
|
||||
|
||||
Reference in New Issue
Block a user