1
0

account_relationships_presenter_spec.rb 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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(accounts.pluck(:id), current_account_id).and_return(default_map)
  7. allow(Account).to receive(:followed_by_map).with(accounts.pluck(:id), current_account_id).and_return(default_map)
  8. allow(Account).to receive(:blocking_map).with(accounts.pluck(:id), current_account_id).and_return(default_map)
  9. allow(Account).to receive(:muting_map).with(accounts.pluck(:id), current_account_id).and_return(default_map)
  10. allow(Account).to receive(:requested_map).with(accounts.pluck(:id), current_account_id).and_return(default_map)
  11. allow(Account).to receive(:requested_by_map).with(accounts.pluck(:id), current_account_id).and_return(default_map)
  12. end
  13. let(:presenter) { described_class.new(accounts, current_account_id, **options) }
  14. let(:current_account_id) { Fabricate(:account).id }
  15. let(:accounts) { [Fabricate(:account)] }
  16. let(:default_map) { { accounts[0].id => true } }
  17. context 'when options are not set' do
  18. let(:options) { {} }
  19. it 'sets default maps' do
  20. expect(presenter).to have_attributes(
  21. following: default_map,
  22. followed_by: default_map,
  23. blocking: default_map,
  24. muting: default_map,
  25. requested: default_map,
  26. domain_blocking: { accounts[0].id => nil }
  27. )
  28. end
  29. end
  30. context 'with a warm cache' do
  31. let(:options) { {} }
  32. before do
  33. described_class.new(accounts, current_account_id, **options)
  34. allow(Account).to receive(:following_map).with([], current_account_id).and_return({})
  35. allow(Account).to receive(:followed_by_map).with([], current_account_id).and_return({})
  36. allow(Account).to receive(:blocking_map).with([], current_account_id).and_return({})
  37. allow(Account).to receive(:muting_map).with([], current_account_id).and_return({})
  38. allow(Account).to receive(:requested_map).with([], current_account_id).and_return({})
  39. allow(Account).to receive(:requested_by_map).with([], current_account_id).and_return({})
  40. end
  41. it 'sets returns expected values' do
  42. expect(presenter).to have_attributes(
  43. following: default_map,
  44. followed_by: default_map,
  45. blocking: default_map,
  46. muting: default_map,
  47. requested: default_map,
  48. domain_blocking: { accounts[0].id => nil }
  49. )
  50. end
  51. end
  52. context 'when options[:following_map] is set' do
  53. let(:options) { { following_map: { 2 => true } } }
  54. it 'sets @following merged with default_map and options[:following_map]' do
  55. expect(presenter.following).to eq default_map.merge(options[:following_map])
  56. end
  57. end
  58. context 'when options[:followed_by_map] is set' do
  59. let(:options) { { followed_by_map: { 3 => true } } }
  60. it 'sets @followed_by merged with default_map and options[:followed_by_map]' do
  61. expect(presenter.followed_by).to eq default_map.merge(options[:followed_by_map])
  62. end
  63. end
  64. context 'when options[:blocking_map] is set' do
  65. let(:options) { { blocking_map: { 4 => true } } }
  66. it 'sets @blocking merged with default_map and options[:blocking_map]' do
  67. expect(presenter.blocking).to eq default_map.merge(options[:blocking_map])
  68. end
  69. end
  70. context 'when options[:muting_map] is set' do
  71. let(:options) { { muting_map: { 5 => true } } }
  72. it 'sets @muting merged with default_map and options[:muting_map]' do
  73. expect(presenter.muting).to eq default_map.merge(options[:muting_map])
  74. end
  75. end
  76. context 'when options[:requested_map] is set' do
  77. let(:options) { { requested_map: { 6 => true } } }
  78. it 'sets @requested merged with default_map and options[:requested_map]' do
  79. expect(presenter.requested).to eq default_map.merge(options[:requested_map])
  80. end
  81. end
  82. context 'when options[:requested_by_map] is set' do
  83. let(:options) { { requested_by_map: { 6 => true } } }
  84. it 'sets @requested merged with default_map and options[:requested_by_map]' do
  85. expect(presenter.requested_by).to eq default_map.merge(options[:requested_by_map])
  86. end
  87. end
  88. context 'when options[:domain_blocking_map] is set' do
  89. let(:options) { { domain_blocking_map: { 7 => true } } }
  90. it 'sets @domain_blocking merged with default_map and options[:domain_blocking_map]' do
  91. expect(presenter.domain_blocking).to eq({ accounts[0].id => nil }.merge(options[:domain_blocking_map]))
  92. end
  93. end
  94. end
  95. end