Skip to content

Commit

Permalink
Re add VINE_API_URL env variable
Browse files Browse the repository at this point in the history
And add error handling if the variable is not set
  • Loading branch information
rioug committed Oct 8, 2024
1 parent a3d8ae6 commit df67b53
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,6 @@ SMTP_PASSWORD="f00d"
# ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
# ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
# ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

# VINE API settings
# VINE_API_URL="https://vine-staging.openfoodnetwork.org.au/api/v1"
3 changes: 3 additions & 0 deletions app/controllers/admin/connected_apps_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ def connect_vine
rescue Faraday::Error => e
log_and_notify_exception(e)
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

def enterprise
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1441,6 +1441,7 @@ en:
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"
connection_error: "API connection error, please try again"
setup_error: "VINE API is not configured, please contact your instance manager"
actions:
edit_profile: Settings
properties: Properties
Expand Down
32 changes: 32 additions & 0 deletions spec/requests/admin/connected_apps_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,38 @@
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
before do
allow(vine_api).to receive(:my_team).and_raise(Faraday::Error)
Expand Down

0 comments on commit df67b53

Please sign in to comment.