<commit_before>require File.join(File.dirname(__FILE__), 'helper')

class TestCheddargetterClientRuby < Test::Unit::TestCase
  ERROR_CODES = { 
    1000 => "An unexpected error occured.  Please try again later.",
    1001 => "The record already exists",
    1002 => "An unexpected error occured.  Please try again later.",
    1003 => "An unexpected error occured.  Please try again later.",
    2000 => "The local gateway configuration is incompatible",
    2001 => "The configuration at the gateway is incompatible",
    2002 => "Authentication to the gateway failed",
    2003 => "The gateway has denied access",
    3000 => "The response from the gateway was not recognized",
    4000 => "The connection to the gateway failed.  Please try again later.",
    5000 => "There was an error processing the transaction",
    5001 => "Credit card number is invalid",
    5002 => "Expiration date is invalid",
    5003 => "Credit card type is not accepted",
    6000 => "The transaction was declined",
    6001 => "The transaction was declined due to AVS mismatch",
    6002 => "The transaction was declined due to card code verification failure",
    7000 => "The transaction failed for an unknown reason"
  }
  
  def free_new_user_hash(id)
    { 
      :code                 => id,
      :firstName            => "First",
      :lastName             => "Last",
      :email                => "<EMAIL>",
      :subscription => { 
        :planCode        => "FREE_PLAN_TEST",
      },
    }
  end
  
  def paid_new_user_hash(id, cc_error = nil)
    { 
      :code                 => id,
      :firstName            => "First",
      :lastName             => "Last",
      :email                => "<EMAIL>",
      :firstContactDatetime => Time.now,
      :subscription => { 
        :planCode        => "TEST_PLAN_2",
        :ccNumber        => "4111111111111111",
        :ccExpiration    => Date.parse("08/2012"),
        :ccCardCode      => "123",
        :ccFirstName     => "ccFirst",
        :ccLastName      => "ccLast",
        :ccZip           => cc_error ? cc_error : "11361"
      },
    }
  end
  
  should "check various client init exceptions" do
    assert_raises(CheddarGetter::ClientException) do
      CheddarGetter::Client.new(:product_code => "code", :password => "password")
    end
    
    assert_raises(CheddarGetter::ClientException) do
      CheddarGetter::Client.new(:product_code => "code", :username => "username")
    end
    
    assert_raises(CheddarGetter::ClientException) do
      CheddarGetter::Client.new(:username => "username", :password => "password")
    end
    
    assert_not_nil CheddarGetter::Client.new(:username => "u", :password => "p", :product_code => "c")
    assert_not_nil CheddarGetter::Client.new(:username => "u", :password => "p", :product_id => "i")
    
    cg = CheddarGetter::Client.new(:username => "username", :password => "password", :product_code => "code")
    cg.product_code = nil
    assert_raises(CheddarGetter::ClientException) { cg.get_plans }
    cg.product_code = "code"
    
    result = cg.get_plans
    assert_equal false, result.valid?
    assert_equal ["Authentication required"], result.error_messages
    
    cg.username = CG.username
    cg.password = CG.password
    result = cg.get_plans
    assert_equal false, result.valid?
    assert_equal ["User #{CGEmail} does not have access to productCode=code"], 
      result.error_messages
    
    cg.product_code = ""
    result = cg.get_plans
    assert_equal false, result.valid?
    assert_equal ["No product selected. Need a productId or productCode."], result.error_messages
    
    cg.product_code = nil
    cg.product_id = "id"
    result = cg.get_plans
    assert_equal false, result.valid?
    assert_equal ["User does not have access to productId=id"], result.error_messages
  end
  
  should "get 3 plans from cheddar getter" do
    result = CG.get_plans
    assert_equal 3, result.plans.size
    assert_equal "Free Plan Test", result.plan("FREE_PLAN_TEST")[:name]
    assert_equal "Test Plan 2", result.plan("TEST_PLAN_2")[:name]
    assert_equal "Test Plan 1", result.plan("TEST_PLAN_1")[:name]
    assert_equal nil, result.plan("NOT_A_PLAN")
    assert_equal 2, result.plan_items("TEST_PLAN_1").count
    assert_equal "Test Item 1", result.plan_item("TEST_ITEM_1", "TEST_PLAN_1")[:name]
    assert_equal "Test Item 2", result.plan_item("TEST_ITEM_2", "TEST_PLAN_1")[:name]
    assert_raises(CheddarGetter::ResponseException){ result.plan }
    assert_raises(CheddarGetter::ResponseException){ result.plan_items }
    assert_raises(CheddarGetter::ResponseException){ result.plan_item }
    assert_raises(CheddarGetter::ResponseException){ result.plan_item("TEST_ITEM_1") }
    assert_raises(CheddarGetter::ResponseException){ result.customer }
    assert_equal true, result.valid?
  end
  
  should "get a single plan from cheddar getter" do
    assert_raises(CheddarGetter::ClientException){ CG.get_plan }
    result = CG.get_plan(:code => "FREE_PLAN_TEST")
    assert_equal 1, result.plans.size
    assert_equal "Free Plan Test", result.plan("FREE_PLAN_TEST")[:name]
    assert_equal nil, result.plan("TEST_PLAN_2")
    assert_equal nil, result.plan("TEST_PLAN_1")
    assert_equal nil, result.plan("NOT_A_PLAN")
    assert_equal 2, result.plan_items.count
    assert_equal nil, result.plan_items("TEST_PLAN_1")
    assert_equal "Test Item 1", result.plan_item("TEST_ITEM_1")[:name]
    assert_equal "Test Item 2", result.plan_item("TEST_ITEM_2")[:name]
    assert_raises(CheddarGetter::ResponseException){ result.plan_item }
    assert_raises(CheddarGetter::ResponseException){ result.customer }
    assert_equal true, result.valid?
    
    result = CG.get_plan(:id => "fe96b9e6-53a2-102e-b098-40402145ee8b")
    assert_equal 1, result.plans.size
    assert_equal "Free Plan Test", result.plan("FREE_PLAN_TEST")[:name]
    assert_equal true, result.valid?
    
    result = CG.get_plan(:code => "NOT_A_PLAN")
    assert_equal false, result.valid?
    assert_equal ["Plan not found for code=NOT_A_PLAN within productCode=GEM_TEST"], result.error_messages
  end
  <commit_msg>Fixing the plan data to work with testing account.<commit_after>require File.join(File.dirname(__FILE__), 'helper')

