mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-05 22:26:07 +00:00
Do not allow re-adding exchange
This commit is contained in:
@@ -15,10 +15,12 @@ angular.module('admin.orderCycles').factory('OrderCycle', ($resource, $window, $
|
||||
parseInt(exchange.enterprise_id) for exchange in @exchangesByDirection(direction)
|
||||
|
||||
novelSupplier: (enterprise) =>
|
||||
@exchangeIds('incoming').indexOf(enterprise.id) == -1
|
||||
id = enterprise?.id || parseInt(enterprise)
|
||||
@exchangeIds('incoming').indexOf(id) == -1
|
||||
|
||||
novelDistributor: (enterprise) =>
|
||||
@exchangeIds('outgoing').indexOf(enterprise.id) == -1
|
||||
id = enterprise?.id || parseInt(enterprise)
|
||||
@exchangeIds('outgoing').indexOf(id) == -1
|
||||
|
||||
exchangeSelectedVariants: (exchange) ->
|
||||
numActiveVariants = 0
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
{{ enterprise.name }}
|
||||
= "{{ enterprise.issues_summary_#{type} ? '('+enterprise.issues_summary_#{type}+')' : '' }}"
|
||||
|
||||
= f.submit "Add #{type}", 'ng-click' => "add#{type.capitalize}($event)", 'ng-disabled' => "!new_#{type}_id"
|
||||
= f.submit "Add #{type}", 'ng-click' => "add#{type.capitalize}($event)", 'ng-disabled' => "!new_#{type}_id || !OrderCycle.novel#{type.capitalize}(new_#{type}_id)"
|
||||
|
||||
@@ -108,6 +108,8 @@ feature %q{
|
||||
|
||||
# I should not be able to re-add the supplier
|
||||
page.should_not have_select 'new_supplier_id', with_options: ['My supplier']
|
||||
page.should have_button 'Add supplier', disabled: true
|
||||
page.all("td.supplier_name").map(&:text).should == ['My supplier']
|
||||
|
||||
# And I add a supplier fee
|
||||
within("tr.supplier-#{supplier.id}") { click_button 'Add fee' }
|
||||
|
||||
@@ -489,20 +489,30 @@ describe 'OrderCycle services', ->
|
||||
expect(OrderCycle.exchangeIds('incoming')).toEqual [1, 2]
|
||||
|
||||
describe "checking for novel enterprises", ->
|
||||
it "detects novel suppliers", ->
|
||||
e1 = {id: 1}
|
||||
e2 = {id: 2}
|
||||
e1 = {id: 1}
|
||||
e2 = {id: 2}
|
||||
|
||||
beforeEach ->
|
||||
OrderCycle.order_cycle.incoming_exchanges = [{enterprise_id: 1}]
|
||||
OrderCycle.order_cycle.outgoing_exchanges = [{enterprise_id: 1}]
|
||||
|
||||
it "detects novel suppliers", ->
|
||||
expect(OrderCycle.novelSupplier(e1)).toBe false
|
||||
expect(OrderCycle.novelSupplier(e2)).toBe true
|
||||
|
||||
it "detects novel suppliers with enterprise as string id", ->
|
||||
expect(OrderCycle.novelSupplier('1')).toBe false
|
||||
expect(OrderCycle.novelSupplier('2')).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
|
||||
|
||||
it "detects novel distributors with enterprise as string id", ->
|
||||
expect(OrderCycle.novelDistributor('1')).toBe false
|
||||
expect(OrderCycle.novelDistributor('2')).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