require 'test_helper'
require 'garen'

class Garen::ClientTest < Minitest::Test
  def test_set_up_client
    VCR.use_cassette 'client/valid_setup' do
      garen = Garen::Client.new(api_key: 'RGAPI-861742fa-3876-4300-a2e7-81ef6cacd15e')
      assert_equal 'RGAPI-861742fa-3876-4300-a2e7-81ef6cacd15e', garen.instance_values['api_key']
      assert_equal 'na1', garen.instance_values['service_platform']
      assert_equal :raise_error, garen.instance_values['debug']
      assert_equal 'RGAPI-861742fa-3876-4300-a2e7-81ef6cacd15e', garen.instance_values['conn'].headers['X-Riot-Token']
      assert_equal 'application/json', garen.instance_values['conn'].headers['Accept']
      assert_equal "Garen api gem #{Garen::VERSION}", garen.instance_values['conn'].headers['User-Agent']
      assert_includes garen.instance_values['conn'].url_prefix.to_s, '.api.riotgames.com/'
    end
  end

  def test_no_api_key
    assert_raises(ArgumentError, 'Riot API Key Required') { Garen::Client.new(api_key: nil) }
  end

  def test_takes_in_service_platform
    VCR.use_cassette 'client/service_platform' do
      garen = Garen::Client.new(api_key: 'RGAPI-ed14c2ae-a063-4195-a3d6-bc5ad541e191', service_platform: 'kr')
      assert_equal 'kr', garen.instance_values['service_platform']
    end
  end
end
