Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions app/presenters/api/v1/settings_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ def initialize(company, context)
def providers
company.current_providers
end

def available_providers
Provider::AVAILABLE_NAMES
end

def eligible_actions
Provider::ELIGIBLE_ACTIONS
end
end
end
end
2 changes: 1 addition & 1 deletion app/resources/api/v1/setting_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Api
module V1
class SettingResource < JSONAPI::Resource
has_many :providers
attributes :available_providers, :eligible_actions, :providers
end
end
end
28 changes: 28 additions & 0 deletions spec/presenters/api/v1/settings_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,33 @@
subject { Api::V1::SettingsPresenter.new(company, admin) }

describe '#providers' do
let!(:company_provider) { create(:provider, company: company) }
let!(:another_provider) { create(:provider) }

it 'should contain available providers'do
expect(subject.providers).to include company_provider
end

it 'should not include other providers' do
expect(subject.providers).to_not include another_provider
end
end

describe '#available_providers' do
it { expect(subject.available_providers).to eq %w[facebook twitter instagram] }
end

describe '#eligible_actions' do
context 'when facebook' do
it { expect(subject.eligible_actions['facebook']).to eq %w[post join like] }
end

context 'when twitter' do
it { expect(subject.eligible_actions['twitter']).to eq %w[tweet retweet follow like] }
end

context 'when instagram' do
it { expect(subject.eligible_actions['instagram']).to eq %w[post follow like] }
end
end
end
4 changes: 3 additions & 1 deletion spec/resources/api/v1/setting_resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@

subject { described_class.new(presenter, {}) }

it { is_expected.to have_many(:providers) }
it { is_expected.to have_attribute(:available_providers) }
it { is_expected.to have_attribute(:eligible_actions) }
it { is_expected.to have_attribute(:providers) }
end