Files
openfoodnetwork/spec/services/variant_overrides_indexed_spec.rb
2024-05-09 12:24:41 +10:00

64 lines
1.8 KiB
Ruby

# frozen_string_literal: true
require 'spec_helper'
RSpec.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