test/stripe/stripe_client_test.rb in stripe-2.3.0 vs test/stripe/stripe_client_test.rb in stripe-2.4.0
- old
+ new
@@ -141,18 +141,23 @@
end
end
context "Stripe-Account header" do
should "use a globally set header" do
- Stripe.stripe_account = 'acct_1234'
+ begin
+ old = Stripe.stripe_account
+ Stripe.stripe_account = 'acct_1234'
- stub_request(:post, "#{Stripe.api_base}/v1/account").
- with(headers: {"Stripe-Account" => Stripe.stripe_account}).
- to_return(body: JSON.generate(API_FIXTURES.fetch(:account)))
+ stub_request(:post, "#{Stripe.api_base}/v1/account").
+ with(headers: {"Stripe-Account" => Stripe.stripe_account}).
+ to_return(body: JSON.generate(API_FIXTURES.fetch(:account)))
- client = StripeClient.new
- client.execute_request(:post, '/v1/account')
+ client = StripeClient.new
+ client.execute_request(:post, '/v1/account')
+ ensure
+ Stripe.stripe_account = old
+ end
end
should "use a locally set header" do
stripe_account = "acct_0000"
stub_request(:post, "#{Stripe.api_base}/v1/account").
@@ -171,9 +176,46 @@
req.headers["Stripe-Account"].nil?
}.to_return(body: JSON.generate(API_FIXTURES.fetch(:account)))
client = StripeClient.new
client.execute_request(:post, '/v1/account')
+ end
+ end
+
+ context "app_info" do
+ should "send app_info if set" do
+ begin
+ old = Stripe.app_info
+ Stripe.set_app_info(
+ "MyAwesomePlugin",
+ url: "https://myawesomeplugin.info",
+ version: "1.2.34"
+ )
+
+ stub_request(:post, "#{Stripe.api_base}/v1/account").
+ with { |req|
+ assert_equal \
+ "Stripe/v1 RubyBindings/#{Stripe::VERSION} " \
+ "MyAwesomePlugin/1.2.34 (https://myawesomeplugin.info)",
+ req.headers["User-Agent"]
+
+ data = JSON.parse(req.headers["X-Stripe-Client-User-Agent"],
+ symbolize_names: true)
+
+ assert_equal({
+ name: "MyAwesomePlugin",
+ url: "https://myawesomeplugin.info",
+ version: "1.2.34"
+ }, data[:application])
+
+ true
+ }.to_return(body: JSON.generate(API_FIXTURES.fetch(:account)))
+
+ client = StripeClient.new
+ client.execute_request(:post, '/v1/account')
+ ensure
+ Stripe.app_info = old
+ end
end
end
context "error handling" do
should "handle error response with empty body" do