From 240ae7d9befaab32de53c042a35f351dc5f985c0 Mon Sep 17 00:00:00 2001 From: Hakan Ensari Date: Tue, 1 Oct 2024 15:56:29 +0200 Subject: [PATCH] Add 404 error --- lib/peddler/error.rb | 1 + test/peddler/error/not_found_test.rb | 26 ++++ test/peddler/error_test.rb | 7 ++ .../Error/NotFoundTest/test_not_found.yml | 111 ++++++++++++++++++ 4 files changed, 145 insertions(+) create mode 100644 test/peddler/error/not_found_test.rb create mode 100644 test/vcr_cassettes/Peddler/Error/NotFoundTest/test_not_found.yml diff --git a/lib/peddler/error.rb b/lib/peddler/error.rb index a0d1cefa..34304943 100644 --- a/lib/peddler/error.rb +++ b/lib/peddler/error.rb @@ -3,6 +3,7 @@ module Peddler class Error < StandardError class InvalidInput < Error; end + class NotFound < Error; end class QuotaExceeded < Error; end class Unauthorized < Error; end diff --git a/test/peddler/error/not_found_test.rb b/test/peddler/error/not_found_test.rb new file mode 100644 index 00000000..9d306816 --- /dev/null +++ b/test/peddler/error/not_found_test.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +require "helper" + +require "peddler/api/reports_2021_06_30" + +module Peddler + class Error + class NotFoundTest < Minitest::Test + include FeatureHelpers + + def test_not_found + error = assert_raises(NotFound) do + api.get_report("1234567") + end + assert_equal(404, error.cause.status) + end + + private + + def api_class + API::Reports20210630 + end + end + end +end diff --git a/test/peddler/error_test.rb b/test/peddler/error_test.rb index 252a2970..87f01387 100644 --- a/test/peddler/error_test.rb +++ b/test/peddler/error_test.rb @@ -12,6 +12,13 @@ def test_invalid_input assert_kind_of(Error::InvalidInput, error) end + def test_not_found + response = '{"errors":[{"code":"NotFound","message":"NotFound"}]}' + error = Error.build(response) + + assert_kind_of(Error::NotFound, error) + end + def test_quota_exceeded response = '{"errors":[{"code":"QuotaExceeded","message":"You exceeded your quota for the requested resource."}]}' error = Error.build(response) diff --git a/test/vcr_cassettes/Peddler/Error/NotFoundTest/test_not_found.yml b/test/vcr_cassettes/Peddler/Error/NotFoundTest/test_not_found.yml new file mode 100644 index 00000000..7e4b7429 --- /dev/null +++ b/test/vcr_cassettes/Peddler/Error/NotFoundTest/test_not_found.yml @@ -0,0 +1,111 @@ +--- +http_interactions: +- request: + method: post + uri: https://api.amazon.com/auth/o2/token + body: + encoding: ASCII-8BIT + base64_string: | + Z3JhbnRfdHlwZT1yZWZyZXNoX3Rva2VuJmNsaWVudF9pZD1GSUxURVJFRCZj + bGllbnRfc2VjcmV0PUZJTFRFUkVEJnJlZnJlc2hfdG9rZW49RklMVEVSRUQ= + headers: + Connection: + - close + Content-Type: + - application/x-www-form-urlencoded + Host: + - api.amazon.com + User-Agent: + - http.rb/5.2.0 + response: + status: + code: 200 + message: OK + headers: + Server: + - Server + Date: + - Tue, 01 Oct 2024 13:47:15 GMT + Content-Type: + - application/json;charset=UTF-8 + Content-Length: + - '806' + Connection: + - close + X-Amz-Rid: + - 28CZXWEVD1MF15WF8NZQ + X-Amzn-Requestid: + - fdbfb623-8c83-45dd-a9e3-c58af79f0a4d + X-Amz-Date: + - Tue, 01 Oct 2024 13:47:15 GMT + Cache-Control: + - no-cache, no-store, must-revalidate + Pragma: + - no-cache + Vary: + - Content-Type,Accept-Encoding,User-Agent + Strict-Transport-Security: + - max-age=47474747; includeSubDomains; preload + body: + encoding: UTF-8 + string: '{"access_token":"FILTERED","refresh_token":"FILTERED","token_type":"bearer","expires_in":3600}' + recorded_at: Tue, 01 Oct 2024 13:47:15 GMT +- request: + method: get + uri: https://sellingpartnerapi-eu.amazon.com/reports/2021-06-30/reports/1234567 + body: + encoding: ASCII-8BIT + base64_string: '' + headers: + Host: + - sellingpartnerapi-eu.amazon.com + User-Agent: + - Peddler/3.0.0.beta1 (Language=Ruby; Hakans-MacBook-Pro.local) + X-Amz-Access-Token: + - FILTERED + X-Amz-Date: + - 20241001T134715Z + Connection: + - close + response: + status: + code: 404 + message: Not Found + headers: + Server: + - Server + Date: + - Tue, 01 Oct 2024 13:47:15 GMT + Content-Type: + - application/json + Content-Length: + - '143' + Connection: + - close + X-Amz-Rid: + - W30CHD6C7KFTVT3GQFCX + X-Amzn-Ratelimit-Limit: + - '2.0' + X-Amzn-Requestid: + - dc880af3-4263-4b91-9294-138c838ff571 + X-Amz-Apigw-Id: + - OPFdc880af34263 + X-Amzn-Trace-Id: + - Root=1-66fbfd63-dc880af342634b91 + Vary: + - Content-Type,Accept-Encoding,User-Agent + Strict-Transport-Security: + - max-age=47474747; includeSubDomains; preload + body: + encoding: UTF-8 + string: |- + { + "errors": [ + { + "code": "NotFound", + "message": "One or more of the provided ReportRequestIds could not be found." + } + ] + } + recorded_at: Tue, 01 Oct 2024 13:47:15 GMT +recorded_with: VCR 6.3.1