Sha256: c395c69c564a5febc825e560475c59f845dd367a54598bb88ff4dbabfa7130a0

Contents?: true

Size: 1.76 KB

Versions: 3

Compression:

Stored size: 1.76 KB

Contents

require "spec_helper"

describe Spree::BankTransfer, type: :model do
  subject { described_class.new }

  describe "#actions" do
    it { expect(subject.actions).to eq ["capture", "void"] }
  end

  describe "#can_capture?" do
    let(:payment) { double(Spree::Payment, state: state) }

    before do
      allow(subject).to receive(:payment) { payment }
    end

    context "when payment state is not checkout or pending" do
      let(:state) { "void" }

      it { expect(subject.can_capture?(payment)).to be_falsy }
    end

    context "when payment state is pending" do
      let(:payment) { double(Spree::Payment, state: state, source: source) }
      let(:state) { "pending" }
      let(:source) { double(Spree::BankTransfer, expires_at: expires_at) }

      before do
        allow(subject).to receive(:payment) { payment }
      end

      context "when expires_at is tomorrow" do
        let(:expires_at) { Date.tomorrow }

        it { expect(subject.can_capture?(payment)).to be_truthy }
      end

      context "when expires_at is yesterday" do
        let(:expires_at) { Date.yesterday}

        it { expect(subject.can_capture?(payment)).to be_falsy }
      end
    end
  end

  describe "#can_void?" do
    let(:payment) { double(Spree::Payment, state: state) }

    before do
      allow(subject).to receive(:payment) { payment }
    end

    context "when payment state is void" do
      let(:state) { "void" }

      it { expect(subject.can_void?(payment)).to be_falsy }
    end

    context "when payment state is pending" do
      let(:state) { "pending" }

      it { expect(subject.can_void?(payment)).to be_truthy }
    end
  end

  describe "#instructions_partial_path" do
    it { expect(subject.instructions_partial_path).to eq "spree/orders/bank_transfer" }
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
spree_komoju-0.0.5 spec/models/spree/bank_transfer_spec.rb
spree_komoju-0.0.4 spec/models/spree/bank_transfer_spec.rb
spree_komoju-0.0.3 spec/models/spree/bank_transfer_spec.rb