Include address when showing group

It may be nice to show more data like social media URLs but the DFC
Connector hasn't implemented that yet and it's not specified in the
current issue.
This commit is contained in:
Maikel Linke
2023-09-07 15:06:53 +10:00
parent 88a3615de7
commit 7e222ad83e
3 changed files with 29 additions and 9 deletions

View File

@@ -15,8 +15,10 @@ module DfcProvider
def show
group = EnterpriseGroup.find(params[:id])
address = AddressBuilder.address(group.address)
enterprise = EnterpriseBuilder.enterprise_group(group)
render json: DfcIo.export(enterprise)
enterprise.addLocalization(address)
render json: DfcIo.export(enterprise, address)
end
end
end

View File

@@ -7,10 +7,11 @@ describe "EnterpriseGroups", type: :request, swagger_doc: "dfc.yaml", rswag_auto
let(:group) {
create(
:enterprise_group,
id: 60_000, owner: user, name: "Sustainable Farmers",
id: 60_000, owner: user, name: "Sustainable Farmers", address:,
enterprises: [enterprise],
)
}
let(:address) { create(:address, id: 40_000, address1: "8 Acres Drive") }
let(:enterprise) { create(:enterprise, id: 10_000) }
before { login_as user }
@@ -49,10 +50,19 @@ describe "EnterpriseGroups", type: :request, swagger_doc: "dfc.yaml", rswag_auto
let(:id) { group.id }
run_test! do
expect(json_response).to include(
graph = json_response["@graph"]
expect(graph[0]).to include(
"@type" => "dfc-b:Enterprise",
"dfc-b:hasName" => "Sustainable Farmers",
"dfc-b:hasAddress" => "http://test.host/api/dfc/addresses/40000",
"dfc-b:affiliatedBy" => "http://test.host/api/dfc/enterprises/10000",
)
expect(graph[1]).to include(
"@type" => "dfc-b:Address",
"dfc-b:hasStreet" => "8 Acres Drive",
)
end
end
end

View File

@@ -278,12 +278,20 @@ paths:
test_example:
value:
"@context": https://www.datafoodconsortium.org
"@id": http://test.host/api/dfc/enterprise_groups/60000
"@type": dfc-b:Enterprise
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
"@graph":
- "@id": http://test.host/api/dfc/enterprise_groups/60000
"@type": dfc-b:Enterprise
dfc-b:hasAddress: http://test.host/api/dfc/addresses/40000
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
- "@id": http://test.host/api/dfc/addresses/40000
"@type": dfc-b:Address
dfc-b:hasStreet: 8 Acres Drive
dfc-b:hasPostalCode: '20170'
dfc-b:hasCity: Herndon
dfc-b:hasCountry: Australia
"/api/dfc/enterprises/{id}":
get:
summary: Show enterprise