mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-26 01:33:22 +00:00
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:
@@ -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
|
||||
|
||||
@@ -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) }
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user