mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-26 01:33:22 +00:00
Spec DFC Connector import behaviour around context
The DFC updated the URLs in their context, basically changing the ids of all data types. I'll add a hacky workaround in the next commit.
This commit is contained in:
@@ -93,6 +93,8 @@ Naming/VariableNumber:
|
||||
AllowedIdentifiers:
|
||||
- street_address_1
|
||||
- street_address_2
|
||||
AllowedPatterns:
|
||||
- _v[\d]+
|
||||
|
||||
Bundler/DuplicatedGem:
|
||||
Enabled: false
|
||||
|
||||
@@ -25,6 +25,59 @@ describe DataFoodConsortium::Connector::Importer, vcr: true do
|
||||
totalTheoreticalStock: 3,
|
||||
)
|
||||
end
|
||||
let(:product_data) do
|
||||
<<~JSON
|
||||
{
|
||||
"@context":"http://static.datafoodconsortium.org/ontologies/context.json",
|
||||
"@id":"https://example.net/tomato",
|
||||
"@type":"dfc-b:SuppliedProduct",
|
||||
"dfc-b:name":"Tomato",
|
||||
"dfc-b:description":"Awesome tomato",
|
||||
"dfc-b:alcoholPercentage":0.0,
|
||||
"dfc-b:lifetime":"",
|
||||
"dfc-b:usageOrStorageCondition":"",
|
||||
"dfc-b:totalTheoreticalStock":3
|
||||
}
|
||||
JSON
|
||||
end
|
||||
let(:product_data_with_context) do
|
||||
<<~JSON
|
||||
{
|
||||
"@context": {
|
||||
"dfc-b": "http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#",
|
||||
"dfc-m": "http://static.datafoodconsortium.org/data/measures.rdf#",
|
||||
"dfc-pt": "http://static.datafoodconsortium.org/data/productTypes.rdf#"
|
||||
},
|
||||
"@id":"https://example.net/tomato",
|
||||
"@type":"dfc-b:SuppliedProduct",
|
||||
"dfc-b:name":"Tomato",
|
||||
"dfc-b:description":"Awesome tomato",
|
||||
"dfc-b:alcoholPercentage":0.0,
|
||||
"dfc-b:lifetime":"",
|
||||
"dfc-b:usageOrStorageCondition":"",
|
||||
"dfc-b:totalTheoreticalStock":3
|
||||
}
|
||||
JSON
|
||||
end
|
||||
let(:product_data_with_context_v1_8) do
|
||||
<<~JSON
|
||||
{
|
||||
"@context": {
|
||||
"dfc-b": "https://github.com/datafoodconsortium/ontology/releases/latest/download/DFC_BusinessOntology.owl#",
|
||||
"dfc-m": "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/measures.rdf#",
|
||||
"dfc-pt": "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/productTypes.rdf#"
|
||||
},
|
||||
"@id":"https://example.net/tomato",
|
||||
"@type":"dfc-b:SuppliedProduct",
|
||||
"dfc-b:name":"Tomato",
|
||||
"dfc-b:description":"Awesome tomato",
|
||||
"dfc-b:alcoholPercentage":0.0,
|
||||
"dfc-b:lifetime":"",
|
||||
"dfc-b:usageOrStorageCondition":"",
|
||||
"dfc-b:totalTheoreticalStock":3
|
||||
}
|
||||
JSON
|
||||
end
|
||||
let(:second_product) do
|
||||
DataFoodConsortium::Connector::SuppliedProduct.new(
|
||||
"https://example.net/ocra",
|
||||
@@ -55,6 +108,39 @@ describe DataFoodConsortium::Connector::Importer, vcr: true do
|
||||
expect(result.totalTheoreticalStock).to eq 3
|
||||
end
|
||||
|
||||
it "imports an object with referenced context" do
|
||||
result = connector.import(product_data)
|
||||
|
||||
expect(result.class).to eq DataFoodConsortium::Connector::SuppliedProduct
|
||||
expect(result.semanticType).to eq "http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#SuppliedProduct"
|
||||
expect(result.semanticId).to eq "https://example.net/tomato"
|
||||
expect(result.name).to eq "Tomato"
|
||||
expect(result.description).to eq "Awesome tomato"
|
||||
expect(result.totalTheoreticalStock).to eq 3
|
||||
end
|
||||
|
||||
it "imports an object with included context" do
|
||||
result = connector.import(product_data_with_context)
|
||||
|
||||
expect(result.class).to eq DataFoodConsortium::Connector::SuppliedProduct
|
||||
expect(result.semanticType).to eq "http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#SuppliedProduct"
|
||||
expect(result.semanticId).to eq "https://example.net/tomato"
|
||||
expect(result.name).to eq "Tomato"
|
||||
expect(result.description).to eq "Awesome tomato"
|
||||
expect(result.totalTheoreticalStock).to eq 3
|
||||
end
|
||||
|
||||
xit "imports an object with DFC v1.8 context" do
|
||||
result = connector.import(product_data_with_context_v1_8)
|
||||
|
||||
expect(result.class).to eq DataFoodConsortium::Connector::SuppliedProduct
|
||||
expect(result.semanticType).to eq "http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#SuppliedProduct"
|
||||
expect(result.semanticId).to eq "https://example.net/tomato"
|
||||
expect(result.name).to eq "Tomato"
|
||||
expect(result.description).to eq "Awesome tomato"
|
||||
expect(result.totalTheoreticalStock).to eq 3
|
||||
end
|
||||
|
||||
it "imports a graph with multiple objects" do
|
||||
result = import(catalog_item, product)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user