闭社主体 forked from https://github.com/tootsuite/mastodon
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.

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