mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-26 20:56:48 +00:00
27 lines
1.0 KiB
Ruby
27 lines
1.0 KiB
Ruby
require 'open_food_network/order_cycle_permissions'
|
|
|
|
describe Api::Admin::ExchangeSerializer do
|
|
let(:v1) { create(:variant) }
|
|
let(:v2) { create(:variant) }
|
|
let(:exchange) { create(:exchange, incoming: false, variants: [v1, v2]) }
|
|
let(:permissions_mock) { double(:permissions) }
|
|
let(:serializer) { Api::Admin::ExchangeSerializer.new exchange }
|
|
|
|
|
|
before do
|
|
allow(OpenFoodNetwork::OrderCyclePermissions).to receive(:new) { permissions_mock }
|
|
allow(permissions_mock).to receive(:visible_variants_for_outgoing_exchanges_to) do
|
|
# This is the permitted list of variants
|
|
Spree::Variant.where(id: [v1] )
|
|
end
|
|
end
|
|
|
|
it "filters variants within the exchange based on permissions" do
|
|
visible_variants = serializer.variants
|
|
expect(permissions_mock).to have_received(:visible_variants_for_outgoing_exchanges_to).with(exchange.receiver)
|
|
expect(exchange.variants).to include v1, v2
|
|
expect(visible_variants.keys).to include v1.id
|
|
expect(visible_variants.keys).to_not include v2.id
|
|
end
|
|
end
|