闭社主体 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.

105 lines
3.2 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) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read') }
  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 #show' do
  11. it 'returns http success' do
  12. notification = Fabricate(:notification, account: user.account)
  13. get :show, params: { id: notification.id }
  14. expect(response).to have_http_status(:success)
  15. end
  16. end
  17. describe 'POST #dismiss' do
  18. it 'destroys the notification' do
  19. notification = Fabricate(:notification, account: user.account)
  20. post :dismiss, params: { id: notification.id }
  21. expect(response).to have_http_status(:success)
  22. expect { notification.reload }.to raise_error(ActiveRecord::RecordNotFound)
  23. end
  24. end
  25. describe 'POST #clear' do
  26. it 'clears notifications for the account' do
  27. notification = Fabricate(:notification, account: user.account)
  28. post :clear
  29. expect(notification.account.reload.notifications).to be_empty
  30. expect(response).to have_http_status(:success)
  31. end
  32. end
  33. describe 'GET #index' do
  34. before do
  35. first_status = PostStatusService.new.call(user.account, 'Test')
  36. @reblog_of_first_status = ReblogService.new.call(other.account, first_status)
  37. mentioning_status = PostStatusService.new.call(other.account, 'Hello @alice')
  38. @mention_from_status = mentioning_status.mentions.first
  39. @favourite = FavouriteService.new.call(other.account, first_status)
  40. @follow = FollowService.new.call(other.account, 'alice')
  41. end
  42. describe 'with no options' do
  43. before do
  44. get :index
  45. end
  46. it 'returns http success' do
  47. expect(response).to have_http_status(:success)
  48. end
  49. it 'includes reblog' do
  50. expect(assigns(:notifications).map(&:activity)).to include(@reblog_of_first_status)
  51. end
  52. it 'includes mention' do
  53. expect(assigns(:notifications).map(&:activity)).to include(@mention_from_status)
  54. end
  55. it 'includes favourite' do
  56. expect(assigns(:notifications).map(&:activity)).to include(@favourite)
  57. end
  58. it 'includes follow' do
  59. expect(assigns(:notifications).map(&:activity)).to include(@follow)
  60. end
  61. end
  62. describe 'with excluded mentions' do
  63. before do
  64. get :index, params: { exclude_types: ['mention'] }
  65. end
  66. it 'returns http success' do
  67. expect(response).to have_http_status(:success)
  68. end
  69. it 'includes reblog' do
  70. expect(assigns(:notifications).map(&:activity)).to include(@reblog_of_first_status)
  71. end
  72. it 'excludes mention' do
  73. expect(assigns(:notifications).map(&:activity)).to_not include(@mention_from_status)
  74. end
  75. it 'includes favourite' do
  76. expect(assigns(:notifications).map(&:activity)).to include(@favourite)
  77. end
  78. it 'includes follow' do
  79. expect(assigns(:notifications).map(&:activity)).to include(@follow)
  80. end
  81. end
  82. end
  83. end