mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-03 22:06:07 +00:00
Add DFC product update action, not implemented
This commit is contained in:
@@ -10,6 +10,13 @@ module DfcProvider
|
||||
render json: variant, serializer: DfcProvider::SuppliedProductSerializer
|
||||
end
|
||||
|
||||
def update
|
||||
dfc_request = JSON.parse(request.body.read)
|
||||
return unless dfc_request.key?("dfc-b:description")
|
||||
|
||||
variant.product.update!(name: dfc_request["dfc-b:description"])
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def variant
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
DfcProvider::Engine.routes.draw do
|
||||
resources :enterprises, only: [:show] do
|
||||
resources :catalog_items, only: [:index, :show]
|
||||
resources :supplied_products, only: [:show]
|
||||
resources :supplied_products, only: [:show, :update]
|
||||
end
|
||||
resources :persons, only: [:show]
|
||||
end
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'spec_helper'
|
||||
require DfcProvider::Engine.root.join("spec/spec_helper")
|
||||
|
||||
describe DfcProvider::SuppliedProductsController, type: :controller do
|
||||
include AuthorizationHelper
|
||||
|
||||
render_views
|
||||
|
||||
let!(:user) { create(:user) }
|
||||
@@ -49,4 +51,30 @@ describe DfcProvider::SuppliedProductsController, type: :controller do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#update" do
|
||||
routes { DfcProvider::Engine.routes }
|
||||
|
||||
it "requires authorisation" do
|
||||
api_put :update, enterprise_id: "default", id: "0"
|
||||
expect(response).to have_http_status :unauthorized
|
||||
end
|
||||
|
||||
describe "with authorisation" do
|
||||
before { authorise user.email }
|
||||
|
||||
it "updates the variant's name" do
|
||||
params = { enterprise_id: enterprise.id, id: variant.id }
|
||||
request_body = File.read(File.join(__dir__, "../../support/patch_product.json"))
|
||||
|
||||
expect {
|
||||
put(:update, params: params, body: request_body)
|
||||
expect(response).to have_http_status :success
|
||||
variant.reload
|
||||
}.to change {
|
||||
variant.name
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
88
engines/dfc_provider/spec/support/patch_product.json
Normal file
88
engines/dfc_provider/spec/support/patch_product.json
Normal file
@@ -0,0 +1,88 @@
|
||||
{
|
||||
"@context": {
|
||||
"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
|
||||
"skos": "http://www.w3.org/2004/02/skos/core#",
|
||||
"dfc": "http://static.datafoodconsortium.org/ontologies/DFC_FullModel.owl#",
|
||||
"dc": "http://purl.org/dc/elements/1.1/#",
|
||||
"dfc-b": "http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#",
|
||||
"dfc-p": "http://static.datafoodconsortium.org/ontologies/DFC_ProductOntology.owl#",
|
||||
"dfc-t": "http://static.datafoodconsortium.org/ontologies/DFC_TechnicalOntology.owl#",
|
||||
"dfc-u": "http://static.datafoodconsortium.org/data/units.rdf#",
|
||||
"dfc-pt": "http://static.datafoodconsortium.org/data/productTypes.rdf#",
|
||||
"dfc-a": "http://static.datafoodconsortium.org/data/claims.rdf#",
|
||||
"dfc-d": "http://static.datafoodconsortium.org/data/dimensions.rdf#",
|
||||
"dfc-c": "http://static.datafoodconsortium.org/data/certifications.rdf#",
|
||||
"dfc-g": "http://static.datafoodconsortium.org/data/geoOrigin.rdf#",
|
||||
"dfc-p:hasUnit": {
|
||||
"@type": "@id"
|
||||
},
|
||||
"dfc-b:hasUnit": {
|
||||
"@type": "@id"
|
||||
},
|
||||
"dfc-b:hasQuantity": {
|
||||
"@type": "@id"
|
||||
},
|
||||
"dfc-p:hasType": {
|
||||
"@type": "@id"
|
||||
},
|
||||
"dfc-b:hasType": {
|
||||
"@type": "@id"
|
||||
},
|
||||
"dfc-b:references": {
|
||||
"@type": "@id"
|
||||
},
|
||||
"dfc-b:referencedBy": {
|
||||
"@type": "@id"
|
||||
},
|
||||
"dfc-b:offeres": {
|
||||
"@type": "@id"
|
||||
},
|
||||
"dfc-b:supplies": {
|
||||
"@type": "@id"
|
||||
},
|
||||
"dfc-b:defines": {
|
||||
"@type": "@id"
|
||||
},
|
||||
"dfc-b:affiliates": {
|
||||
"@type": "@id"
|
||||
},
|
||||
"dfc-b:manages": {
|
||||
"@type": "@id"
|
||||
},
|
||||
"dfc-b:offeredThrough": {
|
||||
"@type": "@id"
|
||||
},
|
||||
"dfc-b:hasBrand": {
|
||||
"@type": "@id"
|
||||
},
|
||||
"dfc-b:hasGeographicalOrigin": {
|
||||
"@type": "@id"
|
||||
},
|
||||
"dfc-b:hasClaim": {
|
||||
"@type": "@id"
|
||||
},
|
||||
"dfc-b:hasAllergenDimension": {
|
||||
"@type": "@id"
|
||||
},
|
||||
"dfc-b:hasNutrimentDimension": {
|
||||
"@type": "@id"
|
||||
},
|
||||
"dfc-b:hasPhysicalDimension": {
|
||||
"@type": "@id"
|
||||
},
|
||||
"dfc:owner": {
|
||||
"@type": "@id"
|
||||
},
|
||||
"dfc-t:hostedBy": {
|
||||
"@type": "@id"
|
||||
},
|
||||
"dfc-t:hasPivot": {
|
||||
"@type": "@id"
|
||||
},
|
||||
"dfc-t:represent": {
|
||||
"@type": "@id"
|
||||
}
|
||||
},
|
||||
"dfc-b:description": "DFC-Pesto updated",
|
||||
"dfc-b:quantity": 0
|
||||
}
|
||||
Reference in New Issue
Block a user