Fall back to givin product id w/o retail variant

This commit is contained in:
Maikel Linke
2024-09-17 11:35:22 +10:00
parent fb96f8f936
commit 070b93c531
4 changed files with 25 additions and 201 deletions

View File

@@ -40,6 +40,9 @@ class FdcOfferBroker
def wholesale_to_retail(wholesale_product_id)
production_flow = flow_producing(wholesale_product_id)
return RetailSolution.new(wholesale_product_id, 1) if production_flow.nil?
consumption_flow = catalog_item(
production_flow.semanticId.sub("AsPlannedProductionFlow", "AsPlannedConsumptionFlow")
)

File diff suppressed because one or more lines are too long

View File

@@ -4,7 +4,9 @@ require 'spec_helper'
RSpec.describe FdcOfferBroker do
subject { FdcOfferBroker.new(catalog) }
let(:catalog) { BackorderJob.load_catalog(user, urls) }
let(:catalog) {
VCR.use_cassette(:fdc_catalog) { BackorderJob.load_catalog(user, urls) }
}
let(:urls) { FdcUrlBuilder.new(product_link) }
let(:product_link) {
"https://env-0105831.jcloud-ver-jpe.ik-server.com/api/dfc/Enterprises/test-hodmedod/SuppliedProducts/44519466467635"
@@ -15,7 +17,7 @@ RSpec.describe FdcOfferBroker do
}
describe ".best_offer" do
it "finds a linked wholesale offer", vcr: true do
it "finds a linked wholesale offer" do
solution = subject.best_offer(product.semanticId)
# These values depend on the test data but are a good sanity check:
@@ -25,7 +27,7 @@ RSpec.describe FdcOfferBroker do
expect(solution.offer.offeredItem).to eq solution.product
end
it "falls back to the original product offer", vcr: true do
it "falls back to the original product offer" do
solution = subject.best_offer(product.semanticId)
fallback_solution = subject.best_offer(solution.product.semanticId)
@@ -35,4 +37,21 @@ RSpec.describe FdcOfferBroker do
expect(fallback_solution.offer.offeredItem).to eq fallback_solution.product
end
end
describe ".wholesale_to_retail" do
it "finds a linked retail offer" do
offer_solution = subject.best_offer(product.semanticId)
retail_solution = subject.wholesale_to_retail(offer_solution.product.semanticId)
expect(retail_solution.retail_product_id).to eq product.semanticId
expect(retail_solution.factor).to eq 12
end
it "falls back to the wholesale product id" do
retail_solution = subject.wholesale_to_retail(product.semanticId)
expect(retail_solution.retail_product_id).to eq product.semanticId
expect(retail_solution.factor).to eq 1
end
end
end