mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-21 00:47:26 +00:00
Merge branch master into properties
This commit is contained in:
@@ -9,22 +9,27 @@ describe "AdminSimpleCreateOrderCycleCtrl", ->
|
||||
|
||||
beforeEach ->
|
||||
scope = {}
|
||||
order_cycle =
|
||||
coordinator_id: 123
|
||||
incoming_exchanges: [incoming_exchange]
|
||||
outgoing_exchanges: [outgoing_exchange]
|
||||
OrderCycle =
|
||||
order_cycle:
|
||||
incoming_exchanges: [incoming_exchange]
|
||||
outgoing_exchanges: [outgoing_exchange]
|
||||
order_cycle: order_cycle
|
||||
addSupplier: jasmine.createSpy()
|
||||
addDistributor: jasmine.createSpy()
|
||||
setExchangeVariants: jasmine.createSpy()
|
||||
new: jasmine.createSpy().andReturn order_cycle
|
||||
Enterprise =
|
||||
get: jasmine.createSpy().andReturn {id: 123}
|
||||
index: jasmine.createSpy()
|
||||
suppliedVariants: jasmine.createSpy().andReturn('supplied variants')
|
||||
EnterpriseFee =
|
||||
index: jasmine.createSpy()
|
||||
ocInstance = {}
|
||||
|
||||
module('admin.order_cycles')
|
||||
inject ($controller) ->
|
||||
ctrl = $controller 'AdminSimpleCreateOrderCycleCtrl', {$scope: scope, OrderCycle: OrderCycle, Enterprise: Enterprise, EnterpriseFee: EnterpriseFee}
|
||||
ctrl = $controller 'AdminSimpleCreateOrderCycleCtrl', {$scope: scope, OrderCycle: OrderCycle, Enterprise: Enterprise, EnterpriseFee: EnterpriseFee, ocInstance: ocInstance}
|
||||
|
||||
describe "initialisation", ->
|
||||
enterprise = {id: 123}
|
||||
@@ -46,4 +51,4 @@ describe "AdminSimpleCreateOrderCycleCtrl", ->
|
||||
toHaveBeenCalledWith(incoming_exchange, 'supplied variants', true)
|
||||
|
||||
it "sets the coordinator", ->
|
||||
expect(OrderCycle.order_cycle.coordinator_id).toEqual enterprise.id
|
||||
expect(OrderCycle.order_cycle.coordinator_id).toEqual enterprise.id
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
describe "ensuring absolute URL", ->
|
||||
filter = null
|
||||
|
||||
beforeEach ->
|
||||
module 'Darkswarm'
|
||||
inject ($filter) ->
|
||||
filter = $filter 'ext_url'
|
||||
|
||||
it "returns null when no URL given", ->
|
||||
expect(filter(null, "http://")).toBeNull()
|
||||
|
||||
it "returns the URL as-is for http URLs", ->
|
||||
expect(filter("http://example.com", "http://")).toEqual "http://example.com"
|
||||
|
||||
it "returns the URL as-is for https URLs", ->
|
||||
expect(filter("https://example.com", "https://")).toEqual "https://example.com"
|
||||
|
||||
it "returns with URL with prefix added when a relative URL is given", ->
|
||||
expect(filter("example.com", "http://")).toEqual "http://example.com"
|
||||
@@ -6,7 +6,10 @@ describe 'Cart service', ->
|
||||
|
||||
beforeEach ->
|
||||
module 'Darkswarm'
|
||||
variant = {id: 1}
|
||||
variant =
|
||||
id: 1
|
||||
name_to_display: 'name'
|
||||
product_name: 'name'
|
||||
order = {
|
||||
line_items: [
|
||||
variant: variant
|
||||
@@ -23,6 +26,9 @@ describe 'Cart service', ->
|
||||
it "registers variants with the Variants service", ->
|
||||
expect(Variants.variants[1]).toBe variant
|
||||
|
||||
it "generates extended variant names", ->
|
||||
expect(Cart.line_items[0].variant.extended_name).toEqual "name"
|
||||
|
||||
it "creates and backreferences new line items if necessary", ->
|
||||
Cart.register_variant(v2 = {id: 2})
|
||||
expect(Cart.line_items[1].variant).toBe v2
|
||||
@@ -37,3 +43,23 @@ describe 'Cart service', ->
|
||||
expect(Cart.line_items_present()).toEqual []
|
||||
order.line_items[0].quantity = 2
|
||||
expect(Cart.total_item_count()).toEqual 2
|
||||
|
||||
describe "generating an extended variant name", ->
|
||||
it "returns the product name when it is the same as the variant name", ->
|
||||
variant = {product_name: 'product_name', name_to_display: 'product_name'}
|
||||
expect(Cart.extendedVariantName(variant)).toEqual "product_name"
|
||||
|
||||
describe "when the product name and the variant name differ", ->
|
||||
it "returns a combined name when there is no options text", ->
|
||||
variant =
|
||||
product_name: 'product_name'
|
||||
name_to_display: 'name_to_display'
|
||||
expect(Cart.extendedVariantName(variant)).toEqual "product_name - name_to_display"
|
||||
|
||||
it "returns a combined name when there is some options text", ->
|
||||
variant =
|
||||
product_name: 'product_name'
|
||||
name_to_display: 'name_to_display'
|
||||
options_text: 'options_text'
|
||||
|
||||
expect(Cart.extendedVariantName(variant)).toEqual "product_name - name_to_display (options_text)"
|
||||
|
||||
@@ -13,7 +13,6 @@ describe 'OrderCycle controllers', ->
|
||||
event =
|
||||
preventDefault: jasmine.createSpy('preventDefault')
|
||||
OrderCycle =
|
||||
order_cycle: 'my order cycle'
|
||||
exchangeSelectedVariants: jasmine.createSpy('exchangeSelectedVariants').andReturn('variants selected')
|
||||
productSuppliedToOrderCycle: jasmine.createSpy('productSuppliedToOrderCycle').andReturn('product supplied')
|
||||
variantSuppliedToOrderCycle: jasmine.createSpy('variantSuppliedToOrderCycle').andReturn('variant supplied')
|
||||
@@ -29,6 +28,7 @@ describe 'OrderCycle controllers', ->
|
||||
removeExchangeFee: jasmine.createSpy('removeExchangeFee')
|
||||
removeDistributionOfVariant: jasmine.createSpy('removeDistributionOfVariant')
|
||||
create: jasmine.createSpy('create')
|
||||
new: jasmine.createSpy('new').andReturn "my order cycle"
|
||||
Enterprise =
|
||||
index: jasmine.createSpy('index').andReturn('enterprises list')
|
||||
supplied_products: 'supplied products'
|
||||
@@ -37,10 +37,11 @@ describe 'OrderCycle controllers', ->
|
||||
EnterpriseFee =
|
||||
index: jasmine.createSpy('index').andReturn('enterprise fees list')
|
||||
forEnterprise: jasmine.createSpy('forEnterprise').andReturn('enterprise fees for enterprise')
|
||||
ocInstance = {}
|
||||
|
||||
module('admin.order_cycles')
|
||||
inject ($controller) ->
|
||||
ctrl = $controller 'AdminCreateOrderCycleCtrl', {$scope: scope, OrderCycle: OrderCycle, Enterprise: Enterprise, EnterpriseFee: EnterpriseFee}
|
||||
ctrl = $controller 'AdminCreateOrderCycleCtrl', {$scope: scope, OrderCycle: OrderCycle, Enterprise: Enterprise, EnterpriseFee: EnterpriseFee, ocInstance: ocInstance}
|
||||
|
||||
|
||||
it 'Loads enterprises and supplied products', ->
|
||||
@@ -93,12 +94,14 @@ describe 'OrderCycle controllers', ->
|
||||
expect(scope.exchangeDirection('exchange')).toEqual('exchange direction')
|
||||
expect(OrderCycle.exchangeDirection).toHaveBeenCalledWith('exchange')
|
||||
|
||||
it 'Finds enterprises participating in the order cycle', ->
|
||||
it 'Finds enterprises participating in the order cycle that have fees', ->
|
||||
scope.enterprises =
|
||||
1: {id: 1, name: 'Eaterprises'}
|
||||
2: {id: 2, name: 'Pepper Tree Place'}
|
||||
3: {id: 3, name: 'South East'}
|
||||
OrderCycle.participatingEnterpriseIds = jasmine.createSpy('participatingEnterpriseIds').andReturn([2])
|
||||
expect(scope.participatingEnterprises()).toEqual([
|
||||
EnterpriseFee.enterprise_fees = [ {enterprise_id: 2} ] # Pepper Tree Place has a fee
|
||||
expect(scope.enterprisesWithFees()).toEqual([
|
||||
{id: 2, name: 'Pepper Tree Place'}
|
||||
])
|
||||
|
||||
@@ -254,12 +257,14 @@ describe 'OrderCycle controllers', ->
|
||||
expect(scope.exchangeDirection('exchange')).toEqual('exchange direction')
|
||||
expect(OrderCycle.exchangeDirection).toHaveBeenCalledWith('exchange')
|
||||
|
||||
it 'Finds enterprises participating in the order cycle', ->
|
||||
it 'Finds enterprises participating in the order cycle that have fees', ->
|
||||
scope.enterprises =
|
||||
1: {id: 1, name: 'Eaterprises'}
|
||||
2: {id: 2, name: 'Pepper Tree Place'}
|
||||
3: {id: 3, name: 'South East'}
|
||||
OrderCycle.participatingEnterpriseIds = jasmine.createSpy('participatingEnterpriseIds').andReturn([2])
|
||||
expect(scope.participatingEnterprises()).toEqual([
|
||||
EnterpriseFee.enterprise_fees = [ {enterprise_id: 2} ] # Pepper Tree Place has a fee
|
||||
expect(scope.enterprisesWithFees()).toEqual([
|
||||
{id: 2, name: 'Pepper Tree Place'}
|
||||
])
|
||||
|
||||
@@ -329,7 +334,7 @@ describe 'OrderCycle services', ->
|
||||
inject ($injector, _$httpBackend_)->
|
||||
Enterprise = $injector.get('Enterprise')
|
||||
$httpBackend = _$httpBackend_
|
||||
$httpBackend.whenGET('/admin/enterprises/for_order_cycle.json').respond [
|
||||
$httpBackend.whenGET('/admin/enterprises/for_order_cycle.json?').respond [
|
||||
{id: 1, name: 'One', supplied_products: [1, 2]}
|
||||
{id: 2, name: 'Two', supplied_products: [3, 4]}
|
||||
{id: 3, name: 'Three', supplied_products: [5, 6]}
|
||||
@@ -395,7 +400,7 @@ describe 'OrderCycle services', ->
|
||||
inject ($injector, _$httpBackend_)->
|
||||
EnterpriseFee = $injector.get('EnterpriseFee')
|
||||
$httpBackend = _$httpBackend_
|
||||
$httpBackend.whenGET('/admin/enterprise_fees.json').respond [
|
||||
$httpBackend.whenGET('/admin/enterprise_fees/for_order_cycle.json?').respond [
|
||||
{id: 1, name: "Yayfee", enterprise_id: 1}
|
||||
{id: 2, name: "FeeTwo", enterprise_id: 2}
|
||||
]
|
||||
@@ -449,12 +454,15 @@ describe 'OrderCycle services', ->
|
||||
{sender_id: 1, receiver_id: 456, incoming: true}
|
||||
{sender_id: 456, receiver_id: 2, incoming: false}
|
||||
]
|
||||
$httpBackend.whenGET('/admin/order_cycles/new.json').respond
|
||||
id: 123
|
||||
name: 'New Order Cycle'
|
||||
coordinator_id: 456
|
||||
coordinator_fees: []
|
||||
exchanges: []
|
||||
|
||||
it 'initialises order cycle', ->
|
||||
expect(OrderCycle.order_cycle).toEqual
|
||||
incoming_exchanges: []
|
||||
outgoing_exchanges: []
|
||||
coordinator_fees: []
|
||||
expect(OrderCycle.order_cycle).toEqual {}
|
||||
|
||||
it 'counts selected variants in an exchange', ->
|
||||
result = OrderCycle.exchangeSelectedVariants({variants: {1: true, 2: false, 3: true}})
|
||||
@@ -494,14 +502,32 @@ describe 'OrderCycle services', ->
|
||||
expect(exchange.showProducts).toEqual(true)
|
||||
|
||||
describe "setting exchange variants", ->
|
||||
it "sets all variants to the provided value", ->
|
||||
exchange = {variants: {2: false}}
|
||||
OrderCycle.setExchangeVariants(exchange, [1, 2, 3], true)
|
||||
expect(exchange.variants).toEqual {1: true, 2: true, 3: true}
|
||||
describe "when I have permissions to edit the variants", ->
|
||||
beforeEach ->
|
||||
OrderCycle.order_cycle["editable_variants_for_outgoing_exchanges"] = { 1: [1, 2, 3] }
|
||||
|
||||
it "sets all variants to the provided value", ->
|
||||
exchange = { enterprise_id: 1, incoming: false, variants: {2: false}}
|
||||
OrderCycle.setExchangeVariants(exchange, [1, 2, 3], true)
|
||||
expect(exchange.variants).toEqual {1: true, 2: true, 3: true}
|
||||
|
||||
describe "when I don't have permissions to edit the variants", ->
|
||||
beforeEach ->
|
||||
OrderCycle.order_cycle["editable_variants_for_outgoing_exchanges"] = { 1: [] }
|
||||
|
||||
it "does not change variants to the provided value", ->
|
||||
exchange = { enterprise_id: 1, incoming: false, variants: {2: false}}
|
||||
OrderCycle.setExchangeVariants(exchange, [1, 2, 3], true)
|
||||
expect(exchange.variants).toEqual {2: false}
|
||||
|
||||
describe 'adding suppliers', ->
|
||||
exchange = null
|
||||
|
||||
beforeEach ->
|
||||
# Initialise OC
|
||||
OrderCycle.new()
|
||||
$httpBackend.flush()
|
||||
|
||||
it 'adds the supplier to incoming exchanges', ->
|
||||
OrderCycle.addSupplier('123')
|
||||
expect(OrderCycle.order_cycle.incoming_exchanges).toEqual [
|
||||
@@ -511,6 +537,11 @@ describe 'OrderCycle services', ->
|
||||
describe 'adding distributors', ->
|
||||
exchange = null
|
||||
|
||||
beforeEach ->
|
||||
# Initialise OC
|
||||
OrderCycle.new()
|
||||
$httpBackend.flush()
|
||||
|
||||
it 'adds the distributor to outgoing exchanges', ->
|
||||
OrderCycle.addDistributor('123')
|
||||
expect(OrderCycle.order_cycle.outgoing_exchanges).toEqual [
|
||||
@@ -558,6 +589,9 @@ describe 'OrderCycle services', ->
|
||||
expect(OrderCycle.removeDistributionOfVariant).not.toHaveBeenCalled()
|
||||
|
||||
it 'adds coordinator fees', ->
|
||||
# Initialise OC
|
||||
OrderCycle.new()
|
||||
$httpBackend.flush()
|
||||
OrderCycle.addCoordinatorFee()
|
||||
expect(OrderCycle.order_cycle.coordinator_fees).toEqual [{}]
|
||||
|
||||
@@ -679,7 +713,25 @@ describe 'OrderCycle services', ->
|
||||
$httpBackend.flush()
|
||||
expect(OrderCycle.loaded).toBe(true)
|
||||
|
||||
describe 'loading an order cycle', ->
|
||||
describe 'loading a new order cycle', ->
|
||||
beforeEach ->
|
||||
OrderCycle.new()
|
||||
$httpBackend.flush()
|
||||
|
||||
|
||||
it 'loads basic fields', ->
|
||||
expect(OrderCycle.order_cycle.id).toEqual(123)
|
||||
expect(OrderCycle.order_cycle.name).toEqual('New Order Cycle')
|
||||
expect(OrderCycle.order_cycle.coordinator_id).toEqual(456)
|
||||
|
||||
it 'initialises the incoming and outgoing exchanges', ->
|
||||
expect(OrderCycle.order_cycle.incoming_exchanges).toEqual []
|
||||
expect(OrderCycle.order_cycle.outgoing_exchanges).toEqual []
|
||||
|
||||
it 'removes the original exchanges array', ->
|
||||
expect(OrderCycle.order_cycle.exchanges).toBeUndefined()
|
||||
|
||||
describe 'loading an existing order cycle', ->
|
||||
beforeEach ->
|
||||
OrderCycle.load('123')
|
||||
$httpBackend.flush()
|
||||
@@ -704,8 +756,8 @@ describe 'OrderCycle services', ->
|
||||
active: true
|
||||
]
|
||||
|
||||
it 'removes original exchanges array', ->
|
||||
expect(OrderCycle.order_cycle.exchanges).toEqual(undefined)
|
||||
it 'removes the original exchanges array', ->
|
||||
expect(OrderCycle.order_cycle.exchanges).toBeUndefined()
|
||||
|
||||
describe 'creating an order cycle', ->
|
||||
it 'redirects to the order cycles page on success', ->
|
||||
|
||||
Reference in New Issue
Block a user