diff --git a/lib/muffin_man/fulfillment_inbound/v0.rb b/lib/muffin_man/fulfillment_inbound/v0.rb index 930c62a..4e2c3e3 100644 --- a/lib/muffin_man/fulfillment_inbound/v0.rb +++ b/lib/muffin_man/fulfillment_inbound/v0.rb @@ -137,6 +137,20 @@ def void_transport(shipment_id) @request_type = "POST" call_api end + + def get_shipment_items(query_type, marketplace_id, last_updated_after: nil, last_updated_before: nil, next_token: nil) + @local_var_path = "/fba/inbound/v0/shipmentItems" + @query_params = { + "MarketplaceId" => marketplace_id, + "QueryType" => query_type, + } + @query_params["LastUpdatedAfter"] = last_updated_after unless last_updated_after.nil? + @query_params["LastUpdatedBefore"] = last_updated_before unless last_updated_before.nil? + @query_params["NextToken"] = next_token unless next_token.nil? + + @request_type = "GET" + call_api + end end end end diff --git a/spec/muffin_man/fulfillment_inbound/v0_spec.rb b/spec/muffin_man/fulfillment_inbound/v0_spec.rb index af5b05c..ea8aa27 100644 --- a/spec/muffin_man/fulfillment_inbound/v0_spec.rb +++ b/spec/muffin_man/fulfillment_inbound/v0_spec.rb @@ -213,4 +213,21 @@ expect(JSON.parse(response.body).dig("payload", "TransportResult", "TransportStatus")).not_to be_empty end end + + describe "get_shipment_items" do + before { stub_get_shipment_items } + let(:query_type) { "DATE_RANGE" } + let(:marketplace_id) { "ATVPDKIKX0DER" } + let(:last_updated_after) { "2022-09-30T00:00:00Z" } + let(:last_updated_before) { "2022-10-01T00:00:00Z" } + + it "makes a request to get shipment items with all parameters" do + response = fba_inbound_client.get_shipment_items(query_type, marketplace_id, + last_updated_after: last_updated_after, + last_updated_before: last_updated_before) + expect(response.response_code).to eq(200) + expect(JSON.parse(response.body).dig("payload", "ItemData")).not_to be_empty + expect(JSON.parse(response.body).dig("payload", "NextToken")).not_to be_nil + end + end end diff --git a/spec/support/sp_api_helpers.rb b/spec/support/sp_api_helpers.rb index 3371f8e..a939217 100644 --- a/spec/support/sp_api_helpers.rb +++ b/spec/support/sp_api_helpers.rb @@ -332,6 +332,11 @@ def stub_get_shipment_items_by_shipment_id .to_return(status: 200, body: File.read("./spec/support/get_shipment_items_by_shipment_id_v0.json"), headers: {}) end + def stub_get_shipment_items + stub_request(:get, "https://#{hostname}/fba/inbound/v0/shipmentItems?MarketplaceId=#{marketplace_id}&QueryType=#{query_type}&LastUpdatedAfter=#{last_updated_after}&LastUpdatedBefore=#{last_updated_before}") + .to_return(status: 200, body: File.read("./spec/support/get_shipment_items_by_shipment_id_v0.json"), headers: {}) + end + def stub_get_item_eligibility_preview stub_request(:get, "https://#{hostname}/fba/inbound/v1/eligibility/itemPreview?asin=#{asin}&program=#{program}") .to_return(status: 200, body: {"payload"=>{"asin"=>asin, "program"=>program, "isEligibleForProgram"=>true}}.to_json, headers: {})