Sha256: fa0f041f4a8b82b1db79fc81dd799a4948b39c9e9553100d7451b0ddd684beee

Contents?: true

Size: 1.73 KB

Versions: 8

Compression:

Stored size: 1.73 KB

Contents

require 'test_helper'
require 'webmock'

module Razorpay
  # Tests for Razorpay
  class RazorpayTest < Minitest::Test
    def setup
      Razorpay.setup('key_id', 'key_secret')
    end

    def test_razorpay_should_be_defined
      refute_nil Razorpay
    end

    def test_setup
      auth = { username: 'key_id', password: 'key_secret' }
      assert_equal auth, Razorpay.auth
    end

    def test_custom_header
      custom_headers = { 'key' => 'value' }
      stub_get(/$/, 'hello_response')
      Razorpay.headers = custom_headers
      Razorpay::Request.new('dummy').make_test_request
      user_agent = "Razorpay-Ruby/#{Razorpay::VERSION}; Ruby/#{RUBY_VERSION}"
      headers = { 'User-Agent' => user_agent, 'Authorization' => 'Basic a2V5X2lkOmtleV9zZWNyZXQ=' }
      headers = headers.merge(custom_headers)
      assert_requested :get, 'https://api.razorpay.com/',
                       headers: headers,
                       times: 1
    end

    # We make a request to the / endpoint to test SSL support
    def test_sample_request
      WebMock.allow_net_connect!
      req = Razorpay::Request.new('dummy')
      response = req.make_test_request.parsed_response
      assert_equal 'Welcome to Razorpay API.', response['message']
      WebMock.disable_net_connect!
    end

    # We mock this request
    def test_auth_header_and_user_agent
      stub_get(/$/, 'hello_response')
      Razorpay::Request.new('dummy').make_test_request
      user_agent = "Razorpay-Ruby/#{Razorpay::VERSION}; Ruby/#{RUBY_VERSION}"
      headers = { 'User-Agent' => user_agent, 'Authorization' => 'Basic a2V5X2lkOmtleV9zZWNyZXQ=' }
      assert_requested :get, 'https://api.razorpay.com/',
                       headers: headers,
                       times: 1
    end
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
razorpay-3.2.1 test/razorpay/test_razorpay.rb
razorpay-3.2.0 test/razorpay/test_razorpay.rb
razorpay-3.1.0 test/razorpay/test_razorpay.rb
razorpay-3.0.1 test/razorpay/test_razorpay.rb
razorruby-3.0.4 test/razorpay/test_razorpay.rb
razorruby-3.0.1 test/razorpay/test_razorpay.rb
razorpay-3.0.0 test/razorpay/test_razorpay.rb
razorpay-2.4.1 test/razorpay/test_razorpay.rb