<commit_before>require File.expand_path(File.join(File.dirname(__FILE__), '../integration_test_helper'))

describe 'Transaction Integration' do
  before do
    Braintree::Customer.all.each { |c| Braintree::Customer.delete c.id }
  end

  it 'should be able to create, submit, void transactions for a customer' do

    braintree_customer = Braintree::Customer.create!(:id => 'customer_id', :first_name => 'Brain', :last_name => 'Tree', :credit_card => credit_card_hash)
    customer = BraintreeRails::Customer.new(braintree_customer)
    credit_card = customer.credit_cards.first

    [{:amount => 10.00, :customer => customer}, {:amount => 20.00, :customer => customer, :credit_card => credit_card}].each do |params|
      transaction = BraintreeRails::Transaction.create!(params)
      transaction.persisted?.must_equal true
      transaction.amount.must_equal params[:amount]
      transaction.status.must_equal Braintree::Transaction::Status::Authorized

      transaction.submit_for_settlement!
      transaction.status.must_equal Braintree::Transaction::Status::SubmittedForSettlement

      transaction.void!
      transaction.status.must_equal Braintree::Transaction::Status::Voided
    end
  end

  it "should be able to load transactions for given customer and credit_card" do
    braintree_customer = Braintree::Customer.create!(:id => 'customer_id', :first_name => 'Brain', :last_name => 'Tree', :credit_card => credit_card_hash)
    customer = BraintreeRails::Customer.new(braintree_customer)
    credit_card = customer.credit_cards.first
    transaction = BraintreeRails::Transaction.create!({:amount => 15.00, :customer => customer})
    
    customer.transactions.count.must_equal 1
    credit_card.transactions.count.must_equal 1
  end
end<commit_msg>Adding one more integration test<commit_after>require File.expand_path(File.join(File.dirname(__FILE__), '../integration_test_helper'))

describe 'Transaction Integration' do
  before do
    Braintree::Customer.all.each { |c| Braintree::Customer.delete c.id }
  end

  it 'should be able to create, submit, void transactions for a customer' do

    braintree_customer = Braintree::Customer.create!(:id => 'customer_id', :first_name => 'Brain', :last_name => 'Tree', :credit_card => credit_card_hash)
    customer = BraintreeRails::Customer.new(braintree_customer)
    credit_card = customer.credit_cards.first

    [{:amount => rand(1..10), :customer => customer}, {:amount => rand(1..10), :customer => customer, :credit_card => credit_card}].each do |params|
      transaction = BraintreeRails::Transaction.create!(params)
      transaction.persisted?.must_equal true
      transaction.amount.must_equal params[:amount]
      transaction.status.must_equal Braintree::Transaction::Status::Authorized

      transaction.submit_for_settlement!
      transaction.status.must_equal Braintree::Transaction::Status::SubmittedForSettlement

      transaction.void!
      transaction.status.must_equal Braintree::Transaction::Status::Voided
    end
  end

  it "should be able to load transactions for given customer and credit_card" do
    braintree_customer = Braintree::Customer.create!(:id => 'customer_id', :first_name => 'Brain', :last_name => 'Tree', :credit_card => credit_card_hash)
    customer = BraintreeRails::Customer.new(braintree_customer)
    credit_card = customer.credit_cards.first
    transaction = BraintreeRails::Transaction.create!(:amount => rand(1..10), :customer => customer)
    
    customer.transactions.count.must_equal 1
    credit_card.transactions.count.must_equal 1
  end

  it 'should be able to capture braintree api errors' do
    braintree_customer = Braintree::Customer.create!(:id => 'customer_id', :first_name => 'Brain', :last_name => 'Tree', :credit_card => credit_card_hash)
    customer = BraintreeRails::Customer.new(braintree_customer)
    credit_card = customer.credit_cards.first
    transaction = BraintreeRails::Transaction.create!(:amount => rand(1..10), :customer => customer)

    transaction.void!
    transaction.submit_for_settlement.must_equal false
    transaction.errors[:base].wont_be :blank?

    lambda{transaction.submit_for_settlement!}.must_raise Braintree::ValidationsFailed
  end
end
{'fraction_non_alphanumeric': 0.11826169555924959, 'fraction_numerical': 0.006649251959154595, 'mean_word_length': 5.113207547169812, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, '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': '1115306', 'n_tokens_mistral': 1279, 'n_tokens_neox': 1221, 'n_words': 249}