Remove superfluous FDC-specific request class

This commit is contained in:
Maikel Linke
2024-08-02 15:38:12 +10:00
parent 6d03a8ddf3
commit ec828c335d
5 changed files with 39 additions and 66 deletions

View File

@@ -35,13 +35,7 @@ module Admin
private
def fetch_catalog(url)
if url =~ /food-data-collaboration/
fdc_json = FdcRequest.new(spree_current_user).call(url)
fdc_message = JSON.parse(fdc_json)
fdc_message["products"]
else
DfcRequest.new(spree_current_user).call(url)
end
DfcRequest.new(spree_current_user).call(url)
end
# Most of this code is the same as in the DfcProvider::SuppliedProductsController.

View File

@@ -1,10 +0,0 @@
# frozen_string_literal: true
# Request a JSON document from the FDC API with authentication.
#
# This class was created when the FDC didn't comply with the DFC standard.
# But now it does and this class is empty. :-)
#
# We can delete this in the next commit.
class FdcRequest < DfcRequest
end

View File

@@ -59,4 +59,28 @@ RSpec.describe DfcRequest do
# would raise errors because we didn't setup Webmock or VCR.
# The absence of errors makes this test pass.
end
it "refreshes the access token and retrieves the FDC catalog", vcr: true do
# A refresh is only attempted if the token is stale.
account.uid = "testdfc@protonmail.com"
account.refresh_token = ENV.fetch("OPENID_REFRESH_TOKEN")
account.updated_at = 1.day.ago
response = nil
expect {
response = api.call(
"https://env-0105831.jcloud-ver-jpe.ik-server.com/api/dfc/Enterprises/test-hodmedod/SuppliedProducts"
)
}.to change {
account.token
}.and change {
account.refresh_token
}
json = JSON.parse(response)
graph = DfcIo.import(json)
products = graph.select { |s| s.semanticType == "dfc-b:SuppliedProduct" }
expect(products).to be_present
end
end

View File

@@ -1,35 +0,0 @@
# frozen_string_literal: true
require_relative "../spec_helper"
RSpec.describe FdcRequest do
subject(:api) { FdcRequest.new(user) }
let(:user) { build(:oidc_user) }
let(:account) { user.oidc_account }
let(:url) {
"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
# A refresh is only attempted if the token is stale.
account.uid = "testdfc@protonmail.com"
account.refresh_token = ENV.fetch("OPENID_REFRESH_TOKEN")
account.updated_at = 1.day.ago
response = nil
expect {
response = api.call(url)
}.to change {
account.token
}.and change {
account.refresh_token
}
json = JSON.parse(response)
graph = DfcIo.import(json)
products = graph.select { |s| s.semanticType == "dfc-b:SuppliedProduct" }
expect(products).to be_present
end
end