闭社主体 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.

185 lines
4.6 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(:app) { Fabricate(:application, name: 'Test app', website: 'http://testapp.com') }
  6. let(:token) { double acceptable?: true, resource_owner_id: user.id, application: app }
  7. before do
  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 'POST #create' do
  48. before do
  49. post :create, params: { status: 'Hello world' }
  50. end
  51. it 'returns http success' do
  52. expect(response).to have_http_status(:success)
  53. end
  54. end
  55. describe 'DELETE #destroy' do
  56. let(:status) { Fabricate(:status, account: user.account) }
  57. before do
  58. post :destroy, params: { id: status.id }
  59. end
  60. it 'returns http success' do
  61. expect(response).to have_http_status(:success)
  62. end
  63. it 'removes the status' do
  64. expect(Status.find_by(id: status.id)).to be nil
  65. end
  66. end
  67. describe 'POST #reblog' do
  68. let(:status) { Fabricate(:status, account: user.account) }
  69. before do
  70. post :reblog, params: { id: status.id }
  71. end
  72. it 'returns http success' do
  73. expect(response).to have_http_status(:success)
  74. end
  75. it 'updates the reblogs count' do
  76. expect(status.reblogs.count).to eq 1
  77. end
  78. it 'updates the reblogged attribute' do
  79. expect(user.account.reblogged?(status)).to be true
  80. end
  81. it 'return json with updated attributes' do
  82. hash_body = body_as_json
  83. expect(hash_body[:reblog][:id]).to eq status.id
  84. expect(hash_body[:reblog][:reblogs_count]).to eq 1
  85. expect(hash_body[:reblog][:reblogged]).to be true
  86. end
  87. end
  88. describe 'POST #unreblog' do
  89. let(:status) { Fabricate(:status, account: user.account) }
  90. before do
  91. post :reblog, params: { id: status.id }
  92. post :unreblog, params: { id: status.id }
  93. end
  94. it 'returns http success' do
  95. expect(response).to have_http_status(:success)
  96. end
  97. it 'updates the reblogs count' do
  98. expect(status.reblogs.count).to eq 0
  99. end
  100. it 'updates the reblogged attribute' do
  101. expect(user.account.reblogged?(status)).to be false
  102. end
  103. end
  104. describe 'POST #favourite' do
  105. let(:status) { Fabricate(:status, account: user.account) }
  106. before do
  107. post :favourite, params: { id: status.id }
  108. end
  109. it 'returns http success' do
  110. expect(response).to have_http_status(:success)
  111. end
  112. it 'updates the favourites count' do
  113. expect(status.favourites.count).to eq 1
  114. end
  115. it 'updates the favourited attribute' do
  116. expect(user.account.favourited?(status)).to be true
  117. end
  118. it 'return json with updated attributes' do
  119. hash_body = body_as_json
  120. expect(hash_body[:id]).to eq status.id
  121. expect(hash_body[:favourites_count]).to eq 1
  122. expect(hash_body[:favourited]).to be true
  123. end
  124. end
  125. describe 'POST #unfavourite' do
  126. let(:status) { Fabricate(:status, account: user.account) }
  127. before do
  128. post :favourite, params: { id: status.id }
  129. post :unfavourite, params: { id: status.id }
  130. end
  131. it 'returns http success' do
  132. expect(response).to have_http_status(:success)
  133. end
  134. it 'updates the favourites count' do
  135. expect(status.favourites.count).to eq 0
  136. end
  137. it 'updates the favourited attribute' do
  138. expect(user.account.favourited?(status)).to be false
  139. end
  140. end
  141. end