diff --git a/engines/dfc_provider/app/services/enterprise_builder.rb b/engines/dfc_provider/app/services/enterprise_builder.rb index 742d8d8f4f..3ac8d0c4fc 100644 --- a/engines/dfc_provider/app/services/enterprise_builder.rb +++ b/engines/dfc_provider/app/services/enterprise_builder.rb @@ -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 diff --git a/engines/dfc_provider/spec/requests/catalog_items_spec.rb b/engines/dfc_provider/spec/requests/catalog_items_spec.rb index 268ba783eb..2d78ab765a 100644 --- a/engines/dfc_provider/spec/requests/catalog_items_spec.rb +++ b/engines/dfc_provider/spec/requests/catalog_items_spec.rb @@ -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) { diff --git a/engines/dfc_provider/spec/requests/enterprises_spec.rb b/engines/dfc_provider/spec/requests/enterprises_spec.rb index a7eaccb4e1..107a3d7347 100644 --- a/engines/dfc_provider/spec/requests/enterprises_spec.rb +++ b/engines/dfc_provider/spec/requests/enterprises_spec.rb @@ -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) { diff --git a/engines/dfc_provider/spec/services/enterprise_builder_spec.rb b/engines/dfc_provider/spec/services/enterprise_builder_spec.rb index e2e7e694f7..932e066212 100644 --- a/engines/dfc_provider/spec/services/enterprise_builder_spec.rb +++ b/engines/dfc_provider/spec/services/enterprise_builder_spec.rb @@ -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 diff --git a/swagger/dfc-v1.7/swagger.yaml b/swagger/dfc-v1.7/swagger.yaml index 72260b02e9..66299f0456 100644 --- a/swagger/dfc-v1.7/swagger.yaml +++ b/swagger/dfc-v1.7/swagger.yaml @@ -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