require 'test_helper'

class ProvidersTest < ActiveSupport::TestCase
  test 'create instance with :atnd' do
    assert_instance_of Providers::Atnd, Providers.new(:atnd)
  end

  test 'create instance with :connpass' do
    assert_instance_of Providers::Connpass, Providers.new(:connpass)
  end

  test 'create instance with :door_keeper' do
    assert_instance_of Providers::DoorKeeper, Providers.new(:door_keeper)
  end

  test 'create instance with :zusaar' do
    assert_instance_of Providers::Zusaar, Providers.new(:zusaar)
  end

  test '.names valid values' do
    assert_empty Providers.names - %w(atnd connpass door_keeper zusaar)
  end

  test '.enabled_names with `Configuration.provider`' do
    assert_empty Providers.enabled_names - %w(connpass door_keeper zusaar)
  end

  test '.enabled_names with `.names`' do
    raise if Configuration.respond_to?(:providers?)
    Configuration.define_singleton_method :providers? do
      false
    end
    assert_empty Providers.enabled_names - %w(atnd connpass door_keeper zusaar)
    (class << Configuration; self; end).send(:remove_method, :providers?)
  end

  test '.[] with valid name' do
    assert_equal Providers[:connpass], Providers::Connpass
    assert_equal Providers[:door_keeper], Providers::DoorKeeper
    assert_equal Providers[:zusaar], Providers::Zusaar
  end

  test '.[] with invalid name' do
    e1 = assert_raise NameError do
      Providers[:base]
    end
    assert_equal e1.message, "Disabled provider 'base'"
    e2 = assert_raise NameError do
      Providers[:atnd]
    end
    assert_equal e2.message, "Disabled provider 'atnd'"
  end

  test '.instances' do
    Providers.stub(:enabled_names, %w(connpass zusaar)) do
      assert_empty Providers.instances.map{|instance| instance.class } - [Providers::Connpass, Providers::Zusaar]
    end
  end
end

Create test for `Providers` module
Create test for `Providers` module
