mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-17 04:34:24 +00:00
Merge pull request #13049 from mkllnk/dfc-wholesale-stock
Calculate stock from DFC wholesale variants
This commit is contained in:
@@ -14,13 +14,14 @@ RSpec.describe CompleteBackorderJob do
|
||||
let(:orderer) { FdcBackorderer.new(user, urls) }
|
||||
let(:order) {
|
||||
backorder = orderer.find_or_build_order(ofn_order)
|
||||
broker = FdcOfferBroker.new(user, urls.catalog_url)
|
||||
catalog = DfcCatalog.load(user, urls.catalog_url)
|
||||
broker = FdcOfferBroker.new(catalog)
|
||||
|
||||
bean_offer = broker.best_offer(product_link).offer
|
||||
bean_line = orderer.find_or_build_order_line(backorder, bean_offer)
|
||||
bean_line.quantity = 3
|
||||
|
||||
chia = broker.catalog_item(chia_seed_retail_link)
|
||||
chia = catalog.item(chia_seed_retail_link)
|
||||
chia_offer = broker.offer_of(chia)
|
||||
chia_line = orderer.find_or_build_order_line(backorder, chia_offer)
|
||||
chia_line.quantity = 5
|
||||
|
||||
@@ -31,9 +31,9 @@ RSpec.describe FdcBackorderer do
|
||||
expect(backorder.lines).to eq []
|
||||
|
||||
# Add items and place the new order:
|
||||
catalog = FdcOfferBroker.load_catalog(order.distributor.owner, urls.catalog_url)
|
||||
product = catalog.find { |i| i.semanticType == "dfc-b:SuppliedProduct" }
|
||||
offer = FdcOfferBroker.new(nil, nil).offer_of(product)
|
||||
catalog = DfcCatalog.load(order.distributor.owner, urls.catalog_url)
|
||||
product = catalog.products.first
|
||||
offer = FdcOfferBroker.new(nil).offer_of(product)
|
||||
line = subject.find_or_build_order_line(backorder, offer)
|
||||
line.quantity = 3
|
||||
placed_order = subject.send_order(backorder)
|
||||
@@ -74,15 +74,14 @@ RSpec.describe FdcBackorderer do
|
||||
|
||||
describe "#find_or_build_order_line" do
|
||||
it "add quantity to an existing line item", vcr: true do
|
||||
catalog = FdcOfferBroker.load_catalog(order.distributor.owner, urls.catalog_url)
|
||||
catalog = DfcCatalog.load(order.distributor.owner, urls.catalog_url)
|
||||
backorder = subject.find_or_build_order(order)
|
||||
|
||||
expect(backorder.lines.count).to eq 0
|
||||
|
||||
# Add new item to the new order:
|
||||
catalog = FdcOfferBroker.load_catalog(order.distributor.owner, urls.catalog_url)
|
||||
product = catalog.find { |i| i.semanticType == "dfc-b:SuppliedProduct" }
|
||||
offer = FdcOfferBroker.new(nil, nil).offer_of(product)
|
||||
product = catalog.products.first
|
||||
offer = FdcOfferBroker.new(nil).offer_of(product)
|
||||
line = subject.find_or_build_order_line(backorder, offer)
|
||||
|
||||
expect(backorder.lines.count).to eq 1
|
||||
|
||||
@@ -3,9 +3,11 @@
|
||||
require 'spec_helper'
|
||||
|
||||
RSpec.describe FdcOfferBroker do
|
||||
subject { FdcOfferBroker.new(user, catalog_url) }
|
||||
subject { FdcOfferBroker.new(catalog) }
|
||||
let(:catalog) {
|
||||
VCR.use_cassette(:fdc_catalog) { subject.catalog }
|
||||
VCR.use_cassette(:fdc_catalog) {
|
||||
DfcCatalog.load(user, catalog_url)
|
||||
}
|
||||
}
|
||||
let(:catalog_url) {
|
||||
"https://env-0105831.jcloud-ver-jpe.ik-server.com/api/dfc/Enterprises/test-hodmedod/SuppliedProducts"
|
||||
@@ -15,7 +17,7 @@ RSpec.describe FdcOfferBroker do
|
||||
}
|
||||
let(:user) { build(:testdfc_user) }
|
||||
let(:product) {
|
||||
catalog.find { |item| item.semanticType == "dfc-b:SuppliedProduct" }
|
||||
catalog.products.first
|
||||
}
|
||||
|
||||
describe ".best_offer" do
|
||||
|
||||
Reference in New Issue
Block a user