Re add VINE_API_URL env variable

And add error handling if the variable is not set
This commit is contained in:
Gaetan Craig-Riou
2024-10-08 13:26:57 +11:00
parent a3d8ae693d
commit df67b53971
4 changed files with 39 additions and 0 deletions

3
.env
View File

@@ -67,3 +67,6 @@ SMTP_PASSWORD="f00d"
# ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" # ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
# ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" # ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
# ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" # ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
# VINE API settings
# VINE_API_URL="https://vine-staging.openfoodnetwork.org.au/api/v1"

View File

@@ -57,6 +57,9 @@ module Admin
rescue Faraday::Error => e rescue Faraday::Error => e
log_and_notify_exception(e) log_and_notify_exception(e)
handle_error(I18n.t("admin.enterprises.form.connected_apps.vine.connection_error")) handle_error(I18n.t("admin.enterprises.form.connected_apps.vine.connection_error"))
rescue KeyError => e
log_and_notify_exception(e)
handle_error(I18n.t("admin.enterprises.form.connected_apps.vine.setup_error"))
end end
def enterprise def enterprise

View File

@@ -1441,6 +1441,7 @@ en:
api_parameters_empty: "Please enter an API key and a secret" api_parameters_empty: "Please enter an API key and a secret"
api_parameters_error: "Check you entered your API key and secret correctly, contact your instance manager if the error persists" api_parameters_error: "Check you entered your API key and secret correctly, contact your instance manager if the error persists"
connection_error: "API connection error, please try again" connection_error: "API connection error, please try again"
setup_error: "VINE API is not configured, please contact your instance manager"
actions: actions:
edit_profile: Settings edit_profile: Settings
properties: Properties properties: Properties

View File

@@ -111,6 +111,38 @@ RSpec.describe "Admin ConnectedApp" do
end end
end end
context "when VINE API is not set up properly" do
before do
# VineApiService will raise a KeyError if VINE_API_URL is not set
allow(VineApiService).to receive(:new).and_raise(KeyError)
end
it "redirects to enterprise edit page, with an error" do
params = {
type: ConnectedApps::Vine,
vine_api_key: "12345678",
vine_secret: "my_secret"
}
post("/admin/enterprises/#{enterprise.id}/connected_apps", params: )
expect(response).to redirect_to(edit_enterprise_url)
expect(flash[:error]).to eq(
"VINE API is not configured, please contact your instance manager"
)
end
it "notifies Bugsnag" do
expect(Bugsnag).to receive(:notify)
params = {
type: ConnectedApps::Vine,
vine_api_key: "12345678",
vine_secret: "my_secret"
}
post("/admin/enterprises/#{enterprise.id}/connected_apps", params: )
end
end
context "when there is a connection error" do context "when there is a connection error" do
before do before do
allow(vine_api).to receive(:my_team).and_raise(Faraday::Error) allow(vine_api).to receive(:my_team).and_raise(Faraday::Error)