logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

accounts_controller_spec.rb (5603B)


  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) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'follow read') }
  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', locked: locked)).account }
  17. before do
  18. post :follow, params: { id: other_account.id }
  19. end
  20. context 'with unlocked account' do
  21. let(:locked) { false }
  22. it 'returns http success' do
  23. expect(response).to have_http_status(:success)
  24. end
  25. it 'returns JSON with following=true and requested=false' do
  26. json = body_as_json
  27. expect(json[:following]).to be true
  28. expect(json[:requested]).to be false
  29. end
  30. it 'creates a following relation between user and target user' do
  31. expect(user.account.following?(other_account)).to be true
  32. end
  33. end
  34. context 'with locked account' do
  35. let(:locked) { true }
  36. it 'returns http success' do
  37. expect(response).to have_http_status(:success)
  38. end
  39. it 'returns JSON with following=false and requested=true' do
  40. json = body_as_json
  41. expect(json[:following]).to be false
  42. expect(json[:requested]).to be true
  43. end
  44. it 'creates a follow request relation between user and target user' do
  45. expect(user.account.requested?(other_account)).to be true
  46. end
  47. end
  48. end
  49. describe 'POST #unfollow' do
  50. let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
  51. before do
  52. user.account.follow!(other_account)
  53. post :unfollow, params: { id: other_account.id }
  54. end
  55. it 'returns http success' do
  56. expect(response).to have_http_status(:success)
  57. end
  58. it 'removes the following relation between user and target user' do
  59. expect(user.account.following?(other_account)).to be false
  60. end
  61. end
  62. describe 'POST #block' do
  63. let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
  64. before do
  65. user.account.follow!(other_account)
  66. post :block, params: { id: other_account.id }
  67. end
  68. it 'returns http success' do
  69. expect(response).to have_http_status(:success)
  70. end
  71. it 'removes the following relation between user and target user' do
  72. expect(user.account.following?(other_account)).to be false
  73. end
  74. it 'creates a blocking relation' do
  75. expect(user.account.blocking?(other_account)).to be true
  76. end
  77. end
  78. describe 'POST #unblock' do
  79. let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
  80. before do
  81. user.account.block!(other_account)
  82. post :unblock, params: { id: other_account.id }
  83. end
  84. it 'returns http success' do
  85. expect(response).to have_http_status(:success)
  86. end
  87. it 'removes the blocking relation between user and target user' do
  88. expect(user.account.blocking?(other_account)).to be false
  89. end
  90. end
  91. describe 'POST #mute' do
  92. let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
  93. before do
  94. user.account.follow!(other_account)
  95. post :mute, params: {id: other_account.id }
  96. end
  97. it 'returns http success' do
  98. expect(response).to have_http_status(:success)
  99. end
  100. it 'does not remove the following relation between user and target user' do
  101. expect(user.account.following?(other_account)).to be true
  102. end
  103. it 'creates a muting relation' do
  104. expect(user.account.muting?(other_account)).to be true
  105. end
  106. it 'mutes notifications' do
  107. expect(user.account.muting_notifications?(other_account)).to be true
  108. end
  109. end
  110. describe 'POST #mute with notifications set to false' do
  111. let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
  112. before do
  113. user.account.follow!(other_account)
  114. post :mute, params: {id: other_account.id, notifications: false }
  115. end
  116. it 'returns http success' do
  117. expect(response).to have_http_status(:success)
  118. end
  119. it 'does not remove the following relation between user and target user' do
  120. expect(user.account.following?(other_account)).to be true
  121. end
  122. it 'creates a muting relation' do
  123. expect(user.account.muting?(other_account)).to be true
  124. end
  125. it 'does not mute notifications' do
  126. expect(user.account.muting_notifications?(other_account)).to be false
  127. end
  128. end
  129. describe 'POST #unmute' do
  130. let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
  131. before do
  132. user.account.mute!(other_account)
  133. post :unmute, params: { id: other_account.id }
  134. end
  135. it 'returns http success' do
  136. expect(response).to have_http_status(:success)
  137. end
  138. it 'removes the muting relation between user and target user' do
  139. expect(user.account.muting?(other_account)).to be false
  140. end
  141. end
  142. end