mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Test that the FDC is now complying with the DFC
This commit is contained in:
@@ -1,33 +1,10 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "private_address_check"
|
||||
require "private_address_check/tcpsocket_ext"
|
||||
|
||||
# Request a JSON document from the FDC API with authentication.
|
||||
#
|
||||
# Currently, the API doesn't quite comply with the DFC standard and we need
|
||||
# to authenticate a little bit differently.
|
||||
# This class was created when the FDC didn't comply with the DFC standard.
|
||||
# But now it does and this class is empty. :-)
|
||||
#
|
||||
# And then we get slightly different data as well.
|
||||
# We can delete this in the next commit.
|
||||
class FdcRequest < DfcRequest
|
||||
# Override main method to POST authorization data.
|
||||
def call(url, data = {})
|
||||
response = request(url, auth_data.merge(data).to_json)
|
||||
|
||||
if response.status >= 400 && token_stale?
|
||||
refresh_access_token!
|
||||
response = request(url, auth_data.merge(data).to_json)
|
||||
end
|
||||
|
||||
response.body
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def auth_data
|
||||
{
|
||||
userId: @user.oidc_account.uid,
|
||||
accessToken: @user.oidc_account.token,
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -8,7 +8,7 @@ RSpec.describe FdcRequest do
|
||||
let(:user) { build(:oidc_user) }
|
||||
let(:account) { user.oidc_account }
|
||||
let(:url) {
|
||||
"https://food-data-collaboration-produc-fe870152f634.herokuapp.com/fdc/products?shop=test-hodmedod.myshopify.com"
|
||||
"https://env-0105831.jcloud-ver-jpe.ik-server.com/api/dfc/Enterprises/test-hodmedod/SuppliedProducts"
|
||||
}
|
||||
|
||||
it "refreshes the access token and retrieves a catalog", vcr: true do
|
||||
@@ -27,9 +27,8 @@ RSpec.describe FdcRequest do
|
||||
}
|
||||
|
||||
json = JSON.parse(response)
|
||||
expect(json["message"]).to eq "Products retrieved successfully"
|
||||
|
||||
graph = DfcIo.import(json["products"])
|
||||
graph = DfcIo.import(json)
|
||||
products = graph.select { |s| s.semanticType == "dfc-b:SuppliedProduct" }
|
||||
expect(products).to be_present
|
||||
end
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -53,7 +53,7 @@ RSpec.describe "DFC Product Import" do
|
||||
|
||||
select enterprise.name, from: "Enterprise"
|
||||
|
||||
url = "https://food-data-collaboration-produc-fe870152f634.herokuapp.com/fdc/products?shop=test-hodmedod.myshopify.com"
|
||||
url = "https://env-0105831.jcloud-ver-jpe.ik-server.com/api/dfc/Enterprises/test-hodmedod/SuppliedProducts"
|
||||
fill_in "catalog_url", with: url
|
||||
|
||||
expect {
|
||||
|
||||
Reference in New Issue
Block a user