From 0bd3ba020c7fdcc9a00c342292ebb3f7b4f5b0c2 Mon Sep 17 00:00:00 2001 From: Aaron Kirley Date: Wed, 26 Feb 2025 15:14:09 -0500 Subject: [PATCH 1/3] Support listing preview validation --- lib/muffin_man/listings/v20210801.rb | 4 +- spec/muffin_man/listings/v20210801_spec.rb | 94 ++++++++++++++++------ spec/support/sp_api_helpers.rb | 5 ++ 3 files changed, 78 insertions(+), 25 deletions(-) diff --git a/lib/muffin_man/listings/v20210801.rb b/lib/muffin_man/listings/v20210801.rb index e718749..8dcd85d 100644 --- a/lib/muffin_man/listings/v20210801.rb +++ b/lib/muffin_man/listings/v20210801.rb @@ -21,13 +21,15 @@ def get_listings_item(seller_id, sku, marketplace_ids, issue_locale: nil, includ end def put_listings_item(seller_id, sku, marketplace_ids, product_type, attributes, issue_locale: nil, - requirements: nil) + requirements: nil, mode: nil, included_data: []) @local_var_path = "/listings/2021-08-01/items/#{seller_id}/#{sku}" @marketplace_ids = marketplace_ids.is_a?(Array) ? marketplace_ids : [marketplace_ids] @query_params = { "marketplaceIds" => @marketplace_ids.join(",") } @query_params["issueLocale"] = issue_locale if issue_locale + @query_params["includedData"] = included_data.join(",") if included_data.any? + @query_params["mode"] = mode if mode @request_body = { "productType" => product_type, "attributes" => attributes diff --git a/spec/muffin_man/listings/v20210801_spec.rb b/spec/muffin_man/listings/v20210801_spec.rb index 5b79af4..2e79e85 100644 --- a/spec/muffin_man/listings/v20210801_spec.rb +++ b/spec/muffin_man/listings/v20210801_spec.rb @@ -32,32 +32,78 @@ end describe "put_listings_item" do - before { stub_put_listings_item } - - let(:requirements) { "LISTING" } - let(:attributes) do - { - condition_type: [ - { - value: "new_new", - marketplace_id: "ATVPDKIKX0DER" - } - ], - item_name: [ - { - value: "AmazonBasics 16\" Underseat Spinner Carry-On", - language_tag: "en_US", - marketplace_id: "ATVPDKIKX0DER" - } - ] - } + context "when creating or updating a full listing item" do + before { stub_put_listings_item } + + let(:requirements) { "LISTING" } + let(:attributes) do + { + condition_type: [ + { + value: "new_new", + marketplace_id: "ATVPDKIKX0DER" + } + ], + item_name: [ + { + value: "AmazonBasics 16\" Underseat Spinner Carry-On", + language_tag: "en_US", + marketplace_id: "ATVPDKIKX0DER" + } + ] + } + end + + it "returns an ACCEPTED status" do + response = listings_client.put_listings_item(seller_id, sku, amazon_marketplace_id, product_type, attributes, + requirements: requirements) + expect(response.response_code).to eq(200) + expect(JSON.parse(response.body)).to eq(submission_accepted_response) + end end - it "makes a request to create a listings item or update an existing listings item" do - response = listings_client.put_listings_item(seller_id, sku, amazon_marketplace_id, product_type, attributes, - requirements: requirements) - expect(response.response_code).to eq(200) - expect(JSON.parse(response.body)).to eq(submission_accepted_response) + context "when previewing validation for a listings item" do + before { stub_put_listings_item_preview } + + let(:requirements) { "LISTING_OFFER_ONLY" } + let(:attributes) do + { + condition_type: [ + { + value: "new_new", + marketplace_id: "ATVPDKIKX0DER" + } + ], + item_name: [ + { + value: "AmazonBasics 16\" Underseat Spinner Carry-On", + language_tag: "en_US", + marketplace_id: "ATVPDKIKX0DER" + } + ], + identifiers: [ + { + asin: "B987654321", + marketplaceId: "ATVPDKIKX0DER" + } + ] + } + end + + # PUT https://sellingpartnerapi-na.amazon.com/listings/2021-08-01/items/AXXXXXXXXXXXXX/ABC123 + # ?marketplaceIds=ATVPDKIKX0DER + # &issueLocale=en_US + # &mode=VALIDATION_PREVIEW + # &includedData=issues,identifiers + + it "returns a VALIDATED status" do + response = listings_client.put_listings_item(seller_id, sku, + amazon_marketplace_id, product_type, attributes, + requirements: requirements, mode: "VALIDATION_PREVIEW", + included_data: ["issues", "identifiers"], issue_locale: "en_US") + expect(response.response_code).to eq(200) + expect(JSON.parse(response.body)["status"]).to eq("VALID") + end end end diff --git a/spec/support/sp_api_helpers.rb b/spec/support/sp_api_helpers.rb index 2d4171a..3f89daa 100644 --- a/spec/support/sp_api_helpers.rb +++ b/spec/support/sp_api_helpers.rb @@ -235,6 +235,11 @@ def stub_put_listings_item .to_return(status: 200, body: File.read("./spec/support/put_listings_item.json"), headers: {}) end + def stub_put_listings_item_preview + stub_request(:put, "https://#{hostname}/listings/2021-08-01/items/#{seller_id}/#{sku}?includedData=issues,identifiers&issueLocale=en_US&marketplaceIds=DRURYLANE&mode=VALIDATION_PREVIEW") + .to_return(status: 200, body: File.read("./spec/support/put_listings_item_preview.json"), headers: {}) + end + def stub_delete_listings_item stub_request(:delete, "https://#{hostname}/listings/2021-08-01/items/#{seller_id}/#{sku}?marketplaceIds=#{amazon_marketplace_id}&issueLocale=#{issue_locale}") .to_return(status: 200, body: File.read("./spec/support/delete_listings_item.json"), headers: {}) From a45249ef4ad425c17b9e5179dea1a986b93fb280 Mon Sep 17 00:00:00 2001 From: Aaron Kirley Date: Wed, 26 Feb 2025 15:14:45 -0500 Subject: [PATCH 2/3] Support listing preview validation --- spec/support/put_listings_item_preview.json | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 spec/support/put_listings_item_preview.json diff --git a/spec/support/put_listings_item_preview.json b/spec/support/put_listings_item_preview.json new file mode 100644 index 0000000..10c61a6 --- /dev/null +++ b/spec/support/put_listings_item_preview.json @@ -0,0 +1,12 @@ +{ + "sku": "ABC123", + "status": "VALID", + "submissionId": "65793a6142784e36b39af92b736a3a9f", + "issues": [], + "identifiers": [ + { + "marketplaceId": "ATVPDKIKX0DER", + "asin": "B987654321" + } + ] +} \ No newline at end of file From d8bc7ea85c3c3ef4131c705b115d2f76beeabf2f Mon Sep 17 00:00:00 2001 From: Aaron Kirley Date: Wed, 26 Feb 2025 15:16:31 -0500 Subject: [PATCH 3/3] remove comments --- spec/muffin_man/listings/v20210801_spec.rb | 6 ------ 1 file changed, 6 deletions(-) diff --git a/spec/muffin_man/listings/v20210801_spec.rb b/spec/muffin_man/listings/v20210801_spec.rb index 2e79e85..c3446eb 100644 --- a/spec/muffin_man/listings/v20210801_spec.rb +++ b/spec/muffin_man/listings/v20210801_spec.rb @@ -90,12 +90,6 @@ } end - # PUT https://sellingpartnerapi-na.amazon.com/listings/2021-08-01/items/AXXXXXXXXXXXXX/ABC123 - # ?marketplaceIds=ATVPDKIKX0DER - # &issueLocale=en_US - # &mode=VALIDATION_PREVIEW - # &includedData=issues,identifiers - it "returns a VALIDATED status" do response = listings_client.put_listings_item(seller_id, sku, amazon_marketplace_id, product_type, attributes,