reblogs_controller_spec.rb 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe Api::V1::Statuses::ReblogsController do
  4. render_views
  5. let(:user) { Fabricate(:user) }
  6. let(:app) { Fabricate(:application, name: 'Test app', website: 'http://testapp.com') }
  7. let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'write:statuses', application: app) }
  8. context 'with an oauth token' do
  9. around do |example|
  10. Sidekiq::Testing.fake! do
  11. example.run
  12. end
  13. end
  14. before do
  15. allow(controller).to receive(:doorkeeper_token) { token }
  16. end
  17. describe 'POST #create' do
  18. let(:status) { Fabricate(:status, account: user.account) }
  19. before do
  20. post :create, params: { status_id: status.id }
  21. end
  22. context 'with public status' do
  23. it 'returns http success' do
  24. expect(response).to have_http_status(200)
  25. end
  26. it 'updates the reblogs count' do
  27. expect(status.reblogs.count).to eq 1
  28. end
  29. it 'updates the reblogged attribute' do
  30. expect(user.account.reblogged?(status)).to be true
  31. end
  32. it 'returns json with updated attributes' do
  33. hash_body = body_as_json
  34. expect(hash_body[:reblog][:id]).to eq status.id.to_s
  35. expect(hash_body[:reblog][:reblogs_count]).to eq 1
  36. expect(hash_body[:reblog][:reblogged]).to be true
  37. end
  38. end
  39. context 'with private status of not-followed account' do
  40. let(:status) { Fabricate(:status, visibility: :private) }
  41. it 'returns http not found' do
  42. expect(response).to have_http_status(404)
  43. end
  44. end
  45. end
  46. describe 'POST #destroy' do
  47. context 'with public status' do
  48. let(:status) { Fabricate(:status, account: user.account) }
  49. before do
  50. ReblogService.new.call(user.account, status)
  51. post :destroy, params: { status_id: status.id }
  52. end
  53. it 'returns http success' do
  54. expect(response).to have_http_status(200)
  55. end
  56. it 'updates the reblogs count' do
  57. expect(status.reblogs.count).to eq 0
  58. end
  59. it 'updates the reblogged attribute' do
  60. expect(user.account.reblogged?(status)).to be false
  61. end
  62. it 'returns json with updated attributes' do
  63. hash_body = body_as_json
  64. expect(hash_body[:id]).to eq status.id.to_s
  65. expect(hash_body[:reblogs_count]).to eq 0
  66. expect(hash_body[:reblogged]).to be false
  67. end
  68. end
  69. context 'with public status when blocked by its author' do
  70. let(:status) { Fabricate(:status, account: user.account) }
  71. before do
  72. ReblogService.new.call(user.account, status)
  73. status.account.block!(user.account)
  74. post :destroy, params: { status_id: status.id }
  75. end
  76. it 'returns http success' do
  77. expect(response).to have_http_status(200)
  78. end
  79. it 'updates the reblogs count' do
  80. expect(status.reblogs.count).to eq 0
  81. end
  82. it 'updates the reblogged attribute' do
  83. expect(user.account.reblogged?(status)).to be false
  84. end
  85. it 'returns json with updated attributes' do
  86. hash_body = body_as_json
  87. expect(hash_body[:id]).to eq status.id.to_s
  88. expect(hash_body[:reblogs_count]).to eq 0
  89. expect(hash_body[:reblogged]).to be false
  90. end
  91. end
  92. context 'with private status that was not reblogged' do
  93. let(:status) { Fabricate(:status, visibility: :private) }
  94. before do
  95. post :destroy, params: { status_id: status.id }
  96. end
  97. it 'returns http not found' do
  98. expect(response).to have_http_status(404)
  99. end
  100. end
  101. end
  102. end
  103. end