Fetch data from URL provided by Litefarm

So we don't have to distinguish between staging and production. They
will provide the right URL.
This commit is contained in:
Maikel Linke
2025-12-09 11:39:48 +11:00
parent b302dcfbec
commit 3331aaa382
3 changed files with 7 additions and 6 deletions

View File

@@ -33,7 +33,7 @@ module DfcProvider
return
end
DfcImporter.new.import_enterprise_profiles(current_user.id)
DfcImporter.new.import_enterprise_profiles(current_user.id, enterprises_url)
render json: { success: true }
end

View File

@@ -2,12 +2,11 @@
# Fetch data from another platform and store it locally.
class DfcImporter
def import_enterprise_profiles(platform)
def import_enterprise_profiles(platform, enterprises_url)
raise "unsupported platform" if platform != "lf-dev"
endpoint = "https://api.beta.litefarm.org/dfc/enterprises/"
api = DfcPlatformRequest.new(platform)
body = api.call(endpoint)
body = api.call(enterprises_url)
graph = DfcIo.import(body).to_a
farms = graph.select { |item| item.semanticType == "dfc-b:Enterprise" }
farms.each { |farm| import_profile(farm) }

View File

@@ -8,9 +8,11 @@ require_relative "../spec_helper"
# OPENID_APP_ID="..."
# OPENID_APP_SECRET="..."
RSpec.describe DfcImporter do
let(:endpoint) { "https://api.beta.litefarm.org/dfc/enterprises/" }
it "fetches a list of enterprises", :vcr do
expect {
subject.import_enterprise_profiles("lf-dev")
subject.import_enterprise_profiles("lf-dev", endpoint)
}.to have_enqueued_mail(Spree::UserMailer, :confirmation_instructions)
.and have_enqueued_mail(EnterpriseMailer, :welcome).twice
@@ -24,7 +26,7 @@ RSpec.describe DfcImporter do
# Repeating works without creating duplicates:
expect {
subject.import_enterprise_profiles("lf-dev")
subject.import_enterprise_profiles("lf-dev", endpoint)
}.not_to have_enqueued_mail
end
end