summaryrefslogtreecommitdiff
path: root/billing/test/unit/customer_test.rb
blob: 4ed6392d3016f68af555f29ea51b85d1ceeda6d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
require 'test_helper'

class CustomerTest < ActiveSupport::TestCase
  setup do
    #cannot get this working with FakeBraintree becuase the methods in customer.rb try to find the customer in braintree itself.

    @user = FactoryGirl.build(:user)
    @user.save
    @customer = Customer.new(:user_id => @user.id)

    result = Braintree::Customer.create()
    @customer.braintree_customer_id = result.customer.id
    @customer.save
    @braintree_customer_data = Braintree::Customer.find(@customer.braintree_customer_id)

    result = Braintree::Customer.create(:credit_card => { :number => "5105105105105100", :expiration_date => "05/2012"})
  end

  teardown do
    @user.destroy
    @customer.destroy
    Braintree::Customer.delete(@customer.braintree_customer_id)
  end

  test "default credit card" do
    assert_nil @customer.default_credit_card(@braintree_customer_data)
    Braintree::Customer.update(@customer.braintree_customer_id, :credit_card => { :number => "5105105105105100", :expiration_date => "05/2012" } )
    assert_not_nil @customer.default_credit_card
    assert_equal @customer.default_credit_card.expiration_date, "05/2012"
  end


  test "single subscription" do


  end

end