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
16 changes: 11 additions & 5 deletions app/models/connected_apps/vine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@
#
module ConnectedApps
class Vine < ConnectedApp
def connect(api_key: )
# TODO
end
VINE_API_URL = "https://vine-staging.openfoodnetwork.org.au/api/v1/my-team"

rioug marked this conversation as resolved.
Show resolved Hide resolved
def connect(api_key:, vine_api:, **_opts)
response = vine_api.my_team

return update data: { api_key: } if response.success?

def disconnect
# TODO
errors.add(:base, I18n.t("activerecord.errors.models.connected_apps.vine.api_request_error"))
rioug marked this conversation as resolved.
Show resolved Hide resolved

false
end

def disconnect; end
end
end
3 changes: 3 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ en:
count_on_hand:
using_producer_stock_settings_but_count_on_hand_set: "must be blank because using producer stock settings"
limited_stock_but_no_count_on_hand: "must be specified because forcing limited stock"
connected_apps:
vine:
api_request_error: "An error occured when connecting to Vine API"
messages:
confirmation: "doesn't match %{attribute}"
blank: "can't be blank"
Expand Down
45 changes: 45 additions & 0 deletions spec/models/connected_apps/vine_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# frozen_string_literal: true

require "spec_helper"

RSpec.describe ConnectedApps::Vine do
subject(:connected_app) { ConnectedApps::Vine.new(enterprise: create(:enterprise)) }

let(:vine_api_key) { "12345" }
let(:vine_api) { instance_double(VineApiService) }

describe "#connect" do
it "send a request to VINE api" do
expect(vine_api).to receive(:my_team).and_return(mock_api_response(true))

connected_app.connect(api_key: vine_api_key, vine_api: )
end

context "when request succeed", :vcr do
it "store the vine api key" do
allow(vine_api).to receive(:my_team).and_return(mock_api_response(true))

expect(connected_app.connect(api_key: vine_api_key, vine_api:)).to eq(true)
expect(connected_app.data).to eql({ "api_key" => vine_api_key })
end
end
rioug marked this conversation as resolved.
Show resolved Hide resolved

context "when request fails" do
it "doesn't store the vine api key" do
allow(vine_api).to receive(:my_team).and_return(mock_api_response(false))

expect(connected_app.connect(api_key: vine_api_key, vine_api:)).to eq(false)
expect(connected_app.data).to be_nil
expect(connected_app.errors[:base]).to include(
"An error occured when connecting to Vine API"
)
end
end
end

def mock_api_response(success)
mock_response = instance_double(Faraday::Response)
allow(mock_response).to receive(:success?).and_return(success)
mock_response
end
end