mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
List enterprises within groups on DFC API
This commit is contained in:
@@ -20,10 +20,20 @@ class EnterpriseBuilder < DfcBuilder
|
||||
end
|
||||
|
||||
def self.enterprise_group(group)
|
||||
members = group.enterprises.map do |member|
|
||||
urls.enterprise_url(member.id)
|
||||
end
|
||||
|
||||
DataFoodConsortium::Connector::Enterprise.new(
|
||||
urls.enterprise_group_url(group.id),
|
||||
name: group.name,
|
||||
description: group.description,
|
||||
)
|
||||
).tap do |enterprise|
|
||||
# This property has been agreed by the DFC but hasn't made it's way into
|
||||
# the Connector yet.
|
||||
enterprise.registerSemanticProperty("dfc-b:affiliatedBy") do
|
||||
members
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,7 +4,13 @@ require_relative "../swagger_helper"
|
||||
|
||||
describe "EnterpriseGroups", type: :request, swagger_doc: "dfc.yaml", rswag_autodoc: true do
|
||||
let(:user) { create(:oidc_user) }
|
||||
let(:group) { create(:enterprise_group, id: 60_000) }
|
||||
let(:group) {
|
||||
create(
|
||||
:enterprise_group,
|
||||
id: 60_000, name: "Sustainable Farmers", enterprises: [enterprise],
|
||||
)
|
||||
}
|
||||
let(:enterprise) { create(:enterprise, id: 10_000) }
|
||||
|
||||
before { login_as user }
|
||||
|
||||
@@ -16,7 +22,12 @@ describe "EnterpriseGroups", type: :request, swagger_doc: "dfc.yaml", rswag_auto
|
||||
response "200", "successful" do
|
||||
let(:id) { group.id }
|
||||
|
||||
run_test!
|
||||
run_test! do
|
||||
expect(json_response).to include(
|
||||
"dfc-b:hasName" => "Sustainable Farmers",
|
||||
"dfc-b:affiliatedBy" => "http://test.host/api/dfc/enterprises/10000",
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -256,9 +256,10 @@ paths:
|
||||
"@context": https://www.datafoodconsortium.org
|
||||
"@id": http://test.host/api/dfc/enterprise_groups/60000
|
||||
"@type": dfc-b:Enterprise
|
||||
dfc-b:hasName: Enterprise group
|
||||
dfc-b:hasName: Sustainable Farmers
|
||||
dfc-b:hasDescription: this is a group
|
||||
dfc-b:VATnumber: ''
|
||||
dfc-b:affiliatedBy: http://test.host/api/dfc/enterprises/10000
|
||||
"/api/dfc/enterprises/{id}":
|
||||
get:
|
||||
summary: Show enterprise
|
||||
|
||||
Reference in New Issue
Block a user