Skip to content

Add support for Listing Preview Validation #96

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/muffin_man/listings/v20210801.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
88 changes: 64 additions & 24 deletions spec/muffin_man/listings/v20210801_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,72 @@
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

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

Expand Down
12 changes: 12 additions & 0 deletions spec/support/put_listings_item_preview.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"sku": "ABC123",
"status": "VALID",
"submissionId": "65793a6142784e36b39af92b736a3a9f",
"issues": [],
"identifiers": [
{
"marketplaceId": "ATVPDKIKX0DER",
"asin": "B987654321"
}
]
}
5 changes: 5 additions & 0 deletions spec/support/sp_api_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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: {})
Expand Down