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.

161 lines
4.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. 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 'POST #follow' do
  41. let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
  42. before do
  43. post :follow, params: { id: other_account.id }
  44. end
  45. it 'returns http success' do
  46. expect(response).to have_http_status(:success)
  47. end
  48. it 'creates a following relation between user and target user' do
  49. expect(user.account.following?(other_account)).to be true
  50. end
  51. end
  52. describe 'POST #unfollow' do
  53. let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
  54. before do
  55. user.account.follow!(other_account)
  56. post :unfollow, params: { id: other_account.id }
  57. end
  58. it 'returns http success' do
  59. expect(response).to have_http_status(:success)
  60. end
  61. it 'removes the following relation between user and target user' do
  62. expect(user.account.following?(other_account)).to be false
  63. end
  64. end
  65. describe 'POST #block' do
  66. let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
  67. before do
  68. user.account.follow!(other_account)
  69. post :block, params: { id: other_account.id }
  70. end
  71. it 'returns http success' do
  72. expect(response).to have_http_status(:success)
  73. end
  74. it 'removes the following relation between user and target user' do
  75. expect(user.account.following?(other_account)).to be false
  76. end
  77. it 'creates a blocking relation' do
  78. expect(user.account.blocking?(other_account)).to be true
  79. end
  80. end
  81. describe 'POST #unblock' do
  82. let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
  83. before do
  84. user.account.block!(other_account)
  85. post :unblock, params: { id: other_account.id }
  86. end
  87. it 'returns http success' do
  88. expect(response).to have_http_status(:success)
  89. end
  90. it 'removes the blocking relation between user and target user' do
  91. expect(user.account.blocking?(other_account)).to be false
  92. end
  93. end
  94. describe 'GET #relationships' do
  95. let(:simon) { Fabricate(:user, email: 'simon@example.com', account: Fabricate(:account, username: 'simon')).account }
  96. let(:lewis) { Fabricate(:user, email: 'lewis@example.com', account: Fabricate(:account, username: 'lewis')).account }
  97. before do
  98. user.account.follow!(simon)
  99. lewis.follow!(user.account)
  100. end
  101. context 'provided only one ID' do
  102. before do
  103. get :relationships, params: { id: simon.id }
  104. end
  105. it 'returns http success' do
  106. expect(response).to have_http_status(:success)
  107. end
  108. it 'returns JSON with correct data' do
  109. json = body_as_json
  110. expect(json).to be_a Enumerable
  111. expect(json.first[:following]).to be true
  112. expect(json.first[:followed_by]).to be false
  113. end
  114. end
  115. context 'provided multiple IDs' do
  116. before do
  117. get :relationships, params: { id: [simon.id, lewis.id] }
  118. end
  119. it 'returns http success' do
  120. expect(response).to have_http_status(:success)
  121. end
  122. xit 'returns JSON with correct data' do
  123. # todo
  124. end
  125. end
  126. end
  127. end