reblogs_controller_spec.rb 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. before do
  10. allow(controller).to receive(:doorkeeper_token) { token }
  11. end
  12. describe 'POST #create' do
  13. let(:status) { Fabricate(:status, account: user.account) }
  14. before do
  15. post :create, params: { status_id: status.id }
  16. end
  17. context 'with public status' do
  18. it 'returns http success' do
  19. expect(response).to have_http_status(200)
  20. end
  21. it 'updates the reblogs count' do
  22. expect(status.reblogs.count).to eq 1
  23. end
  24. it 'updates the reblogged attribute' do
  25. expect(user.account.reblogged?(status)).to be true
  26. end
  27. it 'returns json with updated attributes' do
  28. hash_body = body_as_json
  29. expect(hash_body[:reblog][:id]).to eq status.id.to_s
  30. expect(hash_body[:reblog][:reblogs_count]).to eq 1
  31. expect(hash_body[:reblog][:reblogged]).to be true
  32. end
  33. end
  34. context 'with private status of not-followed account' do
  35. let(:status) { Fabricate(:status, visibility: :private) }
  36. it 'returns http not found' do
  37. expect(response).to have_http_status(404)
  38. end
  39. end
  40. end
  41. describe 'POST #destroy' do
  42. context 'with public status' do
  43. let(:status) { Fabricate(:status, account: user.account) }
  44. before do
  45. ReblogService.new.call(user.account, status)
  46. post :destroy, params: { status_id: status.id }
  47. end
  48. it 'returns http success' do
  49. expect(response).to have_http_status(200)
  50. end
  51. it 'updates the reblogs count' do
  52. expect(status.reblogs.count).to eq 0
  53. end
  54. it 'updates the reblogged attribute' do
  55. expect(user.account.reblogged?(status)).to be false
  56. end
  57. it 'returns json with updated attributes' do
  58. hash_body = body_as_json
  59. expect(hash_body[:id]).to eq status.id.to_s
  60. expect(hash_body[:reblogs_count]).to eq 0
  61. expect(hash_body[:reblogged]).to be false
  62. end
  63. end
  64. context 'with public status when blocked by its author' do
  65. let(:status) { Fabricate(:status, account: user.account) }
  66. before do
  67. ReblogService.new.call(user.account, status)
  68. status.account.block!(user.account)
  69. post :destroy, params: { status_id: status.id }
  70. end
  71. it 'returns http success' do
  72. expect(response).to have_http_status(200)
  73. end
  74. it 'updates the reblogs count' do
  75. expect(status.reblogs.count).to eq 0
  76. end
  77. it 'updates the reblogged attribute' do
  78. expect(user.account.reblogged?(status)).to be false
  79. end
  80. it 'returns json with updated attributes' do
  81. hash_body = body_as_json
  82. expect(hash_body[:id]).to eq status.id.to_s
  83. expect(hash_body[:reblogs_count]).to eq 0
  84. expect(hash_body[:reblogged]).to be false
  85. end
  86. end
  87. context 'with private status that was not reblogged' do
  88. let(:status) { Fabricate(:status, visibility: :private) }
  89. before do
  90. post :destroy, params: { status_id: status.id }
  91. end
  92. it 'returns http not found' do
  93. expect(response).to have_http_status(404)
  94. end
  95. end
  96. end
  97. end
  98. end