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.

160 lines
4.4 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 'GET #relationships' do
  94. let(:simon) { Fabricate(:user, email: 'simon@example.com', account: Fabricate(:account, username: 'simon')).account }
  95. let(:lewis) { Fabricate(:user, email: 'lewis@example.com', account: Fabricate(:account, username: 'lewis')).account }
  96. before do
  97. user.account.follow!(simon)
  98. lewis.follow!(user.account)
  99. end
  100. context 'provided only one ID' do
  101. before do
  102. get :relationships, params: { id: simon.id }
  103. end
  104. it 'returns http success' do
  105. expect(response).to have_http_status(:success)
  106. end
  107. it 'returns JSON with correct data' do
  108. json = body_as_json
  109. expect(json).to be_a Enumerable
  110. expect(json.first[:following]).to be true
  111. expect(json.first[:followed_by]).to be false
  112. end
  113. end
  114. context 'provided multiple IDs' do
  115. before do
  116. get :relationships, params: { id: [simon.id, lewis.id] }
  117. end
  118. it 'returns http success' do
  119. expect(response).to have_http_status(:success)
  120. end
  121. xit 'returns JSON with correct data' do
  122. # todo
  123. end
  124. end
  125. end
  126. end