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.

75 lines
2.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) { 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. status = PostStatusService.new.call(user.account, 'Test')
  13. @reblog = ReblogService.new.call(other.account, status)
  14. @mention = PostStatusService.new.call(other.account, 'Hello @alice')
  15. @favourite = FavouriteService.new.call(other.account, status)
  16. @follow = FollowService.new.call(other.account, 'alice')
  17. end
  18. describe 'with no options' do
  19. before do
  20. get :index
  21. end
  22. it 'returns http success' do
  23. expect(response).to have_http_status(:success)
  24. end
  25. it 'includes reblog' do
  26. expect(assigns(:notifications).map(&:activity_id)).to include(@reblog.id)
  27. end
  28. it 'includes mention' do
  29. expect(assigns(:notifications).map(&:activity_id)).to include(@mention.mentions.first.id)
  30. end
  31. it 'includes favourite' do
  32. expect(assigns(:notifications).map(&:activity_id)).to include(@favourite.id)
  33. end
  34. it 'includes follow' do
  35. expect(assigns(:notifications).map(&:activity_id)).to include(@follow.id)
  36. end
  37. end
  38. describe 'with excluded mentions' do
  39. before do
  40. get :index, params: { exclude_types: ['mention'] }
  41. end
  42. it 'returns http success' do
  43. expect(response).to have_http_status(:success)
  44. end
  45. it 'includes reblog' do
  46. expect(assigns(:notifications).map(&:activity_id)).to include(@reblog.id)
  47. end
  48. it 'excludes mention' do
  49. expect(assigns(:notifications).map(&:activity_id)).to_not include(@mention.mentions.first.id)
  50. end
  51. it 'includes favourite' do
  52. expect(assigns(:notifications).map(&:activity_id)).to include(@favourite.id)
  53. end
  54. it 'includes follow' do
  55. expect(assigns(:notifications).map(&:activity_id)).to include(@follow.id)
  56. end
  57. end
  58. end
  59. end