Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Citi OFN Voucher] Add VINE connected app #12886

Merged
merged 12 commits into from
Oct 14, 2024
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)
rioug marked this conversation as resolved.
Show resolved Hide resolved
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
Loading