<commit_before>require 'test_helper'

class UltimatepayUgcTest < Test::Unit::TestCase
  def setup
    @gateway = UltimatepayUgcGateway.new(
                 :merchant_code => 'UC04',
                 :login => 'login',
                 :password => 'password',
                 :secret_phrase => '<PASSWORD>'
               )

    @authorize_options = {
      :user_id => 1,
      :username => 'shredmasterfresh',
      :ugc_pin => '99999999999'
    }
    
  end
  
  def test_valid_login?
    assert !@gateway.valid_login?('login', 'wrong')
    assert !@gateway.valid_login?('wrong', 'password')
    assert @gateway.valid_login?('login', 'password')
  end
  
  def test_successful_authorize
    @gateway.expects(:ssl_post).returns(successful_authorize_response)
    
    assert response = @gateway.authorize(@authorize_options)
    assert_instance_of Response, response
    assert_success response
    
    # Replace with authorization number from the successful response
    assert_equal 'BMhFnN4SohBrWODtHZn62GTAx3tm11SVWldvoE1Ulpc', response.authorization
    assert_equal 5.0, response.params['value']
    assert_equal 'USD', response.params['currency']
    assert response.test?
  end

  def test_unsuccessful_authorize
    @gateway.expects(:ssl_post).returns(failed_authorize_response)
    
    assert response = @gateway.authorize(@authorize_options)
    assert_instance_of Response, response
    assert_failure response
    assert response.test?
  end

  private
  
  def successful_authorize_response
    [
      'token=<KEY>',
      'result=auth',
      'status=active',
      'value=5',
      'currency=USD'
    ].join('&')
  end
  
  def failed_authorize_response
    'token=6h85pxerDfjwRMSmIAae3lXLXbkE87xjZxy9ytE1bW&result=failed&errorDetail=ugc_pin'
  end
  
  def succesful_commit_response
    "token=iONyv5B13mKRTNtuYHxvV6wUuHz8fZrt9uKcGW90dJx&result=paid"
  end

  def failed_authorize_response
    'token=6h85pxerDfjwRMSmIAae3lXLXbkE87xjZxy9ytE1bW&result=failed&errorDetail=ugc_pin'
  end<commit_msg>Switch purchase method to authorize and change required values/expectations<commit_after>require 'test_helper'

class UltimatepayUgcTest < Test::Unit::TestCase
  def setup
    @gateway = UltimatepayUgcGateway.new(
                 :merchant_code => 'UC04',
                 :login => 'login',
                 :password => 'password',
                 :secret_phrase => '5ebe2294ecd0e0f08eab7690d2a6ee69'
               )

    @authorize_options = {
      :user_id => 1,
      :username => 'shredmasterfresh',
      :ugc_pin => '99999999999'
    }
    
    @capture_options = {
      :token => '<KEY>',
      :ugc_pin => '99999999999'
    }
    
  end
  
  def test_valid_login?
    assert !@gateway.valid_login?('login', 'wrong')
    assert !@gateway.valid_login?('wrong', 'password')
    assert @gateway.valid_login?('login', 'password')
  end
  
  def test_successful_authorize
    @gateway.expects(:ssl_post).returns(successful_authorize_response)
    
    assert response = @gateway.authorize(@authorize_options)
    assert_instance_of Response, response
    assert_success response
    
    # Replace with authorization number from the successful response
    assert_equal 'BMhFnN4SohBrWODtHZn62GTAx3tm11SVWldvoE1Ulpc', response.authorization
    assert_equal 5.0, response.params['value']
    assert_equal 'USD', response.params['currency']
    assert response.test?
  end

  def test_unsuccessful_authorize
    @gateway.expects(:ssl_post).returns(failed_authorize_response)
    
    assert response = @gateway.authorize(@authorize_options)
    assert_instance_of Response, response
    assert_failure response
    assert response.test?
  end

  def test_successful_capture
    @gateway.expects(:ssl_post).returns(successful_capture_response)
    
    assert response = @gateway.capture(@capture_options)
    assert_instance_of Response, response
    assert_success response
    
    # Replace with authorization number from the successful response
    assert_equal 'BMhFnN4SohBrWODtHZn62GTAx3tm11SVWldvoE1Ulpc', response.authorization
    assert response.test?
  end

  def test_unsuccessful_capture
    @gateway.expects(:ssl_post).returns(failed_capture_response)
    
    assert response = @gateway.capture(@capture_options)
    assert_instance_of Response, response
    assert_failure response
    assert response.test?
  end

  private
  
  def successful_authorize_response
    [
      'token=<KEY>',
      'result=auth',
      'status=active',
      'value=5',
      'currency=USD'
    ].join('&')
  end
  
  def failed_authorize_response
    'token=6h85pxerDfjwRMSmIAae3lXLXbkE87xjZxy9ytE1bW&result=failed&errorDetail=ugc_pin'
  end
  
  def successful_capture_response
    "token=BMhFnN4SohBrWODtHZn62GTAx3tm11SVWldvoE1Ulpc&result=paid"
  end

  def failed_capture_response
    'token=6h85pxerDfjwRMSmIAae3lXLXbkE87xjZxy9ytE1bW&result=failed&errorDetail=ugc_pin'
  end
{'fraction_non_alphanumeric': 0.09033442088091354, 'fraction_numerical': 0.026508972267536703, 'mean_word_length': 3.658119658119658, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 3, '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': '5314191', 'n_tokens_mistral': 1731, 'n_tokens_neox': 1643, 'n_words': 259}