Sha256: 9284e62aef4780a0f601c8a043ecdf94f9909e7346eaf9d799aa915e6e6dc682

Contents?: true

Size: 1.78 KB

Versions: 4

Compression:

Stored size: 1.78 KB

Contents

require 'test_helper'

class Salesforce::AuthenticationTest < ActiveSupport::TestCase
  def test_session_id__exists
    Salesforce.configure do
      username "username"
      password "password"
    end
    Salesforce::Authentication.expects(:generate_new_session_id).never
    Salesforce::Config.instance.session_id "existingsessionid"
    assert_equal "existingsessionid", Salesforce::Authentication.session_id
  end
  
  def test_session_id__doesnotexist
    Salesforce.configure do
      username "username"
      password "password"
    end
    Salesforce::Authentication.expects(:generate_new_session_id).returns("new_session_id")
    assert_equal "new_session_id", Salesforce::Authentication.session_id
  end
  
  def test_session_id__credentials_missing
    Salesforce::Authentication.expects(:generate_new_session_id).never
    assert_raises Salesforce::InvalidCredentials do
      Salesforce::Authentication.session_id
    end
  end
  
  def test_logout
    Salesforce::Config.instance.session_id = "session_id"
    Salesforce::Authentication.logout
    assert_equal nil, Salesforce::Config.session_id
  end
    
  def test_generate_new_session_id__calls_connection_login
    result = {
      :session_id => "session_id",
      :server_url => "https://cs99-api.salesforce.com/services/Soap/c/22.0/00DQ00000001LRX",
      :user_id    => "user_id"
    }

    Salesforce.connection.expects(:login).returns(result)

    assert_equal "session_id", Salesforce::Authentication.generate_new_session_id
    assert_equal "https://cs99-api.salesforce.com/services/Soap/c/22.0/00DQ00000001LRX", Salesforce::Config.soap_endpoint_url
    assert_equal "session_id", Salesforce::Config.session_id
    assert_equal "cs99", Salesforce::Config.server_instance
    assert_equal "user_id", Salesforce::Config.user_id
  end
  
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
activeforce-1.7.1 test/salesforce/authentication_test.rb
activeforce-1.7.0 test/salesforce/authentication_test.rb
activeforce-1.6.0 test/salesforce/authentication_test.rb
activeforce-1.5.0 test/salesforce/authentication_test.rb