mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-17 00:07:24 +00:00
Added spec for OrderPaymentFinder
This commit is contained in:
47
spec/services/order_payment_finder_spec.rb
Normal file
47
spec/services/order_payment_finder_spec.rb
Normal file
@@ -0,0 +1,47 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
describe OrderPaymentFinder do
|
||||
let(:order) { create(:order_with_distributor) }
|
||||
let(:finder) { OrderPaymentFinder.new(order) }
|
||||
|
||||
context "when order has several non pending payments" do
|
||||
let!(:failed_payment) { create(:payment, order: order, state: 'failed') }
|
||||
let!(:complete_payment) { create(:payment, order: order, state: 'completed') }
|
||||
|
||||
it "#last_payment returns the last payment" do
|
||||
expect(finder.last_payment).to eq complete_payment
|
||||
end
|
||||
|
||||
it "#last_pending_payment returns nil" do
|
||||
expect(finder.last_pending_payment).to be nil
|
||||
end
|
||||
end
|
||||
|
||||
context "when order has a pending payment and a non pending payment" do
|
||||
let!(:processing_payment) { create(:payment, order: order, state: 'processing') }
|
||||
let!(:failed_payment) { create(:payment, order: order, state: 'failed') }
|
||||
|
||||
it "#last_payment returns the last payment" do
|
||||
expect(finder.last_payment).to eq failed_payment
|
||||
end
|
||||
|
||||
it "#last_pending_payment returns the pending payment" do
|
||||
# a payment in the processing state is a pending payment
|
||||
expect(finder.last_pending_payment).to eq processing_payment
|
||||
end
|
||||
|
||||
context "and an extra last pending payment" do
|
||||
let!(:pending_payment) { create(:payment, order: order, state: 'pending') }
|
||||
|
||||
it "#last_payment returns the last payment" do
|
||||
expect(finder.last_payment).to eq pending_payment
|
||||
end
|
||||
|
||||
it "#last_pending_payment returns the pending payment" do
|
||||
expect(finder.last_pending_payment).to eq pending_payment
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user