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.

198 lines
5.6 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 'GET #verify_credentials' do
  16. it 'returns http success' do
  17. get :verify_credentials
  18. expect(response).to have_http_status(:success)
  19. end
  20. end
  21. describe 'GET #statuses' do
  22. it 'returns http success' do
  23. get :statuses, params: { id: user.account.id }
  24. expect(response).to have_http_status(:success)
  25. end
  26. end
  27. describe 'GET #followers' do
  28. it 'returns http success' do
  29. get :followers, params: { id: user.account.id }
  30. expect(response).to have_http_status(:success)
  31. end
  32. end
  33. describe 'GET #following' do
  34. it 'returns http success' do
  35. get :following, params: { id: user.account.id }
  36. expect(response).to have_http_status(:success)
  37. end
  38. end
  39. describe 'POST #follow' do
  40. let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
  41. before do
  42. post :follow, params: { id: other_account.id }
  43. end
  44. it 'returns http success' do
  45. expect(response).to have_http_status(:success)
  46. end
  47. it 'creates a following relation between user and target user' do
  48. expect(user.account.following?(other_account)).to be true
  49. end
  50. end
  51. describe 'POST #unfollow' do
  52. let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
  53. before do
  54. user.account.follow!(other_account)
  55. post :unfollow, params: { id: other_account.id }
  56. end
  57. it 'returns http success' do
  58. expect(response).to have_http_status(:success)
  59. end
  60. it 'removes the following relation between user and target user' do
  61. expect(user.account.following?(other_account)).to be false
  62. end
  63. end
  64. describe 'POST #block' do
  65. let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
  66. before do
  67. user.account.follow!(other_account)
  68. post :block, params: { id: other_account.id }
  69. end
  70. it 'returns http success' do
  71. expect(response).to have_http_status(:success)
  72. end
  73. it 'removes the following relation between user and target user' do
  74. expect(user.account.following?(other_account)).to be false
  75. end
  76. it 'creates a blocking relation' do
  77. expect(user.account.blocking?(other_account)).to be true
  78. end
  79. end
  80. describe 'POST #unblock' do
  81. let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
  82. before do
  83. user.account.block!(other_account)
  84. post :unblock, params: { id: other_account.id }
  85. end
  86. it 'returns http success' do
  87. expect(response).to have_http_status(:success)
  88. end
  89. it 'removes the blocking relation between user and target user' do
  90. expect(user.account.blocking?(other_account)).to be false
  91. end
  92. end
  93. describe 'POST #mute' do
  94. let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
  95. before do
  96. user.account.follow!(other_account)
  97. post :mute, params: {id: other_account.id }
  98. end
  99. it 'returns http success' do
  100. expect(response).to have_http_status(:success)
  101. end
  102. it 'does not remove the following relation between user and target user' do
  103. expect(user.account.following?(other_account)).to be true
  104. end
  105. it 'creates a muting relation' do
  106. expect(user.account.muting?(other_account)).to be true
  107. end
  108. end
  109. describe 'POST #unmute' do
  110. let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
  111. before do
  112. user.account.mute!(other_account)
  113. post :unmute, params: { id: other_account.id }
  114. end
  115. it 'returns http success' do
  116. expect(response).to have_http_status(:success)
  117. end
  118. it 'removes the muting relation between user and target user' do
  119. expect(user.account.muting?(other_account)).to be false
  120. end
  121. end
  122. describe 'GET #relationships' do
  123. let(:simon) { Fabricate(:user, email: 'simon@example.com', account: Fabricate(:account, username: 'simon')).account }
  124. let(:lewis) { Fabricate(:user, email: 'lewis@example.com', account: Fabricate(:account, username: 'lewis')).account }
  125. before do
  126. user.account.follow!(simon)
  127. lewis.follow!(user.account)
  128. end
  129. context 'provided only one ID' do
  130. before do
  131. get :relationships, params: { id: simon.id }
  132. end
  133. it 'returns http success' do
  134. expect(response).to have_http_status(:success)
  135. end
  136. it 'returns JSON with correct data' do
  137. json = body_as_json
  138. expect(json).to be_a Enumerable
  139. expect(json.first[:following]).to be true
  140. expect(json.first[:followed_by]).to be false
  141. end
  142. end
  143. context 'provided multiple IDs' do
  144. before do
  145. get :relationships, params: { id: [simon.id, lewis.id] }
  146. end
  147. it 'returns http success' do
  148. expect(response).to have_http_status(:success)
  149. end
  150. xit 'returns JSON with correct data' do
  151. # todo
  152. end
  153. end
  154. end
  155. end