account_relationships_presenter_spec.rb 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe AccountRelationshipsPresenter do
  4. describe '.initialize' do
  5. before do
  6. allow(Account).to receive(:following_map).with(account_ids, current_account_id).and_return(default_map)
  7. allow(Account).to receive(:followed_by_map).with(account_ids, current_account_id).and_return(default_map)
  8. allow(Account).to receive(:blocking_map).with(account_ids, current_account_id).and_return(default_map)
  9. allow(Account).to receive(:muting_map).with(account_ids, current_account_id).and_return(default_map)
  10. allow(Account).to receive(:requested_map).with(account_ids, current_account_id).and_return(default_map)
  11. allow(Account).to receive(:requested_by_map).with(account_ids, current_account_id).and_return(default_map)
  12. allow(Account).to receive(:domain_blocking_map).with(account_ids, current_account_id).and_return(default_map)
  13. end
  14. let(:presenter) { described_class.new(account_ids, current_account_id, **options) }
  15. let(:current_account_id) { Fabricate(:account).id }
  16. let(:account_ids) { [Fabricate(:account).id] }
  17. let(:default_map) { { 1 => true } }
  18. context 'when options are not set' do
  19. let(:options) { {} }
  20. it 'sets default maps' do
  21. expect(presenter.following).to eq default_map
  22. expect(presenter.followed_by).to eq default_map
  23. expect(presenter.blocking).to eq default_map
  24. expect(presenter.muting).to eq default_map
  25. expect(presenter.requested).to eq default_map
  26. expect(presenter.domain_blocking).to eq default_map
  27. end
  28. end
  29. context 'when options[:following_map] is set' do
  30. let(:options) { { following_map: { 2 => true } } }
  31. it 'sets @following merged with default_map and options[:following_map]' do
  32. expect(presenter.following).to eq default_map.merge(options[:following_map])
  33. end
  34. end
  35. context 'when options[:followed_by_map] is set' do
  36. let(:options) { { followed_by_map: { 3 => true } } }
  37. it 'sets @followed_by merged with default_map and options[:followed_by_map]' do
  38. expect(presenter.followed_by).to eq default_map.merge(options[:followed_by_map])
  39. end
  40. end
  41. context 'when options[:blocking_map] is set' do
  42. let(:options) { { blocking_map: { 4 => true } } }
  43. it 'sets @blocking merged with default_map and options[:blocking_map]' do
  44. expect(presenter.blocking).to eq default_map.merge(options[:blocking_map])
  45. end
  46. end
  47. context 'when options[:muting_map] is set' do
  48. let(:options) { { muting_map: { 5 => true } } }
  49. it 'sets @muting merged with default_map and options[:muting_map]' do
  50. expect(presenter.muting).to eq default_map.merge(options[:muting_map])
  51. end
  52. end
  53. context 'when options[:requested_map] is set' do
  54. let(:options) { { requested_map: { 6 => true } } }
  55. it 'sets @requested merged with default_map and options[:requested_map]' do
  56. expect(presenter.requested).to eq default_map.merge(options[:requested_map])
  57. end
  58. end
  59. context 'when options[:requested_by_map] is set' do
  60. let(:options) { { requested_by_map: { 6 => true } } }
  61. it 'sets @requested merged with default_map and options[:requested_by_map]' do
  62. expect(presenter.requested_by).to eq default_map.merge(options[:requested_by_map])
  63. end
  64. end
  65. context 'when options[:domain_blocking_map] is set' do
  66. let(:options) { { domain_blocking_map: { 7 => true } } }
  67. it 'sets @domain_blocking merged with default_map and options[:domain_blocking_map]' do
  68. expect(presenter.domain_blocking).to eq default_map.merge(options[:domain_blocking_map])
  69. end
  70. end
  71. end
  72. end