summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjessib <jessib@leap.se>2013-04-30 14:12:08 -0700
committerAzul <azul@leap.se>2013-07-17 10:47:13 +0200
commit7eab7e33730e12eeb460d2b3965a8712320aff54 (patch)
tree56ac203fb7f359e8374a9433a5763f4f5e3e4368
parent5442da999c8398b1e84162996f1e944c6496b095 (diff)
Very rough start to tests, which still doesn't really use FakeBraintree.
-rw-r--r--billing/test/functional/customers_controller_test.rb57
-rw-r--r--billing/test/functional/payments_controller_test.rb55
-rw-r--r--billing/test/test_helper.rb15
-rw-r--r--billing/test/unit/customer_test.rb38
-rw-r--r--common_dependencies.rb1
5 files changed, 166 insertions, 0 deletions
diff --git a/billing/test/functional/customers_controller_test.rb b/billing/test/functional/customers_controller_test.rb
new file mode 100644
index 0000000..45a14ed
--- /dev/null
+++ b/billing/test/functional/customers_controller_test.rb
@@ -0,0 +1,57 @@
+require 'test_helper'
+
+class CustomersControllerTest < ActionController::TestCase
+
+ setup do
+ @user = FactoryGirl.create :user
+ @other_user = FactoryGirl.create :user
+ FakeBraintree.clear!
+ FakeBraintree.verify_all_cards!
+ testid = 'testid'
+ FakeBraintree::Customer.new({:credit_cards => [{:number=>"5105105105105100", :expiration_date=>"05/2013"}]}, {:id => testid, :merchant_id => Braintree::Configuration.merchant_id})
+ # any reason to call the create instance method on the FakeBraintree::Customer ?
+ @customer = Customer.new(:user_id => @other_user.id)
+ @customer.braintree_customer_id = testid
+ @customer.save
+
+ end
+
+ teardown do
+ @user.destroy
+ @other_user.destroy
+ @customer.destroy
+ end
+
+ test "no access if not logged in" do
+ get :new
+ assert_access_denied(true, false)
+ get :show, :id => @customer.braintree_customer_id
+ assert_access_denied(true, false)
+ get :edit, :id => @customer.braintree_customer_id
+ assert_access_denied(true, false)
+ end
+
+
+ test "should get new if logged in and not customer" do
+ login @user
+ get :new
+ assert_not_nil assigns(:tr_data)
+ assert_response :success
+ end
+
+ test "new should direct edit if user is already a customer" do
+ login @other_user
+ get :new
+ assert_response :redirect
+ assert_equal edit_customer_url(@customer.braintree_customer_id), response.header['Location']
+ end
+
+
+ test "show" do
+ login @other_user
+ # Below will fail, as when we go to fetch the customer data, Braintree::Customer.find(params[:id]) won't find the customer as it is a FakeBraintree customer.
+ #get :show, :id => @customer.braintree_customer_id
+
+ end
+
+end
diff --git a/billing/test/functional/payments_controller_test.rb b/billing/test/functional/payments_controller_test.rb
new file mode 100644
index 0000000..c8ef205
--- /dev/null
+++ b/billing/test/functional/payments_controller_test.rb
@@ -0,0 +1,55 @@
+require 'test_helper'
+
+class PaymentsControllerTest < ActionController::TestCase
+
+ setup do
+ FakeBraintree.clear!
+ @user = FactoryGirl.create :user
+ @other_user = FactoryGirl.create :user
+ FakeBraintree.clear!
+ FakeBraintree.verify_all_cards!
+ testid = 'testid'
+ FakeBraintree::Customer.new({:credit_cards => [{:number=>"5105105105105100", :expiration_date=>"05/2013"}]}, {:id => testid, :merchant_id => Braintree::Configuration.merchant_id})
+ # any reason to call the create instance method on the FakeBraintree::Customer ?
+ @customer = Customer.new(:user_id => @other_user.id)
+ @customer.braintree_customer_id = testid
+ @customer.save
+ end
+
+ teardown do
+ @user.destroy
+ @other_user.destroy
+ @customer.destroy
+ end
+
+ test "payment when unauthorized" do
+ get :new
+ assert_not_nil assigns(:tr_data)
+ assert_response :success
+ end
+
+ test "authenticated user must create account before making payment" do
+ login @user
+ get :new
+ assert_response :redirect
+ assert_equal new_customer_url, response.header['Location']
+ end
+
+ test "payment when authenticated as customer" do
+ get :new
+ assert_not_nil assigns(:tr_data)
+ assert_response :success
+ #TODO check more here
+ end
+
+ # what would we test with something like this?
+ test "fake transaction" do
+ transaction = FakeBraintree.generate_transaction(:amount => '20.00',
+ #:status => Braintree::Transaction::Status::Settled,
+ #:subscription_id => 'foobar',
+ )
+
+ end
+
+
+end
diff --git a/billing/test/test_helper.rb b/billing/test/test_helper.rb
new file mode 100644
index 0000000..1e26a31
--- /dev/null
+++ b/billing/test/test_helper.rb
@@ -0,0 +1,15 @@
+# Configure Rails Environment
+ENV["RAILS_ENV"] = "test"
+
+require File.expand_path("../dummy/config/environment.rb", __FILE__)
+require "rails/test_help"
+
+Rails.backtrace_cleaner.remove_silencers!
+
+# Load support files
+Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
+
+# Load fixtures from the engine
+if ActiveSupport::TestCase.method_defined?(:fixture_path=)
+ ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
+end
diff --git a/billing/test/unit/customer_test.rb b/billing/test/unit/customer_test.rb
new file mode 100644
index 0000000..4ed6392
--- /dev/null
+++ b/billing/test/unit/customer_test.rb
@@ -0,0 +1,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
diff --git a/common_dependencies.rb b/common_dependencies.rb
index 085a898..4790ea4 100644
--- a/common_dependencies.rb
+++ b/common_dependencies.rb
@@ -9,6 +9,7 @@ group :test do
gem 'poltergeist'
# required for save_and_open_page in integration tests
# gem 'launchy'
+ gem 'fake_braintree' #depends on rspec?
end
group :test, :development do