Skip to content
This repository
tree: 34500380bc
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 96 lines (81 sloc) 3.026 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
require File.expand_path('../helpers', __FILE__)

class StandaloneTest < MiniTest::Unit::TestCase
  def setup
    @base_api ||= YAML.load_file( File.expand_path( File.dirname(__FILE__) + "/../lib/vk-ruby/api/base.yml" ))
    @ext_api ||= YAML.load_file( File.expand_path( File.dirname(__FILE__) + "/../lib/vk-ruby/api/ext.yml" ))
    @app = ::VK::Standalone.new app_id: :test_id, access_token: :test_token
  end

  def test_init_attributes
    assert_equal @app.app_id, :test_id
    assert_equal @app.access_token, :test_token
    assert_nil @app.expires_in
    assert_nil @app.logger
  end

  def test_base_methods_exists
    cycle @app, @base_api do |obj, method_name, is_group|
      assert_respond_to obj, method_name.to_sym unless is_group
    end
  end

  def test_ext_methods_exists
    cycle @app, @ext_api do |obj, method_name, is_group|
      assert_respond_to obj, method_name.to_sym unless is_group
    end
  end

  def test_base_groups_exists
    cycle @app, @base_api do |obj, method_name, is_group|
      assert_instance_of ::Transformer::Group, obj if is_group
    end
  end

  def test_ext_groups_exists
    cycle @app, @ext_api do |obj, method_name, is_group|
      assert_instance_of ::Transformer::Group, obj if is_group
    end
  end

  def test_base_groups_methods_prefix
    cycle @app, @base_api do |obj, method_name, is_group|
      assert_equal obj.instance_variable_get("@methods_prefix"), method_name if is_group
    end
  end

  def test_ext_groups_methods_prefix
    cycle @app, @ext_api do |obj, method_name, is_group|
      assert_equal obj.instance_variable_get("@methods_prefix"), method_name if is_group
    end
  end

  def test_base_post_request_params
    cycle @app, @base_api do |obj, method_name, is_group|
      unless is_group
        params = random_params.merge!(access_token: :test_token)
        assert_equal obj.method(method_name.to_sym).call(params), params.stringify
      end
    end
  end

  def test_ext_post_request_params
    cycle @app, @ext_api do |obj, method_name, is_group|
      unless is_group
        params = random_params.merge!(access_token: :test_token)
        assert_equal obj.method(method_name.to_sym).call(params), params.stringify
      end
    end
  end

  def test_base_get_request_params
    cycle @app, @base_api do |obj, method_name, is_group|
      unless is_group
        params = random_params.merge!(access_token: :test_token, verb: :get)
        assert_equal obj.method(method_name.to_sym).call(params), params.stringify
      end
    end
  end

  def test_ext_get_request_params
    @app.verb = :get

    cycle @app, @ext_api do |obj, method_name, is_group|
      unless is_group
        params = random_params.merge!(access_token: :test_token)
        assert_equal obj.method(method_name.to_sym).call(params), params.stringify
      end
    end
  end

  def test_raises_initialize
    assert_raises(RuntimeError){ ::VK::Serverside.new {} }
    assert_raises(RuntimeError){ ::VK::Serverside.new app_id: :test_id }
  end

end
Something went wrong with that request. Please try again.