test/unit/peddler/test_client.rb in peddler-0.15.0 vs test/unit/peddler/test_client.rb in peddler-0.16.0

- old
+ new

@@ -2,11 +2,13 @@ require 'excon' require 'peddler/client' class TestPeddlerClient < MiniTest::Test module Parser - def self.new(res, *); res; end + def self.new(res, *) + res + end end def setup @body = 'foo' Excon.defaults[:mock] = true @@ -16,11 +18,11 @@ @klass.parser = Parser @client = @klass.new @client.aws_access_key_id = 'key' @client.aws_secret_access_key = 'secret' @client.merchant_id = 'seller' - @client.marketplace_id = 'ATVPDKIKX0DER' # US + @client.primary_marketplace_id = 'ATVPDKIKX0DER' # US @client.operation('Foo') end def teardown Excon.stubs.clear @@ -42,11 +44,11 @@ def test_default_path assert_equal '/', @klass.path end def test_has_user_agent - assert @client.connection.data[:headers].has_key?('User-Agent') + assert @client.connection.data[:headers].key?('User-Agent') end def test_inherits_parents_params assert_equal Peddler::Client.params, @klass.params end @@ -78,19 +80,19 @@ assert_equal 'text/tab-separated-values; charset=ISO-8859-1', content_type end def test_sets_content_type_header_for_chinese_flat_file_body - @client.marketplace_id = 'AAHKV2X7AFYLW' + @client.primary_marketplace_id = 'AAHKV2X7AFYLW' @client.body = 'foo' content_type = @client.headers.fetch('Content-Type') assert_equal 'text/tab-separated-values; charset=UTF-16', content_type end def test_sets_content_type_header_for_japanese_flat_file_body - @client.marketplace_id = 'A1VC38T7YXB528' + @client.primary_marketplace_id = 'A1VC38T7YXB528' @client.body = 'foo' content_type = @client.headers.fetch('Content-Type') assert_equal 'text/tab-separated-values; charset=Shift_JIS', content_type end @@ -129,15 +131,15 @@ @client.defaults.update(instrumentor: instrumentor) @client.run headers = instrumentor.events['excon.request'][:headers] - assert headers.has_key?('User-Agent') + assert headers.key?('User-Agent') end def test_error_callback_on_class - Excon.stub({}, { status: 503 }) + Excon.stub({}, status: 503) assert_raises(Excon::Errors::ServiceUnavailable) do @client.run end @@ -150,11 +152,11 @@ Excon.stubs.clear @klass.instance_variable_set(:@error_handler, nil) end def test_error_callback_on_instance - Excon.stub({}, { status: 503 }) + Excon.stub({}, status: 503) assert_raises(Excon::Errors::ServiceUnavailable) do @client.run end @@ -166,11 +168,11 @@ Excon.stubs.clear end def test_error_callback_on_client_ancestor - Excon.stub({}, { status: 503 }) + Excon.stub({}, status: 503) assert_raises(Excon::Errors::ServiceUnavailable) do @client.run end @@ -182,24 +184,47 @@ klass.parser = Parser client = klass.new client.aws_access_key_id = 'key' client.aws_secret_access_key = 'secret' client.merchant_id = 'seller' - client.marketplace_id = 'ATVPDKIKX0DER' # US + client.primary_marketplace_id = 'ATVPDKIKX0DER' # US client.operation('Foo') client.run Excon.stubs.clear Peddler::Client.instance_variable_set(:@error_handler, nil) end def test_deprecates_call_to_parser_parse deprecated_parser = Module.new do - def self.parse(res, *); res; end + def self.parse(res, *) + res + end end @client.stub :warn, nil do @klass.parser = deprecated_parser res = @client.run assert_equal @body, res.body end + end + + def test_raises_no_method_errors_not_related_to_deprecated_parser + bad_parser = Module.new do + def self.new(*) + fail NoMethodError, "foo" + end + end + @klass.parser = bad_parser + @client.stub :warn, nil do + assert_raises NoMethodError do + @client.run + end + end + end + + def test_deprecated_marketplace_id_accessor + refute_nil @client.marketplace_id + @client.marketplace_id = "123" + assert_equal "123", @client.marketplace_id + assert_equal @client.primary_marketplace_id, @client.marketplace_id end end