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

127 lines
3.4 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. context 'with an oauth token' do
  8. before do
  9. allow(controller).to receive(:doorkeeper_token) { token }
  10. end
  11. describe 'GET #show' do
  12. let(:status) { Fabricate(:status, account: user.account) }
  13. it 'returns http success' do
  14. get :show, params: { id: status.id }
  15. expect(response).to have_http_status(:success)
  16. end
  17. end
  18. describe 'GET #context' do
  19. let(:status) { Fabricate(:status, account: user.account) }
  20. before do
  21. Fabricate(:status, account: user.account, thread: status)
  22. end
  23. it 'returns http success' do
  24. get :context, params: { id: status.id }
  25. expect(response).to have_http_status(:success)
  26. end
  27. end
  28. describe 'POST #create' do
  29. before do
  30. post :create, params: { status: 'Hello world' }
  31. end
  32. it 'returns http success' do
  33. expect(response).to have_http_status(:success)
  34. end
  35. end
  36. describe 'DELETE #destroy' do
  37. let(:status) { Fabricate(:status, account: user.account) }
  38. before do
  39. post :destroy, params: { id: status.id }
  40. end
  41. it 'returns http success' do
  42. expect(response).to have_http_status(:success)
  43. end
  44. it 'removes the status' do
  45. expect(Status.find_by(id: status.id)).to be nil
  46. end
  47. end
  48. end
  49. context 'without an oauth token' do
  50. before do
  51. allow(controller).to receive(:doorkeeper_token) { nil }
  52. end
  53. context 'with a private status' do
  54. let(:status) { Fabricate(:status, account: user.account, visibility: :private) }
  55. describe 'GET #show' do
  56. it 'returns http unautharized' do
  57. get :show, params: { id: status.id }
  58. expect(response).to have_http_status(:missing)
  59. end
  60. end
  61. describe 'GET #context' do
  62. before do
  63. Fabricate(:status, account: user.account, thread: status)
  64. end
  65. it 'returns http unautharized' do
  66. get :context, params: { id: status.id }
  67. expect(response).to have_http_status(:missing)
  68. end
  69. end
  70. describe 'GET #card' do
  71. it 'returns http unautharized' do
  72. get :card, params: { id: status.id }
  73. expect(response).to have_http_status(:missing)
  74. end
  75. end
  76. end
  77. context 'with a public status' do
  78. let(:status) { Fabricate(:status, account: user.account, visibility: :public) }
  79. describe 'GET #show' do
  80. it 'returns http success' do
  81. get :show, params: { id: status.id }
  82. expect(response).to have_http_status(:success)
  83. end
  84. end
  85. describe 'GET #context' do
  86. before do
  87. Fabricate(:status, account: user.account, thread: status)
  88. end
  89. it 'returns http success' do
  90. get :context, params: { id: status.id }
  91. expect(response).to have_http_status(:success)
  92. end
  93. end
  94. describe 'GET #card' do
  95. it 'returns http success' do
  96. get :card, params: { id: status.id }
  97. expect(response).to have_http_status(:success)
  98. end
  99. end
  100. end
  101. end
  102. end