Setup a test order cycle with its exchanges

This commit is contained in:
Pau Perez
2018-12-18 13:29:05 +01:00
parent 64fb230297
commit 0782907f4d

View File

@@ -23,4 +23,37 @@ describe Api::CachedEnterpriseSerializer do
expect(properties).to eq([property, different_property])
end
end
describe '#distributed_properties' do
let(:cached_enterprise_serializer) { described_class.new(shop, options) }
let(:enterprise_injection_data) do
instance_double(OpenFoodNetwork::EnterpriseInjectionData, active_distributors: [])
end
let(:options) { { data: enterprise_injection_data } }
let(:shop) { create(:distributor_enterprise, name: 'Distributor') }
let(:property) { create(:property, presentation: 'One') }
before do
producer = create(:supplier_enterprise, name: 'Supplier')
product = create(:product, supplier: producer, properties: [property])
order_cycle = build(:simple_order_cycle, coordinator: shop)
incoming_exchange = build(:exchange, sender: producer, receiver: shop, incoming: true)
outgoing_exchange = build(:exchange, sender: shop, receiver: shop, incoming: false)
outgoing_exchange.variants << product.variants.first
order_cycle.exchanges << incoming_exchange
order_cycle.exchanges << outgoing_exchange
order_cycle.save
end
it 'does not duplicate properties' do
properties = cached_enterprise_serializer.distributed_properties
expect(properties).to eq([property])
end
end
end