account_relationships_presenter_spec.rb 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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).to have_attributes(
  22. following: default_map,
  23. followed_by: default_map,
  24. blocking: default_map,
  25. muting: default_map,
  26. requested: default_map,
  27. domain_blocking: default_map
  28. )
  29. end
  30. end
  31. context 'when options[:following_map] is set' do
  32. let(:options) { { following_map: { 2 => true } } }
  33. it 'sets @following merged with default_map and options[:following_map]' do
  34. expect(presenter.following).to eq default_map.merge(options[:following_map])
  35. end
  36. end
  37. context 'when options[:followed_by_map] is set' do
  38. let(:options) { { followed_by_map: { 3 => true } } }
  39. it 'sets @followed_by merged with default_map and options[:followed_by_map]' do
  40. expect(presenter.followed_by).to eq default_map.merge(options[:followed_by_map])
  41. end
  42. end
  43. context 'when options[:blocking_map] is set' do
  44. let(:options) { { blocking_map: { 4 => true } } }
  45. it 'sets @blocking merged with default_map and options[:blocking_map]' do
  46. expect(presenter.blocking).to eq default_map.merge(options[:blocking_map])
  47. end
  48. end
  49. context 'when options[:muting_map] is set' do
  50. let(:options) { { muting_map: { 5 => true } } }
  51. it 'sets @muting merged with default_map and options[:muting_map]' do
  52. expect(presenter.muting).to eq default_map.merge(options[:muting_map])
  53. end
  54. end
  55. context 'when options[:requested_map] is set' do
  56. let(:options) { { requested_map: { 6 => true } } }
  57. it 'sets @requested merged with default_map and options[:requested_map]' do
  58. expect(presenter.requested).to eq default_map.merge(options[:requested_map])
  59. end
  60. end
  61. context 'when options[:requested_by_map] is set' do
  62. let(:options) { { requested_by_map: { 6 => true } } }
  63. it 'sets @requested merged with default_map and options[:requested_by_map]' do
  64. expect(presenter.requested_by).to eq default_map.merge(options[:requested_by_map])
  65. end
  66. end
  67. context 'when options[:domain_blocking_map] is set' do
  68. let(:options) { { domain_blocking_map: { 7 => true } } }
  69. it 'sets @domain_blocking merged with default_map and options[:domain_blocking_map]' do
  70. expect(presenter.domain_blocking).to eq default_map.merge(options[:domain_blocking_map])
  71. end
  72. end
  73. end
  74. end