diff --git a/engines/dfc_provider/spec/requests/supplied_products_spec.rb b/engines/dfc_provider/spec/requests/supplied_products_spec.rb index 8ca59d0d84..6f22460e03 100644 --- a/engines/dfc_provider/spec/requests/supplied_products_spec.rb +++ b/engines/dfc_provider/spec/requests/supplied_products_spec.rb @@ -142,6 +142,36 @@ describe "SuppliedProducts", type: :request, swagger_doc: "dfc.yaml", rswag_auto '"ofn:spree_product_id":90000' ) end + + context "when supplying spree_product_uri matching the host" do + it "creates a variant for the existing product" do |example| + supplied_product[:'ofn:spree_product_uri'] = + "http://test.host/api/dfc/enterprises/10000?spree_product_id=90000" + supplied_product[:'dfc-b:hasQuantity'][:'dfc-b:value'] = 6 + + expect { + submit_request(example.metadata) + product.variants.reload + } + .to change { product.variants.count }.by(1) + + # Creates a variant for existing product + variant_id = json_response["@id"].split("/").last.to_i + new_variant = Spree::Variant.find(variant_id) + expect(product.variants).to include(new_variant) + expect(new_variant.unit_value).to eq 6 + + # Insert static value to keep documentation deterministic: + response.body.gsub!( + "supplied_products/#{variant_id}", + "supplied_products/10001" + ) + .gsub!( + %r{active_storage/[0-9A-Za-z/=-]*/logo-white.png}, + "active_storage/url/logo-white.png", + ) + end + end end end end diff --git a/swagger/dfc.yaml b/swagger/dfc.yaml index acddec3237..ba441c7dd7 100644 --- a/swagger/dfc.yaml +++ b/swagger/dfc.yaml @@ -542,7 +542,7 @@ paths: "@context": https://www.datafoodconsortium.org "@id": http://test.host/api/dfc/enterprises/10000/supplied_products/10001 "@type": dfc-b:SuppliedProduct - dfc-b:name: Apple (6g) + dfc-b:name: Pesto - Apple (6g) dfc-b:description: A delicious heritage apple dfc-b:hasType: dfc-pt:non-local-vegetable dfc-b:hasQuantity: @@ -554,7 +554,8 @@ paths: dfc-b:usageOrStorageCondition: '' dfc-b:totalTheoreticalStock: 0.0 ofn:spree_product_id: 90000 - ofn:spree_product_uri: http://test.host/api/dfc/enterprises/10000?spree_product_id=142 + ofn:spree_product_uri: http://test.host/api/dfc/enterprises/10000?spree_product_id=90000 + ofn:image: http://test.host/rails/active_storage/url/logo-white.png requestBody: content: application/json: @@ -575,6 +576,7 @@ paths: dfc-b:usageOrStorageCondition: '' dfc-b:totalTheoreticalStock: 0.0 ofn:spree_product_id: 90000 + ofn:spree_product_uri: http://test.host/api/dfc/enterprises/10000?spree_product_id=90000 "/api/dfc/enterprises/{enterprise_id}/supplied_products/{id}": parameters: - name: enterprise_id