test/telnyx/telnyx_client_test.rb in telnyx-2.6.0 vs test/telnyx/telnyx_client_test.rb in telnyx-2.7.0

- old
+ new

@@ -1,8 +1,8 @@ # frozen_string_literal: true -require ::File.expand_path("../../test_helper", __FILE__) +require_relative "../test_helper" module Telnyx class TelnyxClientTest < Test::Unit::TestCase context ".active_client" do should "be .default_client outside of #request" do @@ -233,23 +233,21 @@ end end context "Telnyx-Account header" do should "use a globally set header" do - begin - old = Telnyx.telnyx_account - Telnyx.telnyx_account = "acct_1234" + old = Telnyx.telnyx_account + Telnyx.telnyx_account = "acct_1234" - stub_request(:post, "#{Telnyx.api_base}/v2/messaging_profiles") - .with(headers: { "Telnyx-Account" => Telnyx.telnyx_account }) - .to_return(body: JSON.generate(object: "account")) + stub_request(:post, "#{Telnyx.api_base}/v2/messaging_profiles") + .with(headers: { "Telnyx-Account" => Telnyx.telnyx_account }) + .to_return(body: JSON.generate(object: "account")) - client = TelnyxClient.new - client.execute_request(:post, "/v2/messaging_profiles", params: { name: "foobar" }) - ensure - Telnyx.telnyx_account = old - end + client = TelnyxClient.new + client.execute_request(:post, "/v2/messaging_profiles", params: { name: "foobar" }) + ensure + Telnyx.telnyx_account = old end should "use a locally set header" do telnyx_account = "acct_0000" stub_request(:post, "#{Telnyx.api_base}/v2/messaging_profiles") @@ -272,44 +270,42 @@ end end context "app_info" do should "send app_info if set" do - begin - old = Telnyx.app_info - Telnyx.set_app_info( - "MyAwesomePlugin", - partner_id: "partner_1234", - url: "https://myawesomeplugin.info", - version: "1.2.34" - ) + old = Telnyx.app_info + Telnyx.set_app_info( + "MyAwesomePlugin", + partner_id: "partner_1234", + url: "https://myawesomeplugin.info", + version: "1.2.34" + ) - stub_request(:post, "#{Telnyx.api_base}/v2/messaging_profiles") - .with do |req| - assert_equal \ - "Telnyx/v2 RubyBindings/#{Telnyx::VERSION} " \ - "MyAwesomePlugin/1.2.34 (https://myawesomeplugin.info)", - req.headers["User-Agent"] + stub_request(:post, "#{Telnyx.api_base}/v2/messaging_profiles") + .with do |req| + assert_equal \ + "Telnyx/v2 RubyBindings/#{Telnyx::VERSION} " \ + "MyAwesomePlugin/1.2.34 (https://myawesomeplugin.info)", + req.headers["User-Agent"] - data = JSON.parse(req.headers["X-Telnyx-Client-User-Agent"], - symbolize_names: true) + data = JSON.parse(req.headers["X-Telnyx-Client-User-Agent"], + symbolize_names: true) - assert_equal({ - name: "MyAwesomePlugin", - partner_id: "partner_1234", - url: "https://myawesomeplugin.info", - version: "1.2.34", - }, data[:application]) + assert_equal({ + name: "MyAwesomePlugin", + partner_id: "partner_1234", + url: "https://myawesomeplugin.info", + version: "1.2.34", + }, data[:application]) - true - end.to_return(body: JSON.generate(record_type: "messaging_profile")) + true + end.to_return(body: JSON.generate(record_type: "messaging_profile")) - client = TelnyxClient.new - client.execute_request(:post, "/v2/messaging_profiles") - ensure - Telnyx.app_info = old - end + client = TelnyxClient.new + client.execute_request(:post, "/v2/messaging_profiles") + ensure + Telnyx.app_info = old end end context "error handling" do should "handle error response with empty body" do @@ -589,19 +585,17 @@ ret, = client.request { 7 } assert_equal 7, ret end should "reset local thread state after a call" do - begin - Thread.current[:telnyx_client] = :telnyx_client + Thread.current[:telnyx_client] = :telnyx_client - client = TelnyxClient.new - client.request {} + client = TelnyxClient.new + client.request {} - assert_equal :telnyx_client, Thread.current[:telnyx_client] - ensure - Thread.current[:telnyx_client] = nil - end + assert_equal :telnyx_client, Thread.current[:telnyx_client] + ensure + Thread.current[:telnyx_client] = nil end end end class SystemProfilerTest < Test::Unit::TestCase