test/razorpay/test_refund.rb in razorpay-1.2.1 vs test/razorpay/test_refund.rb in razorpay-2.0.0
- old
+ new
@@ -1,31 +1,42 @@
require 'test_helper'
-require 'razorpay/payment'
-require 'razorpay/refund'
module Razorpay
# Tests for Razorpay::Refund
class RazorpayRefundTest < Minitest::Test
def setup
@payment_id = 'fake_payment_id'
- stub_get(%r{payments\/#{Regexp.quote(@payment_id)}$}, 'fake_payment')
+ stub_get(%r{payments/#{@payment_id}$}, 'fake_payment')
+ @refund_id = 'fake_refund_id'
+ stub_get(%r{refunds/#{@refund_id}$}, 'fake_refund')
end
def test_refund_should_be_defined
refute_nil Razorpay::Refund
end
+ def test_fetch_all_refunds_for_payment
+ stub_get(%r{payments/#{@payment_id}/refunds$}, 'refund_collection_for_payment')
+ refunds = Razorpay::Payment.fetch(@payment_id).refunds
+ assert_instance_of Razorpay::Collection, refunds
+ end
+
def test_fetch_all_refunds
- stub_get(%r{payments/#{@payment_id}/refunds$}, 'refund_collection')
- refunds = Razorpay::Payment.fetch(@payment_id).refunds.all
+ stub_get(/refunds$/, 'refund_collection')
+ refunds = Razorpay::Refund.all
assert_instance_of Razorpay::Collection, refunds
end
def test_fetch_specific_refund
- refund_id = 'fake_refund_id'
- stub_get(%r{payments/#{@payment_id}/refunds/#{refund_id}$}, 'fake_refund')
- refund = Razorpay::Payment.fetch(@payment_id).refunds.fetch('fake_refund_id')
+ refund = Razorpay::Refund.fetch(@refund_id)
assert_instance_of Razorpay::Refund, refund
- assert_equal refund.id, refund_id
+ assert_equal refund.id, @refund_id
+ end
+
+ def test_create_refund
+ stub_post(/refunds$/, 'fake_refund', "payment_id=#{@payment_id}")
+ refund = Razorpay::Refund.create(payment_id: @payment_id)
+ assert_instance_of Razorpay::Refund, refund
+ assert_equal refund.payment_id, @payment_id
end
end
end