summaryrefslogtreecommitdiff
path: root/engines/billing/test/functional/payments_controller_test.rb
blob: e015a0766b602f24ef92b9bf434267fa686d9376 (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
require 'test_helper'
require 'fake_braintree'

class PaymentsControllerTest < ActionController::TestCase
  include CustomerTestHelper

  def setup
    FakeBraintree.activate!
  end

  def teardown
    FakeBraintree.clear!
  end

  test "payment new" do
    get :new

    assert_not_nil assigns(:client_token)
    assert_response :success
  end

  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

  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...
end