test/unit/peddler/test_client.rb in peddler-0.12.7 vs test/unit/peddler/test_client.rb in peddler-0.13.0

- old
+ new

@@ -2,11 +2,11 @@ require 'excon' require 'peddler/client' class TestPeddlerClient < MiniTest::Test module Parser - def self.parse(res, *); res; end + def self.new(res, *); res; end end def setup @body = 'foo' Excon.defaults[:mock] = true @@ -132,21 +132,74 @@ headers = instrumentor.events['excon.request'][:headers] assert headers.has_key?('User-Agent') end - def test_error_callback + def test_error_callback_on_class Excon.stub({}, { status: 503 }) assert_raises(Excon::Errors::ServiceUnavailable) do @client.run end + @klass.on_error do |_, res| + assert_equal 503, res.status + end + + @client.run + + Excon.stubs.clear + @klass.instance_variable_set(:@error_handler, nil) + end + + def test_error_callback_on_instance + Excon.stub({}, { status: 503 }) + + assert_raises(Excon::Errors::ServiceUnavailable) do + @client.run + end + @client.on_error do |_, res| assert_equal 503, res.status end @client.run Excon.stubs.clear + end + + def test_error_callback_on_client_ancestor + Excon.stub({}, { status: 503 }) + + assert_raises(Excon::Errors::ServiceUnavailable) do + @client.run + end + + Peddler::Client.on_error do |_, res| + assert_equal 503, res.status + end + + klass = Class.new(Peddler::Client) + 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.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 + end + @client.stub :warn, nil do + @klass.parser = deprecated_parser + res = @client.run + assert_equal @body, res.body + end end end