Sha256: ca2d0377f90c9b7c434de91cc6d6eab891834f279e4bda309cc8b5d3b2c3317a

Contents?: true

Size: 1.94 KB

Versions: 62

Compression:

Stored size: 1.94 KB

Contents

require 'test_helper'

module Workarea
  class Payment
    module Authorize
      class StoreCreditTest < TestCase
        def profile
          @profile ||= create_payment_profile(store_credit: 15.to_m)
        end

        def payment
          @payment ||= create_payment(profile: profile)
        end

        def tender
          @tender ||= begin
            payment.set_store_credit
            payment.store_credit
          end
        end

        def test_complete!
          transaction = tender.build_transaction(amount: 5.to_m)
          operation = StoreCredit.new(tender, transaction)

          operation.complete!
          profile.reload

          assert_equal(10.to_m, profile.store_credit)
          assert(transaction.success?)
          assert_equal(
            ActiveMerchant::Billing::Response,
            transaction.response.class
          )
          assert_equal('purchase', transaction.action)

          transaction = tender.build_transaction(amount: 100.to_m)
          operation = StoreCredit.new(tender, transaction)

          operation.complete!
          refute(transaction.success?)
          assert(transaction.response)
          assert_equal(
            ActiveMerchant::Billing::Response,
            transaction.response.class
          )
        end

        def test_cancel!
          transaction = tender.build_transaction(amount: 5.to_m, success: false)
          operation = StoreCredit.new(tender, transaction)

          operation.cancel!
          profile.reload

          assert_equal(15.to_m, profile.store_credit)

          transaction = tender.build_transaction(amount: 5.to_m, success: true)
          operation = StoreCredit.new(tender, transaction)

          operation.cancel!
          profile.reload

          assert_equal(20.to_m, profile.store_credit)
          assert_equal(
            ActiveMerchant::Billing::Response,
            transaction.cancellation.class
          )
        end
      end
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-core-3.4.27 test/models/workarea/payment/authorize/store_credit_test.rb
workarea-core-3.5.4 test/models/workarea/payment/authorize/store_credit_test.rb
workarea-core-3.4.26 test/models/workarea/payment/authorize/store_credit_test.rb
workarea-core-3.5.3 test/models/workarea/payment/authorize/store_credit_test.rb
workarea-core-3.4.25 test/models/workarea/payment/authorize/store_credit_test.rb
workarea-core-3.5.2 test/models/workarea/payment/authorize/store_credit_test.rb
workarea-core-3.4.24 test/models/workarea/payment/authorize/store_credit_test.rb
workarea-core-3.5.1 test/models/workarea/payment/authorize/store_credit_test.rb
workarea-core-3.4.23 test/models/workarea/payment/authorize/store_credit_test.rb
workarea-core-3.4.22 test/models/workarea/payment/authorize/store_credit_test.rb
workarea-core-3.5.0 test/models/workarea/payment/authorize/store_credit_test.rb
workarea-core-3.4.21 test/models/workarea/payment/authorize/store_credit_test.rb
workarea-core-3.5.0.beta.1 test/models/workarea/payment/authorize/store_credit_test.rb
workarea-core-3.4.20 test/models/workarea/payment/authorize/store_credit_test.rb
workarea-core-3.4.19 test/models/workarea/payment/authorize/store_credit_test.rb
workarea-core-3.4.18 test/models/workarea/payment/authorize/store_credit_test.rb
workarea-core-3.4.17 test/models/workarea/payment/authorize/store_credit_test.rb
workarea-core-3.4.16 test/models/workarea/payment/authorize/store_credit_test.rb
workarea-core-3.4.15 test/models/workarea/payment/authorize/store_credit_test.rb
workarea-core-3.4.14 test/models/workarea/payment/authorize/store_credit_test.rb