mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-26 01:33:22 +00:00
Respond with SuppliedProduct data when creating
This commit is contained in:
@@ -16,6 +16,11 @@ module DfcProvider
|
||||
product = SuppliedProductBuilder.import(supplied_product)
|
||||
product.supplier = current_enterprise
|
||||
product.save!
|
||||
|
||||
supplied_product = SuppliedProductBuilder.supplied_product(
|
||||
product.variants.first
|
||||
)
|
||||
render json: DfcLoader.connector.export(supplied_product)
|
||||
end
|
||||
|
||||
def show
|
||||
|
||||
@@ -52,20 +52,30 @@ describe "SuppliedProducts", type: :request, swagger_doc: "dfc-v1.7/swagger.yaml
|
||||
run_test!
|
||||
end
|
||||
|
||||
response "204", "success" do
|
||||
response "200", "success" do
|
||||
let(:supplied_product) do |example|
|
||||
example.metadata[:operation][:parameters].first[:schema][:example]
|
||||
end
|
||||
|
||||
it "creates a variant" do |example|
|
||||
existing = Spree::Variant.pluck(:id)
|
||||
|
||||
expect { submit_request(example.metadata) }
|
||||
.to change { enterprise.supplied_products.count }.by(1)
|
||||
|
||||
variant = Spree::Variant.where.not(id: existing).first
|
||||
dfc_id = json_response["@id"]
|
||||
expect(dfc_id).to match(
|
||||
%r|^http://test\.host/api/dfc-v1\.7/enterprises/10000/supplied_products/[0-9]+$|
|
||||
)
|
||||
|
||||
variant_id = dfc_id.split("/").last.to_i
|
||||
variant = Spree::Variant.find(variant_id)
|
||||
expect(variant.name).to eq "Apple"
|
||||
expect(variant.unit_value).to eq 3
|
||||
|
||||
# Insert static value to keep documentation deterministic:
|
||||
response.body.gsub!(
|
||||
"supplied_products/#{variant_id}",
|
||||
"supplied_products/10001"
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -269,8 +269,27 @@ paths:
|
||||
responses:
|
||||
'400':
|
||||
description: bad request
|
||||
'204':
|
||||
'200':
|
||||
description: success
|
||||
content:
|
||||
application/json:
|
||||
examples:
|
||||
test_example:
|
||||
value:
|
||||
"@context": http://static.datafoodconsortium.org/ontologies/context.json
|
||||
"@id": http://test.host/api/dfc-v1.7/enterprises/10000/supplied_products/10001
|
||||
"@type": dfc-b:SuppliedProduct
|
||||
dfc-b:name: Apple
|
||||
dfc-b:description: A delicious heritage apple
|
||||
dfc-b:hasType: dfc-pt:non-local-vegetable
|
||||
dfc-b:hasQuantity:
|
||||
"@type": dfc-b:QuantitativeValue
|
||||
dfc-b:hasUnit: dfc-m:Piece
|
||||
dfc-b:value: 3.0
|
||||
dfc-b:alcoholPercentage: 0.0
|
||||
dfc-b:lifetime: ''
|
||||
dfc-b:usageOrStorageCondition: ''
|
||||
dfc-b:totalTheoreticalStock: 0.0
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
|
||||
Reference in New Issue
Block a user