Files
openfoodnetwork/spec/services/variant_overrides_indexed_spec.rb
Rob H dcdd3f2444 Modify interface of VariantOverridesIndexed#indexed
Stop using keyword args and accept variant_ids instead of line_items
2020-04-13 22:11:58 +10:00

62 lines
1.7 KiB
Ruby

require 'spec_helper'
describe VariantOverridesIndexed do
subject(:variant_overrides) { described_class.new([variant.id],[distributor.id]) }
let(:distributor) { create(:distributor_enterprise) }
let(:variant) { create(:variant) }
let!(:variant_override) do
create(
:variant_override,
hub: vo_distributor,
variant: vo_variant,
)
end
describe '#indexed' do
let(:result) { variant_overrides.indexed }
context 'when variant overrides exist for variants of specified variants' do
let(:vo_variant) { variant }
context 'when variant overrides apply to one of the specified distributors' do
let(:vo_distributor) { distributor }
it 'they are included in the mapping' do
expect(result).to eq(
distributor.id => { variant => variant_override }
)
end
end
context 'when variant overrides don\'t apply to one of the specified distributors' do
let(:vo_distributor) { create(:distributor_enterprise) }
it 'they are not included in the mapping' do
expect(result).to eq({})
end
end
end
context 'when variant overrides exist for other variants' do
let(:vo_variant) { create(:variant) }
context 'when variant overrides apply to one of the specified distributors' do
let(:vo_distributor) { distributor }
it 'they are not included in the mapping' do
expect(result).to eq({})
end
end
context 'when variant overrides don\'t apply to one of the specified distributors' do
let(:vo_distributor) { create(:distributor_enterprise) }
it 'they are not included in the mapping' do
expect(result).to eq({})
end
end
end
end
end