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.

116 lines
3.3 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 #statuses' do
  17. it 'returns http success' do
  18. get :statuses, params: { id: user.account.id }
  19. expect(response).to have_http_status(:success)
  20. end
  21. end
  22. describe 'GET #followers' do
  23. it 'returns http success' do
  24. get :followers, params: { id: user.account.id }
  25. expect(response).to have_http_status(:success)
  26. end
  27. end
  28. describe 'GET #following' do
  29. it 'returns http success' do
  30. get :following, params: { id: user.account.id }
  31. expect(response).to have_http_status(:success)
  32. end
  33. end
  34. describe 'POST #follow' do
  35. let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
  36. before do
  37. post :follow, params: { id: other_account.id }
  38. end
  39. it 'returns http success' do
  40. expect(response).to have_http_status(:success)
  41. end
  42. it 'creates a following relation between user and target user' do
  43. expect(user.account.following?(other_account)).to be true
  44. end
  45. end
  46. describe 'POST #unfollow' do
  47. let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
  48. before do
  49. user.account.follow!(other_account)
  50. post :unfollow, params: { id: other_account.id }
  51. end
  52. it 'returns http success' do
  53. expect(response).to have_http_status(:success)
  54. end
  55. it 'removes the following relation between user and target user' do
  56. expect(user.account.following?(other_account)).to be false
  57. end
  58. end
  59. describe 'GET #relationships' do
  60. let(:simon) { Fabricate(:user, email: 'simon@example.com', account: Fabricate(:account, username: 'simon')).account }
  61. let(:lewis) { Fabricate(:user, email: 'lewis@example.com', account: Fabricate(:account, username: 'lewis')).account }
  62. before do
  63. user.account.follow!(simon)
  64. lewis.follow!(user.account)
  65. end
  66. context 'provided only one ID' do
  67. before do
  68. get :relationships, params: { id: simon.id }
  69. end
  70. it 'returns http success' do
  71. expect(response).to have_http_status(:success)
  72. end
  73. it 'returns JSON with correct data' do
  74. json = body_as_json
  75. expect(json).to be_a Enumerable
  76. expect(json.first[:following]).to be true
  77. expect(json.first[:followed_by]).to be false
  78. end
  79. end
  80. context 'provided multiple IDs' do
  81. before do
  82. get :relationships, params: { id: [simon.id, lewis.id] }
  83. end
  84. it 'returns http success' do
  85. expect(response).to have_http_status(:success)
  86. end
  87. xit 'returns JSON with correct data' do
  88. # todo
  89. end
  90. end
  91. end
  92. end