From 775835dc1b9a8f79cdd53d450fd6cd35f131b4a6 Mon Sep 17 00:00:00 2001 From: claucece Date: Mon, 5 Oct 2015 21:57:05 -0500 Subject: add test to payments and subscriptions --- .../test/functional/payments_controller_test.rb | 69 ++++++++++++---------- 1 file changed, 39 insertions(+), 30 deletions(-) (limited to 'engines/billing/test/functional/payments_controller_test.rb') diff --git a/engines/billing/test/functional/payments_controller_test.rb b/engines/billing/test/functional/payments_controller_test.rb index 90b7582..e015a07 100644 --- a/engines/billing/test/functional/payments_controller_test.rb +++ b/engines/billing/test/functional/payments_controller_test.rb @@ -4,47 +4,56 @@ require 'fake_braintree' class PaymentsControllerTest < ActionController::TestCase include CustomerTestHelper - test "payment when unauthorized" do - get :new - assert_not_nil assigns(:tr_data) - assert_response :success + def setup + FakeBraintree.activate! end - test "successful confirmation renders confirm" do - Braintree::TransparentRedirect.expects(:confirm).returns(success_response) - get :confirm - - assert_response :success - assert_template :confirm + def teardown + FakeBraintree.clear! end - test "failed confirmation renders new" do - Braintree::TransparentRedirect.expects(:confirm).returns(failure_response) - get :confirm + test "payment new" do + get :new + assert_not_nil assigns(:client_token) assert_response :success - assert_not_nil assigns(:tr_data) - assert_template :new end - def failure_response - stub success?: false, - errors: stub(for: nil, size: 0), - params: {}, - transaction: stub(status: nil) + test "sucess confirmation" do + #already included with FakeBraintree + #Braintree::Transaction.sale.expects(:confirm).returns(success_response) + post :confirm, { + amount: "100", + payment_method_nonce: "fake-valid-nonce", + customer: { + first_name: "Test", + last_name: "Testing", + company: "RGSoC", + email: "any@email.com", + phone: "555-888-1234" } + } + + assert assigns(:result).success? + assert_not_nil flash[:success] end - def success_response - stub success?: true, - transaction: stub_transaction + test "failed confirmation renders new" do + FakeBraintree.decline_all_cards! + post :confirm, { + amount: "100", + payment_method_nonce: "fake-valid-nonce", + customer: { + first_name: "Test", + last_name: "Testing", + company: "RGSoC", + email: "any@email.com", + phone: "555-888-1234" } + } + + assert !assigns(:result).success? + assert_not_nil flash[:error] + FakeBraintree.clear! end # that's what you get when not following the law of demeter... - def stub_transaction - stub amount: "100.00", - id: "ASDF", - customer_details: FactoryGirl.build(:braintree_customer), - credit_card_details: FactoryGirl.build(:braintree_customer).credit_cards.first - end - end -- cgit v1.2.3