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.

175 lines
4.9 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. stub_request(:post, "https://pubsubhubbub.superfeedr.com/").to_return(:status => 200, :body => "", :headers => {})
  8. allow(controller).to receive(:doorkeeper_token) { token }
  9. end
  10. describe 'GET #show' do
  11. it 'returns http success' do
  12. get :show, params: { id: user.account.id }
  13. expect(response).to have_http_status(:success)
  14. end
  15. end
  16. describe 'GET #verify_credentials' do
  17. it 'returns http success' do
  18. get :verify_credentials
  19. expect(response).to have_http_status(:success)
  20. end
  21. end
  22. describe 'GET #statuses' do
  23. it 'returns http success' do
  24. get :statuses, params: { id: user.account.id }
  25. expect(response).to have_http_status(:success)
  26. end
  27. end
  28. describe 'GET #followers' do
  29. it 'returns http success' do
  30. get :followers, params: { id: user.account.id }
  31. expect(response).to have_http_status(:success)
  32. end
  33. end
  34. describe 'GET #following' do
  35. it 'returns http success' do
  36. get :following, params: { id: user.account.id }
  37. expect(response).to have_http_status(:success)
  38. end
  39. end
  40. describe 'GET #suggestions' do
  41. it 'returns http success' do
  42. get :suggestions
  43. expect(response).to have_http_status(:success)
  44. end
  45. end
  46. describe 'GET #common_followers' do
  47. it 'returns http success' do
  48. get :common_followers, params: { id: user.account.id }
  49. expect(response).to have_http_status(:success)
  50. end
  51. end
  52. describe 'POST #follow' do
  53. let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
  54. before do
  55. post :follow, 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 'creates a following relation between user and target user' do
  61. expect(user.account.following?(other_account)).to be true
  62. end
  63. end
  64. describe 'POST #unfollow' 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 :unfollow, 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. end
  77. describe 'POST #block' do
  78. let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
  79. before do
  80. user.account.follow!(other_account)
  81. post :block, params: { id: other_account.id }
  82. end
  83. it 'returns http success' do
  84. expect(response).to have_http_status(:success)
  85. end
  86. it 'removes the following relation between user and target user' do
  87. expect(user.account.following?(other_account)).to be false
  88. end
  89. it 'creates a blocking relation' do
  90. expect(user.account.blocking?(other_account)).to be true
  91. end
  92. end
  93. describe 'POST #unblock' do
  94. let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
  95. before do
  96. user.account.block!(other_account)
  97. post :unblock, 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 'removes the blocking relation between user and target user' do
  103. expect(user.account.blocking?(other_account)).to be false
  104. end
  105. end
  106. describe 'GET #relationships' do
  107. let(:simon) { Fabricate(:user, email: 'simon@example.com', account: Fabricate(:account, username: 'simon')).account }
  108. let(:lewis) { Fabricate(:user, email: 'lewis@example.com', account: Fabricate(:account, username: 'lewis')).account }
  109. before do
  110. user.account.follow!(simon)
  111. lewis.follow!(user.account)
  112. end
  113. context 'provided only one ID' do
  114. before do
  115. get :relationships, params: { id: simon.id }
  116. end
  117. it 'returns http success' do
  118. expect(response).to have_http_status(:success)
  119. end
  120. it 'returns JSON with correct data' do
  121. json = body_as_json
  122. expect(json).to be_a Enumerable
  123. expect(json.first[:following]).to be true
  124. expect(json.first[:followed_by]).to be false
  125. end
  126. end
  127. context 'provided multiple IDs' do
  128. before do
  129. get :relationships, params: { id: [simon.id, lewis.id] }
  130. end
  131. it 'returns http success' do
  132. expect(response).to have_http_status(:success)
  133. end
  134. xit 'returns JSON with correct data' do
  135. # todo
  136. end
  137. end
  138. end
  139. end