@@ -20,6 +20,7 @@ class StripeClientTest < Test::Unit::TestCase
20
20
@orig_api_key = Stripe . api_key
21
21
@orig_stripe_account = Stripe . stripe_account
22
22
@orig_open_timeout = Stripe . open_timeout
23
+ @orig_api_version = Stripe . api_version
23
24
24
25
Stripe . api_key = "DONT_USE_THIS_KEY"
25
26
Stripe . stripe_account = "DONT_USE_THIS_ACCOUNT"
@@ -30,6 +31,7 @@ class StripeClientTest < Test::Unit::TestCase
30
31
Stripe . api_key = @orig_api_key
31
32
Stripe . stripe_account = @orig_stripe_account
32
33
Stripe . open_timeout = @orig_open_timeout
34
+ Stripe . api_version = @orig_api_version
33
35
end
34
36
35
37
should "use default config options" do
@@ -45,7 +47,6 @@ class StripeClientTest < Test::Unit::TestCase
45
47
client = StripeClient . new ( "test_123" )
46
48
assert_equal "test_123" , client . instance_variable_get ( :@requestor ) . config . api_key
47
49
assert_nil client . instance_variable_get ( :@requestor ) . config . stripe_account
48
- assert_equal 30 , client . instance_variable_get ( :@requestor ) . config . open_timeout
49
50
end
50
51
51
52
should "use client config options" do
@@ -67,6 +68,30 @@ class StripeClientTest < Test::Unit::TestCase
67
68
assert_equal "2022-11-15" , req . headers [ "Stripe-Version" ]
68
69
end
69
70
71
+ should "use global config options for options unavailable in client" do
72
+ Stripe . api_key = "NOT_THIS_KEY"
73
+ Stripe . stripe_account = "NOT_THIS_ACCOUNT"
74
+ Stripe . api_version = "2022-11-15"
75
+ client = StripeClient . new ( "test_123" , stripe_account : "acct_123" )
76
+ # Imported from global options
77
+ assert_equal 30_000 , client . instance_variable_get ( :@requestor ) . config . open_timeout
78
+ # Not set in client options, not imported from global
79
+ assert_equal client . instance_variable_get ( :@requestor ) . config . api_base , Stripe ::DEFAULT_API_BASE
80
+ assert_equal client . instance_variable_get ( :@requestor ) . config . api_version , Stripe ::ApiVersion ::CURRENT
81
+
82
+ req = nil
83
+ stub_request ( :get , "#{ Stripe ::DEFAULT_API_BASE } /v1/customers/cus_123" )
84
+ . with { |request | req = request }
85
+ . to_return ( body : JSON . generate ( object : "customer" ) )
86
+
87
+ client . v1 . customers . retrieve ( "cus_123" )
88
+
89
+ # Set in client options
90
+ assert_equal "Bearer test_123" , req . headers [ "Authorization" ]
91
+ assert_equal "acct_123" , req . headers [ "Stripe-Account" ]
92
+ assert_requested ( :get , "#{ Stripe ::DEFAULT_API_BASE } /v1/customers/cus_123" )
93
+ end
94
+
70
95
should "request options overrides client config options" do
71
96
client = StripeClient . new ( "test_123" , stripe_version : "2022-11-15" , stripe_account : "acct_123" )
72
97
0 commit comments