闭社主体 forked from https://github.com/tootsuite/mastodon
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.

76 lines
2.3 KiB

  1. require 'rails_helper'
  2. RSpec.describe Api::V1::NotificationsController, type: :controller do
  3. render_views
  4. let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
  5. let(:token) { double acceptable?: true, resource_owner_id: user.id }
  6. let(:other) { Fabricate(:user, account: Fabricate(:account, username: 'bob')) }
  7. before do
  8. allow(controller).to receive(:doorkeeper_token) { token }
  9. end
  10. describe 'GET #index' do
  11. before do
  12. first_status = PostStatusService.new.call(user.account, 'Test')
  13. @reblog_of_first_status = ReblogService.new.call(other.account, first_status)
  14. mentioning_status = PostStatusService.new.call(other.account, 'Hello @alice')
  15. @mention_from_status = mentioning_status.mentions.first
  16. @favourite = FavouriteService.new.call(other.account, first_status)
  17. @follow = FollowService.new.call(other.account, 'alice')
  18. end
  19. describe 'with no options' do
  20. before do
  21. get :index
  22. end
  23. it 'returns http success' do
  24. expect(response).to have_http_status(:success)
  25. end
  26. it 'includes reblog' do
  27. expect(assigns(:notifications).map(&:activity)).to include(@reblog_of_first_status)
  28. end
  29. it 'includes mention' do
  30. expect(assigns(:notifications).map(&:activity)).to include(@mention_from_status)
  31. end
  32. it 'includes favourite' do
  33. expect(assigns(:notifications).map(&:activity)).to include(@favourite)
  34. end
  35. it 'includes follow' do
  36. expect(assigns(:notifications).map(&:activity)).to include(@follow)
  37. end
  38. end
  39. describe 'with excluded mentions' do
  40. before do
  41. get :index, params: { exclude_types: ['mention'] }
  42. end
  43. it 'returns http success' do
  44. expect(response).to have_http_status(:success)
  45. end
  46. it 'includes reblog' do
  47. expect(assigns(:notifications).map(&:activity)).to include(@reblog_of_first_status)
  48. end
  49. it 'excludes mention' do
  50. expect(assigns(:notifications).map(&:activity)).to_not include(@mention_from_status)
  51. end
  52. it 'includes favourite' do
  53. expect(assigns(:notifications).map(&:activity)).to include(@favourite)
  54. end
  55. it 'includes follow' do
  56. expect(assigns(:notifications).map(&:activity)).to include(@follow)
  57. end
  58. end
  59. end
  60. end