Spec creating variant via DFC API

This commit is contained in:
Gaetan Craig-Riou
2024-03-06 16:20:32 +11:00
committed by Maikel Linke
parent 462c763cd1
commit a4b7a8f95d
2 changed files with 34 additions and 2 deletions

View File

@@ -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

View File

@@ -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