mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-02 21:57:17 +00:00
Merge branch 'master' into currency
Conflicts: app/helpers/injection_helper.rb db/suburb_seeds.rb
This commit is contained in:
@@ -12,5 +12,5 @@ describe "enterprise relationships", ->
|
||||
EnterpriseRelationships = _EnterpriseRelationships_
|
||||
|
||||
it "presents permission names", ->
|
||||
expect(EnterpriseRelationships.permission_presentation("add_to_order_cycle")).toEqual "can add to order cycle"
|
||||
expect(EnterpriseRelationships.permission_presentation("manage_products")).toEqual "can manage the products of"
|
||||
expect(EnterpriseRelationships.permission_presentation("add_to_order_cycle")).toEqual "to add to order cycle"
|
||||
expect(EnterpriseRelationships.permission_presentation("manage_products")).toEqual "to manage products"
|
||||
|
||||
@@ -2,7 +2,9 @@ describe "AdminOrderMgmtCtrl", ->
|
||||
ctrl = scope = httpBackend = VariantUnitManager = null
|
||||
|
||||
beforeEach ->
|
||||
module "ofn.admin"
|
||||
module "ofn.admin", ($provide) ->
|
||||
$provide.value 'SpreeApiKey', 'API_KEY'
|
||||
return
|
||||
beforeEach inject(($controller, $rootScope, $httpBackend, _VariantUnitManager_) ->
|
||||
scope = $rootScope.$new()
|
||||
ctrl = $controller
|
||||
@@ -18,7 +20,7 @@ describe "AdminOrderMgmtCtrl", ->
|
||||
returnedSuppliers = ["list of suppliers"]
|
||||
returnedDistributors = ["list of distributors"]
|
||||
returnedOrderCycles = [ "oc1", "oc2", "oc3" ]
|
||||
httpBackend.expectGET("/api/users/authorise_api?token=api_key").respond success: "Use of API Authorised"
|
||||
httpBackend.expectGET("/api/users/authorise_api?token=API_KEY").respond success: "Use of API Authorised"
|
||||
httpBackend.expectGET("/api/enterprises/accessible?template=bulk_index&q[is_primary_producer_eq]=true").respond returnedSuppliers
|
||||
httpBackend.expectGET("/api/enterprises/accessible?template=bulk_index&q[is_distributor_eq]=true").respond returnedDistributors
|
||||
httpBackend.expectGET("/api/order_cycles/accessible").respond returnedOrderCycles
|
||||
@@ -27,7 +29,7 @@ describe "AdminOrderMgmtCtrl", ->
|
||||
#spyOn(returnedSuppliers, "unshift")
|
||||
#spyOn(returnedDistributors, "unshift")
|
||||
#spyOn(returnedOrderCycles, "unshift")
|
||||
scope.initialise "api_key"
|
||||
scope.initialise()
|
||||
httpBackend.flush()
|
||||
|
||||
expect(scope.suppliers).toEqual [{ id : '0', name : 'All' }, 'list of suppliers']
|
||||
|
||||
@@ -165,7 +165,7 @@ describe "filtering products for submission to database", ->
|
||||
variant_unit: 'weight'
|
||||
variant_unit_scale: 1
|
||||
]
|
||||
|
||||
|
||||
# TODO Not an exhaustive test, is there a better way to do this?
|
||||
it "only returns the properties of products which ought to be updated", ->
|
||||
available_on = new Date()
|
||||
@@ -238,6 +238,7 @@ describe "AdminProductEditCtrl", ->
|
||||
module ($provide)->
|
||||
$provide.value "producers", []
|
||||
$provide.value "taxons", []
|
||||
$provide.value 'SpreeApiKey', 'API_KEY'
|
||||
null
|
||||
|
||||
beforeEach inject((_$controller_, _$timeout_, $rootScope, _$httpBackend_, _DirtyProducts_) ->
|
||||
@@ -252,9 +253,9 @@ describe "AdminProductEditCtrl", ->
|
||||
|
||||
describe "loading data upon initialisation", ->
|
||||
it "gets a list of producers 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/users/authorise_api?token=API_KEY").respond success: "Use of API Authorised"
|
||||
spyOn($scope, "fetchProducts").andReturn "nothing"
|
||||
$scope.initialise "api_key"
|
||||
$scope.initialise()
|
||||
$httpBackend.flush()
|
||||
expect($scope.fetchProducts.calls.length).toEqual 1
|
||||
expect($scope.spree_api_key_ok).toEqual true
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
describe "EnterpriseRegistrationService", ->
|
||||
EnterpriseRegistrationService = null
|
||||
$httpBackend = null
|
||||
availableCountries = []
|
||||
enterpriseAttributes =
|
||||
name: "Enterprise 1"
|
||||
something: true
|
||||
spreeApiKey = "keykeykeykey"
|
||||
CurrentUser =
|
||||
id: 2
|
||||
email: 'lalala@email.com'
|
||||
RegistrationServiceMock =
|
||||
select: -> null
|
||||
|
||||
beforeEach ->
|
||||
module('Darkswarm')
|
||||
angular.module('Darkswarm').value 'availableCountries', availableCountries
|
||||
angular.module('Darkswarm').value 'enterpriseAttributes', enterpriseAttributes
|
||||
angular.module('Darkswarm').value 'spreeApiKey', spreeApiKey
|
||||
angular.module('Darkswarm').value 'CurrentUser', CurrentUser
|
||||
angular.module('Darkswarm').value 'RegistrationService', RegistrationServiceMock
|
||||
|
||||
inject ($injector, _$httpBackend_) ->
|
||||
$httpBackend = _$httpBackend_
|
||||
EnterpriseRegistrationService = $injector.get("EnterpriseRegistrationService")
|
||||
|
||||
it "adds the specified attributes to the ERS enterprise object", ->
|
||||
expect(EnterpriseRegistrationService.enterprise.name).toBe "Enterprise 1"
|
||||
expect(EnterpriseRegistrationService.enterprise.something).toBe true
|
||||
|
||||
describe "creating an enterprise", ->
|
||||
describe "success", ->
|
||||
beforeEach ->
|
||||
spyOn(RegistrationServiceMock, "select")
|
||||
$httpBackend.expectPOST("/api/enterprises?token=keykeykeykey").respond 200, 6
|
||||
EnterpriseRegistrationService.create()
|
||||
$httpBackend.flush()
|
||||
|
||||
it "stores the id of the created enterprise", ->
|
||||
expect(EnterpriseRegistrationService.enterprise.id).toBe 6
|
||||
|
||||
it "moves the user to the about page", ->
|
||||
expect(RegistrationServiceMock.select).toHaveBeenCalledWith 'about'
|
||||
|
||||
describe "failure", ->
|
||||
beforeEach ->
|
||||
spyOn(RegistrationServiceMock, "select")
|
||||
spyOn(window, "alert")
|
||||
$httpBackend.expectPOST("/api/enterprises?token=keykeykeykey").respond 400, 6
|
||||
EnterpriseRegistrationService.create()
|
||||
$httpBackend.flush()
|
||||
|
||||
it "alerts the user to failure", ->
|
||||
expect(window.alert).toHaveBeenCalledWith 'Failed to create your enterprise.\nPlease ensure all fields are completely filled out.'
|
||||
|
||||
it "does not move the user to the about page", ->
|
||||
expect(RegistrationServiceMock.select).not.toHaveBeenCalled
|
||||
|
||||
|
||||
describe "updating an enterprise", ->
|
||||
beforeEach ->
|
||||
EnterpriseRegistrationService.enterprise.id = 78
|
||||
spyOn(RegistrationServiceMock, "select")
|
||||
|
||||
describe "success", ->
|
||||
beforeEach ->
|
||||
$httpBackend.expectPUT("/api/enterprises/78?token=keykeykeykey").respond 200, 6
|
||||
EnterpriseRegistrationService.update('step')
|
||||
$httpBackend.flush()
|
||||
|
||||
it "moves the user to the about page", ->
|
||||
expect(RegistrationServiceMock.select).toHaveBeenCalledWith 'step'
|
||||
|
||||
describe "failure", ->
|
||||
beforeEach ->
|
||||
spyOn(window, "alert")
|
||||
$httpBackend.expectPUT("/api/enterprises/78?token=keykeykeykey").respond 400, 6
|
||||
EnterpriseRegistrationService.update('step')
|
||||
$httpBackend.flush()
|
||||
|
||||
it "alerts the user to failure", ->
|
||||
expect(window.alert).toHaveBeenCalledWith 'Failed to update your enterprise.\nPlease ensure all fields are completely filled out.'
|
||||
|
||||
it "does not move the user to the about page", ->
|
||||
expect(RegistrationServiceMock.select).not.toHaveBeenCalled
|
||||
@@ -8,18 +8,21 @@ describe "Hubs service", ->
|
||||
active: false
|
||||
orders_close_at: new Date()
|
||||
is_distributor: true
|
||||
has_shopfront: true
|
||||
}
|
||||
{
|
||||
id: 3
|
||||
active: false
|
||||
orders_close_at: new Date()
|
||||
is_distributor: true
|
||||
has_shopfront: true
|
||||
}
|
||||
{
|
||||
id: 1
|
||||
active: true
|
||||
orders_close_at: new Date()
|
||||
is_distributor: true
|
||||
has_shopfront: true
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
@@ -516,30 +516,44 @@ describe 'OrderCycle services', ->
|
||||
]
|
||||
|
||||
describe 'removing exchanges', ->
|
||||
it 'removes incoming exchanges', ->
|
||||
exchange = {enterprise_id: '123', active: true, variants: {}, enterprise_fees: []}
|
||||
OrderCycle.order_cycle.incoming_exchanges = [exchange]
|
||||
OrderCycle.removeExchange(exchange)
|
||||
expect(OrderCycle.order_cycle.incoming_exchanges).toEqual []
|
||||
exchange = null
|
||||
|
||||
it 'removes outgoing exchanges', ->
|
||||
exchange = {enterprise_id: '123', active: true, variants: {}, enterprise_fees: []}
|
||||
OrderCycle.order_cycle.outgoing_exchanges = [exchange]
|
||||
OrderCycle.removeExchange(exchange)
|
||||
expect(OrderCycle.order_cycle.outgoing_exchanges).toEqual []
|
||||
|
||||
it 'removes distribution of all exchange variants', ->
|
||||
beforeEach ->
|
||||
spyOn(OrderCycle, 'removeDistributionOfVariant')
|
||||
exchange =
|
||||
enterprise_id: '123'
|
||||
active: true
|
||||
incoming: false
|
||||
variants: {1: true, 2: false, 3: true}
|
||||
enterprise_fees: []
|
||||
OrderCycle.order_cycle.incoming_exchanges = [exchange]
|
||||
OrderCycle.removeExchange(exchange)
|
||||
expect(OrderCycle.removeDistributionOfVariant).toHaveBeenCalledWith('1')
|
||||
expect(OrderCycle.removeDistributionOfVariant).not.toHaveBeenCalledWith('2')
|
||||
expect(OrderCycle.removeDistributionOfVariant).toHaveBeenCalledWith('3')
|
||||
|
||||
describe "removing incoming exchanges", ->
|
||||
beforeEach ->
|
||||
exchange.incoming = true
|
||||
OrderCycle.order_cycle.incoming_exchanges = [exchange]
|
||||
|
||||
it 'removes the exchange', ->
|
||||
OrderCycle.removeExchange(exchange)
|
||||
expect(OrderCycle.order_cycle.incoming_exchanges).toEqual []
|
||||
|
||||
it 'removes distribution of all exchange variants', ->
|
||||
OrderCycle.removeExchange(exchange)
|
||||
expect(OrderCycle.removeDistributionOfVariant).toHaveBeenCalledWith('1')
|
||||
expect(OrderCycle.removeDistributionOfVariant).not.toHaveBeenCalledWith('2')
|
||||
expect(OrderCycle.removeDistributionOfVariant).toHaveBeenCalledWith('3')
|
||||
|
||||
describe "removing outgoing exchanges", ->
|
||||
beforeEach ->
|
||||
exchange.incoming = false
|
||||
OrderCycle.order_cycle.outgoing_exchanges = [exchange]
|
||||
|
||||
it 'removes the exchange', ->
|
||||
OrderCycle.removeExchange(exchange)
|
||||
expect(OrderCycle.order_cycle.outgoing_exchanges).toEqual []
|
||||
|
||||
it "does not remove distribution of any variants", ->
|
||||
OrderCycle.removeExchange(exchange)
|
||||
expect(OrderCycle.removeDistributionOfVariant).not.toHaveBeenCalled()
|
||||
|
||||
it 'adds coordinator fees', ->
|
||||
OrderCycle.addCoordinatorFee()
|
||||
|
||||
Reference in New Issue
Block a user