You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
3.3 KiB

  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(:domain_blocking_map).with(account_ids, current_account_id).and_return(default_map)
  12. end
  13. let(:presenter) { AccountRelationshipsPresenter.new(account_ids, current_account_id, **options) }
  14. let(:current_account_id) { Fabricate(:account).id }
  15. let(:account_ids) { [Fabricate(:account).id] }
  16. let(:default_map) { { 1 => true } }
  17. context 'options are not set' do
  18. let(:options) { {} }
  19. it 'sets default maps' do
  20. expect(presenter.following).to eq default_map
  21. expect(presenter.followed_by).to eq default_map
  22. expect(presenter.blocking).to eq default_map
  23. expect(presenter.muting).to eq default_map
  24. expect(presenter.requested).to eq default_map
  25. expect(presenter.domain_blocking).to eq default_map
  26. end
  27. end
  28. context 'options[:following_map] is set' do
  29. let(:options) { { following_map: { 2 => true } } }
  30. it 'sets @following merged with default_map and options[:following_map]' do
  31. expect(presenter.following).to eq default_map.merge(options[:following_map])
  32. end
  33. end
  34. context 'options[:followed_by_map] is set' do
  35. let(:options) { { followed_by_map: { 3 => true } } }
  36. it 'sets @followed_by merged with default_map and options[:followed_by_map]' do
  37. expect(presenter.followed_by).to eq default_map.merge(options[:followed_by_map])
  38. end
  39. end
  40. context 'options[:blocking_map] is set' do
  41. let(:options) { { blocking_map: { 4 => true } } }
  42. it 'sets @blocking merged with default_map and options[:blocking_map]' do
  43. expect(presenter.blocking).to eq default_map.merge(options[:blocking_map])
  44. end
  45. end
  46. context 'options[:muting_map] is set' do
  47. let(:options) { { muting_map: { 5 => true } } }
  48. it 'sets @muting merged with default_map and options[:muting_map]' do
  49. expect(presenter.muting).to eq default_map.merge(options[:muting_map])
  50. end
  51. end
  52. context 'options[:requested_map] is set' do
  53. let(:options) { { requested_map: { 6 => true } } }
  54. it 'sets @requested merged with default_map and options[:requested_map]' do
  55. expect(presenter.requested).to eq default_map.merge(options[:requested_map])
  56. end
  57. end
  58. context 'options[:domain_blocking_map] is set' do
  59. let(:options) { { domain_blocking_map: { 7 => true } } }
  60. it 'sets @domain_blocking merged with default_map and options[:domain_blocking_map]' do
  61. expect(presenter.domain_blocking).to eq default_map.merge(options[:domain_blocking_map])
  62. end
  63. end
  64. end
  65. end