mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Test OrderCycleHelper with real data, not mocks
It's more realistic and doesn't break with the next change.
This commit is contained in:
@@ -94,24 +94,27 @@ describe OrderCyclesHelper, type: :helper do
|
||||
end
|
||||
|
||||
describe "distibutors that have editable shipping/payment methods" do
|
||||
let(:result) {
|
||||
helper.distributors_with_editable_shipping_and_payment_methods(order_cycle)
|
||||
}
|
||||
let(:order_cycle) {
|
||||
create(
|
||||
:simple_order_cycle,
|
||||
coordinator:, suppliers: [supplier], distributors: [hub1, hub2],
|
||||
)
|
||||
}
|
||||
let(:hub1) { create(:distributor_enterprise, name: 'hub1') }
|
||||
let(:hub2) { create(:distributor_enterprise, name: 'hub2') }
|
||||
let(:supplier){ create(:supplier_enterprise, name: 'supplier') }
|
||||
let(:coordinator){ create(:distributor_enterprise, name: 'coordinator') }
|
||||
|
||||
before do
|
||||
allow(oc).to receive(:coordinator).and_return coordinator
|
||||
allow(oc).to receive(:suppliers).and_return [supplier]
|
||||
allow(oc).to receive(:distributors).and_return [hub1, hub2]
|
||||
end
|
||||
|
||||
context 'current user is a coordinator' do
|
||||
before do
|
||||
allow(helper).to receive(:spree_current_user).and_return coordinator.owner
|
||||
end
|
||||
|
||||
it 'returns all distributors' do
|
||||
expect(helper.distributors_with_editable_shipping_and_payment_methods(oc)).to eq [hub1, hub2]
|
||||
expect(result).to match_array [hub1, hub2]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -121,7 +124,7 @@ describe OrderCyclesHelper, type: :helper do
|
||||
end
|
||||
|
||||
it "doesn't return any distributors" do
|
||||
expect(helper.distributors_with_editable_shipping_and_payment_methods(oc)).to eq []
|
||||
expect(result).to eq []
|
||||
end
|
||||
end
|
||||
|
||||
@@ -131,7 +134,7 @@ describe OrderCyclesHelper, type: :helper do
|
||||
end
|
||||
|
||||
it "returns only the hubs of the current user" do
|
||||
expect(helper.distributors_with_editable_shipping_and_payment_methods(oc)).to eq [hub1]
|
||||
expect(result).to eq [hub1]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user