From 743e7f26a82c54f6d6698bc75ddd3d6486cb3e91 Mon Sep 17 00:00:00 2001 From: Max Grechko Date: Wed, 23 May 2018 19:22:52 +0300 Subject: [PATCH] Update SettingsPresenter to return provider settings --- app/presenters/api/v1/settings_presenter.rb | 8 ++++++ app/resources/api/v1/setting_resource.rb | 2 +- .../api/v1/settings_presenter_spec.rb | 28 +++++++++++++++++++ .../resources/api/v1/setting_resource_spec.rb | 4 ++- 4 files changed, 40 insertions(+), 2 deletions(-) diff --git a/app/presenters/api/v1/settings_presenter.rb b/app/presenters/api/v1/settings_presenter.rb index 111c3cf..94632dc 100644 --- a/app/presenters/api/v1/settings_presenter.rb +++ b/app/presenters/api/v1/settings_presenter.rb @@ -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 diff --git a/app/resources/api/v1/setting_resource.rb b/app/resources/api/v1/setting_resource.rb index 2a3b712..21c16eb 100644 --- a/app/resources/api/v1/setting_resource.rb +++ b/app/resources/api/v1/setting_resource.rb @@ -3,7 +3,7 @@ module Api module V1 class SettingResource < JSONAPI::Resource - has_many :providers + attributes :available_providers, :eligible_actions, :providers end end end diff --git a/spec/presenters/api/v1/settings_presenter_spec.rb b/spec/presenters/api/v1/settings_presenter_spec.rb index 7681d54..959df02 100644 --- a/spec/presenters/api/v1/settings_presenter_spec.rb +++ b/spec/presenters/api/v1/settings_presenter_spec.rb @@ -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 diff --git a/spec/resources/api/v1/setting_resource_spec.rb b/spec/resources/api/v1/setting_resource_spec.rb index 706a31a..aab6ca2 100644 --- a/spec/resources/api/v1/setting_resource_spec.rb +++ b/spec/resources/api/v1/setting_resource_spec.rb @@ -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