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.

206 lines
5.0 KiB

  1. require 'rails_helper'
  2. RSpec.describe Api::V1::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 #reblogged_by' do
  28. let(:status) { Fabricate(:status, account: user.account) }
  29. before do
  30. post :reblog, params: { id: status.id }
  31. end
  32. it 'returns http success' do
  33. get :reblogged_by, params: { id: status.id }
  34. expect(response).to have_http_status(:success)
  35. end
  36. end
  37. describe 'GET #favourited_by' do
  38. let(:status) { Fabricate(:status, account: user.account) }
  39. before do
  40. post :favourite, params: { id: status.id }
  41. end
  42. it 'returns http success' do
  43. get :favourited_by, params: { id: status.id }
  44. expect(response).to have_http_status(:success)
  45. end
  46. end
  47. describe 'GET #home' do
  48. it 'returns http success' do
  49. get :home
  50. expect(response).to have_http_status(:success)
  51. end
  52. end
  53. describe 'GET #mentions' do
  54. it 'returns http success' do
  55. get :mentions
  56. expect(response).to have_http_status(:success)
  57. end
  58. end
  59. describe 'GET #public' do
  60. it 'returns http success' do
  61. get :public
  62. expect(response).to have_http_status(:success)
  63. end
  64. end
  65. describe 'POST #create' do
  66. before do
  67. post :create, params: { status: 'Hello world' }
  68. end
  69. it 'returns http success' do
  70. expect(response).to have_http_status(:success)
  71. end
  72. end
  73. describe 'DELETE #destroy' do
  74. let(:status) { Fabricate(:status, account: user.account) }
  75. before do
  76. post :destroy, params: { id: status.id }
  77. end
  78. it 'returns http success' do
  79. expect(response).to have_http_status(:success)
  80. end
  81. it 'removes the status' do
  82. expect(Status.find_by(id: status.id)).to be nil
  83. end
  84. end
  85. describe 'POST #reblog' do
  86. let(:status) { Fabricate(:status, account: user.account) }
  87. before do
  88. post :reblog, params: { id: status.id }
  89. end
  90. it 'returns http success' do
  91. expect(response).to have_http_status(:success)
  92. end
  93. it 'updates the reblogs count' do
  94. expect(status.reblogs_count).to eq 1
  95. end
  96. it 'updates the reblogged attribute' do
  97. expect(user.account.reblogged?(status)).to be true
  98. end
  99. it 'return json with updated attributes' do
  100. hash_body = body_as_json
  101. expect(hash_body[:reblog][:id]).to eq status.id
  102. expect(hash_body[:reblog][:reblogs_count]).to eq 1
  103. expect(hash_body[:reblog][:reblogged]).to be true
  104. end
  105. end
  106. describe 'POST #unreblog' do
  107. let(:status) { Fabricate(:status, account: user.account) }
  108. before do
  109. post :reblog, params: { id: status.id }
  110. post :unreblog, params: { id: status.id }
  111. end
  112. it 'returns http success' do
  113. expect(response).to have_http_status(:success)
  114. end
  115. it 'updates the reblogs count' do
  116. expect(status.reblogs_count).to eq 0
  117. end
  118. it 'updates the reblogged attribute' do
  119. expect(user.account.reblogged?(status)).to be false
  120. end
  121. end
  122. describe 'POST #favourite' do
  123. let(:status) { Fabricate(:status, account: user.account) }
  124. before do
  125. post :favourite, params: { id: status.id }
  126. end
  127. it 'returns http success' do
  128. expect(response).to have_http_status(:success)
  129. end
  130. it 'updates the favourites count' do
  131. expect(status.favourites_count).to eq 1
  132. end
  133. it 'updates the favourited attribute' do
  134. expect(user.account.favourited?(status)).to be true
  135. end
  136. it 'return json with updated attributes' do
  137. hash_body = body_as_json
  138. expect(hash_body[:id]).to eq status.id
  139. expect(hash_body[:favourites_count]).to eq 1
  140. expect(hash_body[:favourited]).to be true
  141. end
  142. end
  143. describe 'POST #unfavourite' do
  144. let(:status) { Fabricate(:status, account: user.account) }
  145. before do
  146. post :favourite, params: { id: status.id }
  147. post :unfavourite, params: { id: status.id }
  148. end
  149. it 'returns http success' do
  150. expect(response).to have_http_status(:success)
  151. end
  152. it 'updates the favourites count' do
  153. expect(status.favourites_count).to eq 0
  154. end
  155. it 'updates the favourited attribute' do
  156. expect(user.account.favourited?(status)).to be false
  157. end
  158. end
  159. end