From df3fc83c8ee5b95b6dd099086d1daeeb091059fb Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Tue, 5 Sep 2023 14:54:19 +1000 Subject: [PATCH] Remove version from DFC API URL in specs We were aiming to use stable URLs to identify resources but the URL helpers were still using dfc-v1.7 because that was the last and overriding path of the mounted DFC Provider engine. --- config/routes/api.rb | 6 +- .../spec/requests/addresses_spec.rb | 4 +- .../spec/requests/catalog_items_spec.rb | 4 +- .../spec/requests/enterprises_spec.rb | 2 +- .../spec/requests/persons_spec.rb | 2 +- .../spec/requests/supplied_products_spec.rb | 8 +-- .../spec/services/address_builder_spec.rb | 2 +- .../services/catalog_item_builder_spec.rb | 4 +- .../spec/services/enterprise_builder_spec.rb | 2 +- .../services/supplied_product_builder_spec.rb | 2 +- swagger/dfc.yaml | 72 +++++++++---------- 11 files changed, 54 insertions(+), 54 deletions(-) diff --git a/config/routes/api.rb b/config/routes/api.rb index f7310d93cd..a661c6f359 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -6,13 +6,13 @@ Openfoodnetwork::Application.routes.draw do # Mount DFC API endpoints # - # Latest implemented version: - mount DfcProvider::Engine, at: '/dfc/' - # The DFC prototype is still pointing to the old URL though: mount DfcProvider::Engine, at: '/dfc-v1.6/', as: :legacy_dfc_provider_engine mount DfcProvider::Engine, at: '/dfc-v1.7/', as: :v1_7_dfc_provider_engine + # Latest implemented version: + mount DfcProvider::Engine, at: '/dfc/' + namespace :v0 do resources :products do collection do diff --git a/engines/dfc_provider/spec/requests/addresses_spec.rb b/engines/dfc_provider/spec/requests/addresses_spec.rb index aa556e6a35..9848c9244b 100644 --- a/engines/dfc_provider/spec/requests/addresses_spec.rb +++ b/engines/dfc_provider/spec/requests/addresses_spec.rb @@ -9,7 +9,7 @@ describe "Addresses", type: :request, swagger_doc: "dfc.yaml", rswag_autodoc: tr before { login_as user } - path "/api/dfc-v1.7/addresses/{id}" do + path "/api/dfc/addresses/{id}" do get "Show address" do parameter name: :id, in: :path, type: :string produces "application/json" @@ -20,7 +20,7 @@ describe "Addresses", type: :request, swagger_doc: "dfc.yaml", rswag_autodoc: tr before { create(:enterprise, owner: user, address:) } run_test! do - expect(result["@id"]).to eq "http://test.host/api/dfc-v1.7/addresses/40000" + expect(result["@id"]).to eq "http://test.host/api/dfc/addresses/40000" expect(result["@type"]).to eq "dfc-b:Address" 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 4ed2e4f597..0d401f9090 100644 --- a/engines/dfc_provider/spec/requests/catalog_items_spec.rb +++ b/engines/dfc_provider/spec/requests/catalog_items_spec.rb @@ -23,7 +23,7 @@ describe "CatalogItems", type: :request, swagger_doc: "dfc.yaml", before { login_as user } - path "/api/dfc-v1.7/enterprises/{enterprise_id}/catalog_items" do + path "/api/dfc/enterprises/{enterprise_id}/catalog_items" do parameter name: :enterprise_id, in: :path, type: :string get "List CatalogItems" do @@ -77,7 +77,7 @@ describe "CatalogItems", type: :request, swagger_doc: "dfc.yaml", end end - path "/api/dfc-v1.7/enterprises/{enterprise_id}/catalog_items/{id}" do + path "/api/dfc/enterprises/{enterprise_id}/catalog_items/{id}" do parameter name: :enterprise_id, in: :path, type: :string parameter name: :id, in: :path, type: :string diff --git a/engines/dfc_provider/spec/requests/enterprises_spec.rb b/engines/dfc_provider/spec/requests/enterprises_spec.rb index d5d4e02bf1..ebe66f827b 100644 --- a/engines/dfc_provider/spec/requests/enterprises_spec.rb +++ b/engines/dfc_provider/spec/requests/enterprises_spec.rb @@ -23,7 +23,7 @@ describe "Enterprises", type: :request, swagger_doc: "dfc.yaml", rswag_autodoc: before { login_as user } - path "/api/dfc-v1.7/enterprises/{id}" do + path "/api/dfc/enterprises/{id}" do get "Show enterprise" do parameter name: :id, in: :path, type: :string produces "application/json" diff --git a/engines/dfc_provider/spec/requests/persons_spec.rb b/engines/dfc_provider/spec/requests/persons_spec.rb index 4981f15c95..8e03a7667e 100644 --- a/engines/dfc_provider/spec/requests/persons_spec.rb +++ b/engines/dfc_provider/spec/requests/persons_spec.rb @@ -8,7 +8,7 @@ describe "Persons", type: :request, swagger_doc: "dfc.yaml", rswag_autodoc: true before { login_as user } - path "/api/dfc-v1.7/persons/{id}" do + path "/api/dfc/persons/{id}" do get "Show person" do parameter name: :id, in: :path, type: :string produces "application/json" diff --git a/engines/dfc_provider/spec/requests/supplied_products_spec.rb b/engines/dfc_provider/spec/requests/supplied_products_spec.rb index dac8f8f7b8..b310fff021 100644 --- a/engines/dfc_provider/spec/requests/supplied_products_spec.rb +++ b/engines/dfc_provider/spec/requests/supplied_products_spec.rb @@ -17,7 +17,7 @@ describe "SuppliedProducts", type: :request, swagger_doc: "dfc.yaml", before { login_as user } - path "/api/dfc-v1.7/enterprises/{enterprise_id}/supplied_products" do + path "/api/dfc/enterprises/{enterprise_id}/supplied_products" do parameter name: :enterprise_id, in: :path, type: :string let(:enterprise_id) { enterprise.id } @@ -36,7 +36,7 @@ describe "SuppliedProducts", type: :request, swagger_doc: "dfc.yaml", '@type': "@id" }, }, - '@id': "http://test.host/api/dfc-v1.7/enterprises/6201/supplied_products/0", + '@id': "http://test.host/api/dfc/enterprises/6201/supplied_products/0", '@type': "dfc-b:SuppliedProduct", 'dfc-b:name': "Apple", 'dfc-b:description': "A delicious heritage apple", @@ -84,7 +84,7 @@ describe "SuppliedProducts", type: :request, swagger_doc: "dfc.yaml", dfc_id = json_response["@id"] expect(dfc_id).to match( - %r|^http://test\.host/api/dfc-v1\.7/enterprises/10000/supplied_products/[0-9]+$| + %r|^http://test\.host/api/dfc/enterprises/10000/supplied_products/[0-9]+$| ) variant_id = dfc_id.split("/").last.to_i @@ -102,7 +102,7 @@ describe "SuppliedProducts", type: :request, swagger_doc: "dfc.yaml", end end - path "/api/dfc-v1.7/enterprises/{enterprise_id}/supplied_products/{id}" do + path "/api/dfc/enterprises/{enterprise_id}/supplied_products/{id}" do parameter name: :enterprise_id, in: :path, type: :string parameter name: :id, in: :path, type: :string diff --git a/engines/dfc_provider/spec/services/address_builder_spec.rb b/engines/dfc_provider/spec/services/address_builder_spec.rb index 473f9c86fd..72fc0f08c0 100644 --- a/engines/dfc_provider/spec/services/address_builder_spec.rb +++ b/engines/dfc_provider/spec/services/address_builder_spec.rb @@ -14,7 +14,7 @@ describe AddressBuilder do describe ".address" do it "assigns a semantic id" do expect(result.semanticId).to eq( - "http://test.host/api/dfc-v1.7/addresses/1" + "http://test.host/api/dfc/addresses/1" ) end diff --git a/engines/dfc_provider/spec/services/catalog_item_builder_spec.rb b/engines/dfc_provider/spec/services/catalog_item_builder_spec.rb index 34faefe66a..ed80ac34a1 100644 --- a/engines/dfc_provider/spec/services/catalog_item_builder_spec.rb +++ b/engines/dfc_provider/spec/services/catalog_item_builder_spec.rb @@ -13,7 +13,7 @@ describe DfcBuilder do item = DfcBuilder.catalog_item(variant) expect(item.semanticId).to eq( - "http://test.host/api/dfc-v1.7/enterprises/7/catalog_items/5" + "http://test.host/api/dfc/enterprises/7/catalog_items/5" ) end @@ -24,7 +24,7 @@ describe DfcBuilder do item = DfcBuilder.catalog_item(variant) expect(item.product.semanticId).to eq( - "http://test.host/api/dfc-v1.7/enterprises/7/supplied_products/5" + "http://test.host/api/dfc/enterprises/7/supplied_products/5" ) end end diff --git a/engines/dfc_provider/spec/services/enterprise_builder_spec.rb b/engines/dfc_provider/spec/services/enterprise_builder_spec.rb index c7ecc8f76a..c1d4bf94a8 100644 --- a/engines/dfc_provider/spec/services/enterprise_builder_spec.rb +++ b/engines/dfc_provider/spec/services/enterprise_builder_spec.rb @@ -21,7 +21,7 @@ describe EnterpriseBuilder do it "assigns a semantic id" do expect(result.semanticId).to eq( - "http://test.host/api/dfc-v1.7/enterprises/10000" + "http://test.host/api/dfc/enterprises/10000" ) end diff --git a/engines/dfc_provider/spec/services/supplied_product_builder_spec.rb b/engines/dfc_provider/spec/services/supplied_product_builder_spec.rb index f656c707c1..53ac99f16a 100644 --- a/engines/dfc_provider/spec/services/supplied_product_builder_spec.rb +++ b/engines/dfc_provider/spec/services/supplied_product_builder_spec.rb @@ -13,7 +13,7 @@ describe SuppliedProductBuilder do product = builder.supplied_product(variant) expect(product.semanticId).to eq( - "http://test.host/api/dfc-v1.7/enterprises/7/supplied_products/5" + "http://test.host/api/dfc/enterprises/7/supplied_products/5" ) end diff --git a/swagger/dfc.yaml b/swagger/dfc.yaml index 197abe88f7..e0920b29c1 100644 --- a/swagger/dfc.yaml +++ b/swagger/dfc.yaml @@ -38,7 +38,7 @@ security: - ofn_api_token: [] - ofn_session: [] paths: - "/api/dfc-v1.7/addresses/{id}": + "/api/dfc/addresses/{id}": get: summary: Show address parameters: @@ -58,7 +58,7 @@ paths: test_example: value: "@context": https://www.datafoodconsortium.org - "@id": http://test.host/api/dfc-v1.7/addresses/40000 + "@id": http://test.host/api/dfc/addresses/40000 "@type": dfc-b:Address dfc-b:hasStreet: 10 Lovely Street dfc-b:hasPostalCode: '20170' @@ -66,7 +66,7 @@ paths: dfc-b:hasCountry: Australia '404': description: not found - "/api/dfc-v1.7/enterprises/{enterprise_id}/catalog_items": + "/api/dfc/enterprises/{enterprise_id}/catalog_items": parameters: - name: enterprise_id in: path @@ -89,23 +89,23 @@ paths: value: "@context": https://www.datafoodconsortium.org "@graph": - - "@id": http://test.host/api/dfc-v1.7/persons/12345 + - "@id": http://test.host/api/dfc/persons/12345 "@type": dfc-b:Person - dfc-b:affiliates: http://test.host/api/dfc-v1.7/enterprises/10000 - - "@id": http://test.host/api/dfc-v1.7/enterprises/10000 + dfc-b:affiliates: http://test.host/api/dfc/enterprises/10000 + - "@id": http://test.host/api/dfc/enterprises/10000 "@type": dfc-b:Enterprise - dfc-b:hasAddress: http://test.host/api/dfc-v1.7/addresses/40000 + dfc-b:hasAddress: http://test.host/api/dfc/addresses/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 - dfc-b:manages: http://test.host/api/dfc-v1.7/enterprises/10000/catalog_items/10001 - - "@id": http://test.host/api/dfc-v1.7/enterprises/10000/catalog_items/10001 + dfc-b:supplies: http://test.host/api/dfc/enterprises/10000/supplied_products/10001 + dfc-b:manages: http://test.host/api/dfc/enterprises/10000/catalog_items/10001 + - "@id": http://test.host/api/dfc/enterprises/10000/catalog_items/10001 "@type": dfc-b:CatalogItem - dfc-b:references: http://test.host/api/dfc-v1.7/enterprises/10000/supplied_products/10001 + dfc-b:references: http://test.host/api/dfc/enterprises/10000/supplied_products/10001 dfc-b:sku: AR dfc-b:stockLimitation: 0 - dfc-b:offeredThrough: http://test.host/api/dfc-v1.7/enterprises/10000/offers/10001 - - "@id": http://test.host/api/dfc-v1.7/enterprises/10000/supplied_products/10001 + dfc-b:offeredThrough: http://test.host/api/dfc/enterprises/10000/offers/10001 + - "@id": http://test.host/api/dfc/enterprises/10000/supplied_products/10001 "@type": dfc-b:SuppliedProduct dfc-b:name: Apple dfc-b:description: Red @@ -118,13 +118,13 @@ paths: dfc-b:lifetime: '' dfc-b:usageOrStorageCondition: '' dfc-b:totalTheoreticalStock: 0.0 - - "@id": http://test.host/api/dfc-v1.7/enterprises/10000/offers/10001 + - "@id": http://test.host/api/dfc/enterprises/10000/offers/10001 "@type": dfc-b:Offer dfc-b:price: 19.99 dfc-b:stockLimitation: 0 '401': description: unauthorized - "/api/dfc-v1.7/enterprises/{enterprise_id}/catalog_items/{id}": + "/api/dfc/enterprises/{enterprise_id}/catalog_items/{id}": parameters: - name: enterprise_id in: path @@ -150,13 +150,13 @@ paths: value: "@context": https://www.datafoodconsortium.org "@graph": - - "@id": http://test.host/api/dfc-v1.7/enterprises/10000/catalog_items/10001 + - "@id": http://test.host/api/dfc/enterprises/10000/catalog_items/10001 "@type": dfc-b:CatalogItem - dfc-b:references: http://test.host/api/dfc-v1.7/enterprises/10000/supplied_products/10001 + dfc-b:references: http://test.host/api/dfc/enterprises/10000/supplied_products/10001 dfc-b:sku: AR dfc-b:stockLimitation: 0 - dfc-b:offeredThrough: http://test.host/api/dfc-v1.7/enterprises/10000/offers/10001 - - "@id": http://test.host/api/dfc-v1.7/enterprises/10000/offers/10001 + dfc-b:offeredThrough: http://test.host/api/dfc/enterprises/10000/offers/10001 + - "@id": http://test.host/api/dfc/enterprises/10000/offers/10001 "@type": dfc-b:Offer dfc-b:price: 19.99 dfc-b:stockLimitation: 0 @@ -234,7 +234,7 @@ paths: "@type": "@id" dfc-b:stockLimitation: '3' dfc-b:sku: new-sku - "/api/dfc-v1.7/enterprises/{id}": + "/api/dfc/enterprises/{id}": get: summary: Show enterprise parameters: @@ -255,21 +255,21 @@ paths: value: "@context": https://www.datafoodconsortium.org "@graph": - - "@id": http://test.host/api/dfc-v1.7/enterprises/10000 + - "@id": http://test.host/api/dfc/enterprises/10000 "@type": dfc-b:Enterprise - dfc-b:hasAddress: http://test.host/api/dfc-v1.7/addresses/40000 + dfc-b:hasAddress: http://test.host/api/dfc/addresses/40000 dfc-b:hasName: Fred's Farm dfc-b:hasDescription: This is an awesome enterprise dfc-b:VATnumber: 123 456 - dfc-b:supplies: http://test.host/api/dfc-v1.7/enterprises/10000/supplied_products/10001 - dfc-b:manages: http://test.host/api/dfc-v1.7/enterprises/10000/catalog_items/10001 - - "@id": http://test.host/api/dfc-v1.7/addresses/40000 + dfc-b:supplies: http://test.host/api/dfc/enterprises/10000/supplied_products/10001 + dfc-b:manages: http://test.host/api/dfc/enterprises/10000/catalog_items/10001 + - "@id": http://test.host/api/dfc/addresses/40000 "@type": dfc-b:Address dfc-b:hasStreet: 42 Doveton Street dfc-b:hasPostalCode: '20170' dfc-b:hasCity: Herndon dfc-b:hasCountry: Australia - - "@id": http://test.host/api/dfc-v1.7/enterprises/10000/supplied_products/10001 + - "@id": http://test.host/api/dfc/enterprises/10000/supplied_products/10001 "@type": dfc-b:SuppliedProduct dfc-b:name: Apple dfc-b:description: Round @@ -282,15 +282,15 @@ paths: dfc-b:lifetime: '' dfc-b:usageOrStorageCondition: '' dfc-b:totalTheoreticalStock: 0.0 - - "@id": http://test.host/api/dfc-v1.7/enterprises/10000/catalog_items/10001 + - "@id": http://test.host/api/dfc/enterprises/10000/catalog_items/10001 "@type": dfc-b:CatalogItem - dfc-b:references: http://test.host/api/dfc-v1.7/enterprises/10000/supplied_products/10001 + dfc-b:references: http://test.host/api/dfc/enterprises/10000/supplied_products/10001 dfc-b:sku: APP dfc-b:stockLimitation: 0 - dfc-b:offeredThrough: http://test.host/api/dfc-v1.7/enterprises/10000/offers/10001 + dfc-b:offeredThrough: http://test.host/api/dfc/enterprises/10000/offers/10001 '404': description: not found - "/api/dfc-v1.7/persons/{id}": + "/api/dfc/persons/{id}": get: summary: Show person parameters: @@ -310,11 +310,11 @@ paths: test_example: value: "@context": https://www.datafoodconsortium.org - "@id": http://test.host/api/dfc-v1.7/persons/10000 + "@id": http://test.host/api/dfc/persons/10000 "@type": dfc-b:Person '404': description: not found - "/api/dfc-v1.7/enterprises/{enterprise_id}/supplied_products": + "/api/dfc/enterprises/{enterprise_id}/supplied_products": parameters: - name: enterprise_id in: path @@ -337,7 +337,7 @@ paths: test_example: value: "@context": https://www.datafoodconsortium.org - "@id": http://test.host/api/dfc-v1.7/enterprises/10000/supplied_products/10001 + "@id": http://test.host/api/dfc/enterprises/10000/supplied_products/10001 "@type": dfc-b:SuppliedProduct dfc-b:name: Apple dfc-b:description: A delicious heritage apple @@ -361,7 +361,7 @@ paths: dfc-pt: http://static.datafoodconsortium.org/data/productTypes.rdf# dfc-b:hasUnit: "@type": "@id" - "@id": http://test.host/api/dfc-v1.7/enterprises/6201/supplied_products/0 + "@id": http://test.host/api/dfc/enterprises/6201/supplied_products/0 "@type": dfc-b:SuppliedProduct dfc-b:name: Apple dfc-b:description: A delicious heritage apple @@ -374,7 +374,7 @@ paths: dfc-b:lifetime: '' dfc-b:usageOrStorageCondition: '' dfc-b:totalTheoreticalStock: 0.0 - "/api/dfc-v1.7/enterprises/{enterprise_id}/supplied_products/{id}": + "/api/dfc/enterprises/{enterprise_id}/supplied_products/{id}": parameters: - name: enterprise_id in: path @@ -399,7 +399,7 @@ paths: test_example: value: "@context": https://www.datafoodconsortium.org - "@id": http://test.host/api/dfc-v1.7/enterprises/10000/supplied_products/10001 + "@id": http://test.host/api/dfc/enterprises/10000/supplied_products/10001 "@type": dfc-b:SuppliedProduct dfc-b:name: Pesto dfc-b:description: Basil Pesto