summaryrefslogtreecommitdiff
path: root/billing/test/integration
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2013-07-03 09:28:44 +0200
committerAzul <azul@leap.se>2013-07-17 10:47:14 +0200
commitb51f300fe374e9eecf7e98266c96631fa3c8a278 (patch)
treea400bd1f102ff87335e3063c44405bd0e0500a8b /billing/test/integration
parent1e4245907ca17d1d6afbeca82b25c35c970ba499 (diff)
billing: integration test creating customer
Diffstat (limited to 'billing/test/integration')
-rw-r--r--billing/test/integration/customer_creation_test.rb61
1 files changed, 61 insertions, 0 deletions
diff --git a/billing/test/integration/customer_creation_test.rb b/billing/test/integration/customer_creation_test.rb
new file mode 100644
index 0000000..50116db
--- /dev/null
+++ b/billing/test/integration/customer_creation_test.rb
@@ -0,0 +1,61 @@
+require 'test_helper'
+require 'fake_braintree'
+require 'capybara/rails'
+
+class CustomerCreationTest < ActionDispatch::IntegrationTest
+ include Warden::Test::Helpers
+ include Capybara::DSL
+
+ setup do
+ Warden.test_mode!
+ end
+
+ teardown do
+ Warden.test_reset!
+ end
+
+ # We only test the confirmation here.
+ # The first request to Braintree is triggered outside of rails
+ test "successfully confirms customer creation" do
+ user = FactoryGirl.create(:user)
+ login_as user
+ response = post_transparent_redirect :create_customer_data,
+ customer: FactoryGirl.attributes_for(:braintree_customer),
+ redirect_url: confirm_customer_url
+
+ assert_difference("Customer.count") do
+ post response['Location']
+ end
+
+ assert_equal 200, status
+ assert customer = Customer.find_by_user_id(user.id)
+ assert customer.braintree_customer
+ end
+
+ # let's test both steps together with capybara
+ test "create customer with braintree" do
+ user = FactoryGirl.create(:user)
+ login_as user
+ visit '/customer/new'
+ assert_difference("Customer.count") do
+ click_button 'Save Payment Info'
+ end
+ assert_equal 200, status
+ assert customer = Customer.find_by_user_id(user.id)
+ assert customer.braintree_customer
+ end
+
+ def post_transparent_redirect(type, data)
+ params = data.dup
+ params[:tr_data] = Braintree::TransparentRedirect.send(type, params)
+ post_transparent_redirect_params(params)
+ end
+
+ def post_transparent_redirect_params(params)
+ uri = URI.parse(Braintree::TransparentRedirect.url)
+ Net::HTTP.start(uri.host, uri.port) do |http|
+ http.post(uri.path, Rack::Utils.build_nested_query(params))
+ end
+ end
+
+end