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

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