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.

173 lines
4.3 KiB

  1. require 'rails_helper'
  2. RSpec.describe Api::StatusesController, 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. let(:status) { Fabricate(:status, account: user.account) }
  12. it 'returns http success' do
  13. get :show, params: { id: status.id }
  14. expect(response).to have_http_status(:success)
  15. end
  16. end
  17. describe 'GET #context' do
  18. let(:status) { Fabricate(:status, account: user.account) }
  19. before do
  20. Fabricate(:status, account: user.account, thread: status)
  21. end
  22. it 'returns http success' do
  23. get :context, params: { id: status.id }
  24. expect(response).to have_http_status(:success)
  25. end
  26. end
  27. describe 'GET #home' do
  28. it 'returns http success' do
  29. get :home
  30. expect(response).to have_http_status(:success)
  31. end
  32. end
  33. describe 'GET #mentions' do
  34. it 'returns http success' do
  35. get :mentions
  36. expect(response).to have_http_status(:success)
  37. end
  38. end
  39. describe 'POST #create' do
  40. before do
  41. post :create, params: { status: 'Hello world' }
  42. end
  43. it 'returns http success' do
  44. expect(response).to have_http_status(:success)
  45. end
  46. end
  47. describe 'DELETE #destroy' do
  48. let(:status) { Fabricate(:status, account: user.account) }
  49. before do
  50. post :destroy, params: { id: status.id }
  51. end
  52. it 'returns http success' do
  53. expect(response).to have_http_status(:success)
  54. end
  55. it 'removes the status' do
  56. expect(Status.find_by(id: status.id)).to be nil
  57. end
  58. end
  59. describe 'POST #reblog' do
  60. let(:status) { Fabricate(:status, account: user.account) }
  61. before do
  62. post :reblog, params: { id: status.id }
  63. end
  64. it 'returns http success' do
  65. expect(response).to have_http_status(:success)
  66. end
  67. it 'updates the reblogs count' do
  68. expect(status.reblogs_count).to eq 1
  69. end
  70. it 'updates the reblogged attribute' do
  71. expect(user.account.reblogged?(status)).to be true
  72. end
  73. it 'return json with updated attributes' do
  74. hash_body = body_as_json
  75. expect(hash_body[:reblog][:id]).to eq status.id
  76. expect(hash_body[:reblog][:reblogs_count]).to eq 1
  77. expect(hash_body[:reblog][:reblogged]).to be true
  78. end
  79. end
  80. describe 'POST #unreblog' do
  81. let(:status) { Fabricate(:status, account: user.account) }
  82. before do
  83. post :reblog, params: { id: status.id }
  84. post :unreblog, params: { id: status.id }
  85. end
  86. it 'returns http success' do
  87. expect(response).to have_http_status(:success)
  88. end
  89. it 'updates the reblogs count' do
  90. expect(status.reblogs_count).to eq 0
  91. end
  92. it 'updates the reblogged attribute' do
  93. expect(user.account.reblogged?(status)).to be false
  94. end
  95. end
  96. describe 'POST #favourite' do
  97. let(:status) { Fabricate(:status, account: user.account) }
  98. before do
  99. post :favourite, params: { id: status.id }
  100. end
  101. it 'returns http success' do
  102. expect(response).to have_http_status(:success)
  103. end
  104. it 'updates the favourites count' do
  105. expect(status.favourites_count).to eq 1
  106. end
  107. it 'updates the favourited attribute' do
  108. expect(user.account.favourited?(status)).to be true
  109. end
  110. it 'return json with updated attributes' do
  111. hash_body = body_as_json
  112. expect(hash_body[:id]).to eq status.id
  113. expect(hash_body[:favourites_count]).to eq 1
  114. expect(hash_body[:favourited]).to be true
  115. end
  116. end
  117. describe 'POST #unfavourite' do
  118. let(:status) { Fabricate(:status, account: user.account) }
  119. before do
  120. post :favourite, params: { id: status.id }
  121. post :unfavourite, params: { id: status.id }
  122. end
  123. it 'returns http success' do
  124. expect(response).to have_http_status(:success)
  125. end
  126. it 'updates the favourites count' do
  127. expect(status.favourites_count).to eq 0
  128. end
  129. it 'updates the favourited attribute' do
  130. expect(user.account.favourited?(status)).to be false
  131. end
  132. end
  133. end