Sha256: 009c42277ba919a3560971ebfb0c9e5de2a110874ba4e03ba07391f4990050e8

Contents?: true

Size: 1.67 KB

Versions: 3

Compression:

Stored size: 1.67 KB

Contents

require 'spec_helper'

describe Spree::PagseguroCheckout do
  subject { described_class.new transaction_id: '1223' }

  ORDER_ID = 1
  STATUS_PAID = 3
  STATUS_CANCELLED = 7

  context '#process' do
    let(:transaction) { double('transaction').as_null_object }
    let(:status_paid) { PagSeguro::PaymentStatus.new STATUS_PAID}
    let(:status_cancelled) { PagSeguro::PaymentStatus.new STATUS_CANCELLED }
    let(:order) { double('order').as_null_object }
    let(:payment) { double('payment').as_null_object }

    before do
      allow(order).to receive(:id).and_return(ORDER_ID)

      allow(payment).to receive(:order).and_return(order)

      payments = [payment]
      allow(payments).to receive(:pending).and_return(payments)

      allow(subject).to receive(:payments).and_return(payments)
      allow(subject).to receive(:transaction).and_return(transaction)
    end

    context 'when valid' do
      before { allow(transaction).to receive(:reference).and_return(ORDER_ID) }

      it 'completes payment' do
        allow(transaction).to receive(:status).and_return(status_paid)

        expect(payment).to receive(:complete!)

        subject.process!
      end

      it 'voids payment' do
        allow(transaction).to receive(:status).and_return(status_cancelled)

        expect(payment).to receive(:failure)
        expect(order).to receive(:cancel!)

        subject.process!
      end
    end

    context 'when invalid' do
      it 'raises an error when id of the order is not the same in the reference transaction' do
        allow(transaction).to receive(:reference).and_return(2)

        expect {
          subject.process!
        }.to raise_error(RuntimeError)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
solidus_pagseguro_oficial-1.1.2 spec/models/spree/pagseguro_checkout_spec.rb
solidus_pagseguro_oficial-1.1.1 spec/models/spree/pagseguro_checkout_spec.rb
solidus_pagseguro_oficial-1.1.0 spec/models/spree/pagseguro_checkout_spec.rb