mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-26 20:56:48 +00:00
30 lines
773 B
Ruby
30 lines
773 B
Ruby
# frozen_string_literal: true
|
|
|
|
require 'spec_helper'
|
|
|
|
RSpec.describe Checkout::PaymentMethodFetcher do
|
|
let!(:order) { create(:completed_order_with_totals) }
|
|
let(:payment1) { build(:payment, order:) }
|
|
let(:payment2) { build(:payment, order:) }
|
|
let(:service) { Checkout::PaymentMethodFetcher.new(order) }
|
|
|
|
describe '#call' do
|
|
context "when the order has payments" do
|
|
before do
|
|
order.payments << payment1
|
|
order.payments << payment2
|
|
end
|
|
|
|
it "returns the payment_method of the most recently created payment" do
|
|
expect(service.call).to eq payment2.payment_method
|
|
end
|
|
end
|
|
|
|
context "when the order has no payments" do
|
|
it "returns nil" do
|
|
expect(service.call).to be_nil
|
|
end
|
|
end
|
|
end
|
|
end
|