mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-17 00:07:24 +00:00
Link address to enterprise
+ spec
This commit is contained in:
committed by
Maikel Linke
parent
86bb77ab9f
commit
a8d15154a2
@@ -5,6 +5,7 @@ class EnterpriseBuilder < DfcBuilder
|
||||
variants = VariantFetcher.new(enterprise).scope.to_a
|
||||
catalog_items = variants.map(&method(:catalog_item))
|
||||
supplied_products = catalog_items.map(&:product)
|
||||
address = AddressBuilder.address(enterprise.address)
|
||||
|
||||
DataFoodConsortium::Connector::Enterprise.new(
|
||||
urls.enterprise_url(enterprise.id),
|
||||
@@ -13,6 +14,8 @@ class EnterpriseBuilder < DfcBuilder
|
||||
vatNumber: enterprise.abn,
|
||||
suppliedProducts: supplied_products,
|
||||
catalogItems: catalog_items
|
||||
)
|
||||
).tap do |e|
|
||||
e.addLocalization(address)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -9,6 +9,7 @@ describe "CatalogItems", type: :request, swagger_doc: "dfc-v1.7/swagger.yaml",
|
||||
create(
|
||||
:distributor_enterprise,
|
||||
id: 10_000, owner: user, name: "Fred's Farm", description: "Beautiful",
|
||||
address: build(:address, id: 40_000),
|
||||
)
|
||||
}
|
||||
let(:product) {
|
||||
|
||||
@@ -9,6 +9,7 @@ describe "Enterprises", type: :request, swagger_doc: "dfc-v1.7/swagger.yaml", rs
|
||||
:distributor_enterprise,
|
||||
id: 10_000, owner: user, abn: "123 456", name: "Fred's Farm",
|
||||
description: "This is an awesome enterprise",
|
||||
address: build(:address, id: 40_000),
|
||||
)
|
||||
end
|
||||
let!(:product) {
|
||||
|
||||
@@ -9,6 +9,7 @@ describe EnterpriseBuilder do
|
||||
:enterprise,
|
||||
id: 10_000, name: "Fabi's Farm",
|
||||
description: "The place where stuff grows", abn: "123 456 789 0",
|
||||
address: build(:address, city: "Melbourne"),
|
||||
)
|
||||
}
|
||||
let(:variant) {
|
||||
@@ -36,11 +37,16 @@ describe EnterpriseBuilder do
|
||||
expect(result.vatNumber).to eq "123 456 789 0"
|
||||
end
|
||||
|
||||
it "assignes products" do
|
||||
it "assigns products" do
|
||||
expect(variant).to be_persisted
|
||||
|
||||
expect(result.suppliedProducts.count).to eq 1
|
||||
expect(result.suppliedProducts[0].name).to eq "Apple"
|
||||
end
|
||||
|
||||
it "assigns an address" do
|
||||
expect(result.localizations.count).to eq 1
|
||||
expect(result.localizations[0].city).to eq "Melbourne"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -64,6 +64,7 @@ paths:
|
||||
dfc-b:affiliates: http://test.host/api/dfc-v1.7/enterprises/10000
|
||||
- "@id": http://test.host/api/dfc-v1.7/enterprises/10000
|
||||
"@type": dfc-b:Enterprise
|
||||
dfc-b:hasAddress: http://test.host/api/dfc-v1.7/address/40000
|
||||
dfc-b:hasName: Fred's Farm
|
||||
dfc-b:hasDescription: Beautiful
|
||||
dfc-b:supplies: http://test.host/api/dfc-v1.7/enterprises/10000/supplied_products/10001
|
||||
@@ -220,6 +221,7 @@ paths:
|
||||
"@graph":
|
||||
- "@id": http://test.host/api/dfc-v1.7/enterprises/10000
|
||||
"@type": dfc-b:Enterprise
|
||||
dfc-b:hasAddress: http://test.host/api/dfc-v1.7/address/40000
|
||||
dfc-b:hasName: Fred's Farm
|
||||
dfc-b:hasDescription: This is an awesome enterprise
|
||||
dfc-b:VATnumber: 123 456
|
||||
|
||||
Reference in New Issue
Block a user