class TestCheddargetterClientRuby < Test::Unit::TestCase
  ERROR_CODES = { 
    1000 => "An unexpected error occured.  Please try again later.",
    1001 => "The record already exists",
    1002 => "An unexpected error occured.  Please try again later.",
    1003 => "An unexpected error occured.  Please try again later.",
    2000 => "The local gateway configuration is incompatible",
    2001 => "The configuration at the gateway is incompatible",
    2002 => "Authentication to the gateway failed",
    2003 => "The gateway has denied access",
    3000 => "The response from the gateway was not recognized",
    4000 => "The connection to the gateway failed.  Please try again later.",
    5000 => "There was an error processing the transaction",
    5001 => "Credit card number is invalid",
    5002 => "Expiration date is invalid",
    5003 => "Credit card type is not accepted",
    6000 => "The transaction was declined",
    6001 => "The transaction was declined due to AVS mismatch",
    6002 => "The transaction was declined due to card code verification failure",
    7000 => "The transaction failed for an unknown reason"
  }
  
  def free_new_user_hash(id)
    { 
      :code                 => id,
      :firstName            => "First",
      :lastName             => "Last",
      :email                => "<EMAIL>",
      :subscription => { 
        :planCode        => "FREE_PLAN_TEST",
      },
    }
  end
  
  def paid_new_user_hash(id, cc_error = nil)
    { 
      :code                 => id,
      :firstName            => "First",
      :lastName             => "Last",
      :email                => "<EMAIL>",
      :firstContactDatetime => Time.now,
      :subscription => { 
        :planCode        => "TEST_PLAN_2",
        :ccNumber        => "4111111111111111",
        :ccExpiration    => Date.parse("08/2012"),
        :ccCardCode      => "123",
        :ccFirstName     => "ccFirst",
        :ccLastName      => "ccLast",
        :ccZip           => cc_error ? cc_error : "11361"
      },
    }
  end
  
  should "check various client init exceptions" do
    assert_raises(CheddarGetter::ClientException) do
      CheddarGetter::Client.new(:product_code => "code", :password => "password")
    end
    
    assert_raises(CheddarGetter::ClientException) do
      CheddarGetter::Client.new(:product_code => "code", :username => "username")
    end
    
    assert_raises(CheddarGetter::ClientException) do
      CheddarGetter::Client.new(:username => "username", :password => "password")
    end
    
    assert_not_nil CheddarGetter::Client.new(:username => "u", :password => "p", :product_code => "c")
    assert_not_nil CheddarGetter::Client.new(:username => "u", :password => "p", :product_id => "i")
    
    cg = CheddarGetter::Client.new(:username => "username", :password => "password", :product_code => "code")
    cg.product_code = nil
    assert_raises(CheddarGetter::ClientException) { cg.get_plans }
    cg.product_code = "code"
    
    result = cg.get_plans
    assert_equal false, result.valid?
    assert_equal ["Authentication required"], result.error_messages
    
    cg.username = CG.username
    cg.password = <PASSWORD>
    result = cg.get_plans
    assert_equal false, result.valid?
    assert_equal ["User #{CGEmail} does not have access to productCode=code"], 
      result.error_messages
    
    cg.product_code = ""
    result = cg.get_plans
    assert_equal false, result.valid?
    assert_equal ["No product selected. Need a productId or productCode."], result.error_messages
    
    cg.product_code = nil
    cg.product_id = "id"
    result = cg.get_plans
    assert_equal false, result.valid?
    assert_equal ["User does not have access to productId=id"], result.error_messages
  end
  
  should "get 3 plans from cheddar getter" do
    result = CG.get_plans
    assert_equal 3, result.plans.size
    assert_equal "Free Plan Test", result.plan("FREE_PLAN_TEST")[:name]
    assert_equal "Test Plan 2", result.plan("TEST_PLAN_2")[:name]
    assert_equal "Test Plan 1", result.plan("TEST_PLAN_1")[:name]
    assert_equal nil, result.plan("NOT_A_PLAN")
    assert_equal 2, result.plan_items("TEST_PLAN_1").count
    assert_equal "Test Item 1", result.plan_item("TEST_ITEM_1", "TEST_PLAN_1")[:name]
    assert_equal "Test Item 2", result.plan_item("TEST_ITEM_2", "TEST_PLAN_1")[:name]
    assert_raises(CheddarGetter::ResponseException){ result.plan }
    assert_raises(CheddarGetter::ResponseException){ result.plan_items }
    assert_raises(CheddarGetter::ResponseException){ result.plan_item }
    assert_raises(CheddarGetter::ResponseException){ result.plan_item("TEST_ITEM_1") }
    assert_raises(CheddarGetter::ResponseException){ result.customer }
    assert_equal true, result.valid?
  end
  
  should "get a single plan from cheddar getter" do
    assert_raises(CheddarGetter::ClientException){ CG.get_plan }
    result = CG.get_plan(:code => "FREE_PLAN_TEST")
    assert_equal 1, result.plans.size
    assert_equal "Free Plan Test", result.plan("FREE_PLAN_TEST")[:name]
    assert_equal nil, result.plan("TEST_PLAN_2")
    assert_equal nil, result.plan("TEST_PLAN_1")
    assert_equal nil, result.plan("NOT_A_PLAN")
    assert_equal 2, result.plan_items.count
    assert_equal nil, result.plan_items("TEST_PLAN_1")
    assert_equal "Test Item 1", result.plan_item("TEST_ITEM_1")[:name]
    assert_equal "Test Item 2", result.plan_item("TEST_ITEM_2")[:name]
    assert_raises(CheddarGetter::ResponseException){ result.plan_item }
    assert_raises(CheddarGetter::ResponseException){ result.customer }
    assert_equal true, result.valid?
    
    result = CG.get_plan(:id => "a6a816c8-6d14-11e0-bcd4-40406799fa1e")
    assert_equal 1, result.plans.size
    assert_equal "Free Plan Test", result.plan("FREE_PLAN_TEST")[:name]
    assert_equal true, result.valid?
    
    result = CG.get_plan(:code => "NOT_A_PLAN")
    assert_equal false, result.valid?
    assert_equal ["Plan not found for code=NOT_A_PLAN within productCode=RUBYGEM"], result.error_messages
  end
  
{'fraction_non_alphanumeric': 0.11823141437993649, 'fraction_numerical': 0.024346551583747253, 'mean_word_length': 3.341463414634146, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 118, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3854844', 'n_tokens_mistral': 4029, 'n_tokens_neox': 3819, 'n_words': 914}