status_relationships_presenter_spec.rb 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe StatusRelationshipsPresenter do
  4. describe '.initialize' do
  5. before do
  6. allow(Status).to receive(:reblogs_map).with(status_ids, current_account_id).and_return(default_map)
  7. allow(Status).to receive(:favourites_map).with(status_ids, current_account_id).and_return(default_map)
  8. allow(Status).to receive(:bookmarks_map).with(status_ids, current_account_id).and_return(default_map)
  9. allow(Status).to receive(:mutes_map).with(anything, current_account_id).and_return(default_map)
  10. allow(Status).to receive(:pins_map).with(anything, current_account_id).and_return(default_map)
  11. end
  12. let(:presenter) { StatusRelationshipsPresenter.new(statuses, current_account_id, **options) }
  13. let(:current_account_id) { Fabricate(:account).id }
  14. let(:statuses) { [Fabricate(:status)] }
  15. let(:status_ids) { statuses.map(&: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.reblogs_map).to eq default_map
  21. expect(presenter.favourites_map).to eq default_map
  22. expect(presenter.bookmarks_map).to eq default_map
  23. expect(presenter.mutes_map).to eq default_map
  24. expect(presenter.pins_map).to eq default_map
  25. end
  26. end
  27. context 'options[:reblogs_map] is set' do
  28. let(:options) { { reblogs_map: { 2 => true } } }
  29. it 'sets @reblogs_map merged with default_map and options[:reblogs_map]' do
  30. expect(presenter.reblogs_map).to eq default_map.merge(options[:reblogs_map])
  31. end
  32. end
  33. context 'options[:favourites_map] is set' do
  34. let(:options) { { favourites_map: { 3 => true } } }
  35. it 'sets @favourites_map merged with default_map and options[:favourites_map]' do
  36. expect(presenter.favourites_map).to eq default_map.merge(options[:favourites_map])
  37. end
  38. end
  39. context 'options[:bookmarks_map] is set' do
  40. let(:options) { { bookmarks_map: { 4 => true } } }
  41. it 'sets @bookmarks_map merged with default_map and options[:bookmarks_map]' do
  42. expect(presenter.bookmarks_map).to eq default_map.merge(options[:bookmarks_map])
  43. end
  44. end
  45. context 'options[:mutes_map] is set' do
  46. let(:options) { { mutes_map: { 5 => true } } }
  47. it 'sets @mutes_map merged with default_map and options[:mutes_map]' do
  48. expect(presenter.mutes_map).to eq default_map.merge(options[:mutes_map])
  49. end
  50. end
  51. context 'options[:pins_map] is set' do
  52. let(:options) { { pins_map: { 6 => true } } }
  53. it 'sets @pins_map merged with default_map and options[:pins_map]' do
  54. expect(presenter.pins_map).to eq default_map.merge(options[:pins_map])
  55. end
  56. end
  57. end
  58. end