Sha256: 6cee28520945368512de9839bedff7e6bd91d4f6a474b6c9bfb7ffd9932b4498

Contents?: true

Size: 1.94 KB

Versions: 8

Compression:

Stored size: 1.94 KB

Contents

require 'test_helper'

module Razorpay
  # Tests for Razorpay::QrCode
  class RazorpayQrCodeTest < Minitest::Test
    def setup
      @qrcode_id = 'qr_HMsVL8HOpbMcjU'
      @customer_id = 'cust_HKsR5se84c5LTO'
      # Any request that ends with qrcode/qrcode_id
      stub_get(%r{payments/qr_codes/#{@qrcode_id}$}, 'fake_qrcode')
      stub_get(%r{payments/qr_codes$}, 'qrcode_collection')
    end

    def test_qrcode_should_be_defined
      refute_nil Razorpay::QrCode
    end

    def test_qrcode_should_be_created
      para_attr = {
        "type": "upi_qr",
        "name": "Store_1",
        "usage": "single_use",
        "fixed_amount": true,
        "payment_amount": 300,
        "description": "For Store 1",
        "customer_id": "cust_HKsR5se84c5LTO",
        "close_by": 1681615838,
        "notes": {
          "purpose": "Test UPI QR code notes"
        }
      }  
      stub_post(%r{/payments/qr_codes$}, 'fake_qrcode', para_attr.to_json)
      qr_code = Razorpay::QrCode.create(para_attr.to_json)

       assert_equal @qrcode_id, qr_code.id
       assert_equal @customer_id, qr_code.customer_id
    end

    def test_fetch_all_qcode
      qr_code = Razorpay::QrCode.all
      assert_instance_of Razorpay::Collection, qr_code
    end

    def test_fetch_specific_qrcode
      qr_code = Razorpay::QrCode.fetch(@qrcode_id)
      assert_instance_of Razorpay::QrCode, qr_code
      assert_equal qr_code.id, @qrcode_id
    end

    def test_qrcode_close
      stub_post(%r{payments/qr_codes/#{@qrcode_id}/close$}, 'fake_qrcode_close',{})  
      qr_code = Razorpay::QrCode.fetch(@qrcode_id).close
      assert_instance_of Razorpay::QrCode, qr_code
      assert_equal qr_code.id, @qrcode_id
    end

    def test_qrcode_fetch_payments
      stub_get(%r{payments/qr_codes/#{@qrcode_id}/payments$}, 'qrcode_payments_collection',{})  
      qr_code = Razorpay::QrCode.fetch(@qrcode_id).fetch_payments()
      assert_instance_of Razorpay::Collection, qr_code
    end
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
razorpay-3.2.2 test/razorpay/test_qr_code.rb
razorpay-3.2.1 test/razorpay/test_qr_code.rb
razorpay-3.2.0 test/razorpay/test_qr_code.rb
razorpay-3.1.0 test/razorpay/test_qr_code.rb
razorpay-3.0.1 test/razorpay/test_qr_code.rb
razorruby-3.0.4 test/razorpay/test_qr_code.rb
razorruby-3.0.1 test/razorpay/test_qr_code.rb
razorpay-3.0.0 test/razorpay/test_qr_code.rb