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.

128 lines
3.7 KiB

  1. require 'rails_helper'
  2. RSpec.describe Api::V1::AccountsController, 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. before do
  7. allow(controller).to receive(:doorkeeper_token) { token }
  8. end
  9. describe 'GET #show' do
  10. it 'returns http success' do
  11. get :show, params: { id: user.account.id }
  12. expect(response).to have_http_status(:success)
  13. end
  14. end
  15. describe 'POST #follow' do
  16. let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
  17. before do
  18. post :follow, params: { id: other_account.id }
  19. end
  20. it 'returns http success' do
  21. expect(response).to have_http_status(:success)
  22. end
  23. it 'creates a following relation between user and target user' do
  24. expect(user.account.following?(other_account)).to be true
  25. end
  26. end
  27. describe 'POST #unfollow' do
  28. let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
  29. before do
  30. user.account.follow!(other_account)
  31. post :unfollow, params: { id: other_account.id }
  32. end
  33. it 'returns http success' do
  34. expect(response).to have_http_status(:success)
  35. end
  36. it 'removes the following relation between user and target user' do
  37. expect(user.account.following?(other_account)).to be false
  38. end
  39. end
  40. describe 'POST #block' do
  41. let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
  42. before do
  43. user.account.follow!(other_account)
  44. post :block, params: { id: other_account.id }
  45. end
  46. it 'returns http success' do
  47. expect(response).to have_http_status(:success)
  48. end
  49. it 'removes the following relation between user and target user' do
  50. expect(user.account.following?(other_account)).to be false
  51. end
  52. it 'creates a blocking relation' do
  53. expect(user.account.blocking?(other_account)).to be true
  54. end
  55. end
  56. describe 'POST #unblock' do
  57. let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
  58. before do
  59. user.account.block!(other_account)
  60. post :unblock, params: { id: other_account.id }
  61. end
  62. it 'returns http success' do
  63. expect(response).to have_http_status(:success)
  64. end
  65. it 'removes the blocking relation between user and target user' do
  66. expect(user.account.blocking?(other_account)).to be false
  67. end
  68. end
  69. describe 'POST #mute' do
  70. let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
  71. before do
  72. user.account.follow!(other_account)
  73. post :mute, params: {id: other_account.id }
  74. end
  75. it 'returns http success' do
  76. expect(response).to have_http_status(:success)
  77. end
  78. it 'does not remove the following relation between user and target user' do
  79. expect(user.account.following?(other_account)).to be true
  80. end
  81. it 'creates a muting relation' do
  82. expect(user.account.muting?(other_account)).to be true
  83. end
  84. end
  85. describe 'POST #unmute' do
  86. let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
  87. before do
  88. user.account.mute!(other_account)
  89. post :unmute, params: { id: other_account.id }
  90. end
  91. it 'returns http success' do
  92. expect(response).to have_http_status(:success)
  93. end
  94. it 'removes the muting relation between user and target user' do
  95. expect(user.account.muting?(other_account)).to be false
  96. end
  97. end
  98. end