reblogs_spec.rb 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe 'API V1 Statuses Reblogs' do
  4. let(:user) { Fabricate(:user) }
  5. let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
  6. let(:scopes) { 'write:statuses' }
  7. let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
  8. context 'with an oauth token' do
  9. describe 'POST /api/v1/statuses/:status_id/reblog' do
  10. let(:status) { Fabricate(:status, account: user.account) }
  11. before do
  12. post "/api/v1/statuses/#{status.id}/reblog", headers: headers
  13. end
  14. context 'with public status' do
  15. it 'reblogs the status', :aggregate_failures do
  16. expect(response).to have_http_status(200)
  17. expect(status.reblogs.count).to eq 1
  18. expect(user.account.reblogged?(status)).to be true
  19. hash_body = body_as_json
  20. expect(hash_body[:reblog][:id]).to eq status.id.to_s
  21. expect(hash_body[:reblog][:reblogs_count]).to eq 1
  22. expect(hash_body[:reblog][:reblogged]).to be true
  23. end
  24. end
  25. context 'with private status of not-followed account' do
  26. let(:status) { Fabricate(:status, visibility: :private) }
  27. it 'returns http not found' do
  28. expect(response).to have_http_status(404)
  29. end
  30. end
  31. end
  32. describe 'POST /api/v1/statuses/:status_id/unreblog', :sidekiq_inline do
  33. context 'with public status' do
  34. let(:status) { Fabricate(:status, account: user.account) }
  35. before do
  36. ReblogService.new.call(user.account, status)
  37. post "/api/v1/statuses/#{status.id}/unreblog", headers: headers
  38. end
  39. it 'destroys the reblog', :aggregate_failures do
  40. expect(response).to have_http_status(200)
  41. expect(status.reblogs.count).to eq 0
  42. expect(user.account.reblogged?(status)).to be false
  43. hash_body = body_as_json
  44. expect(hash_body[:id]).to eq status.id.to_s
  45. expect(hash_body[:reblogs_count]).to eq 0
  46. expect(hash_body[:reblogged]).to be false
  47. end
  48. end
  49. context 'with public status when blocked by its author' do
  50. let(:status) { Fabricate(:status, account: user.account) }
  51. before do
  52. ReblogService.new.call(user.account, status)
  53. status.account.block!(user.account)
  54. post "/api/v1/statuses/#{status.id}/unreblog", headers: headers
  55. end
  56. it 'destroys the reblog', :aggregate_failures do
  57. expect(response).to have_http_status(200)
  58. expect(status.reblogs.count).to eq 0
  59. expect(user.account.reblogged?(status)).to be false
  60. hash_body = body_as_json
  61. expect(hash_body[:id]).to eq status.id.to_s
  62. expect(hash_body[:reblogs_count]).to eq 0
  63. expect(hash_body[:reblogged]).to be false
  64. end
  65. end
  66. context 'with private status that was not reblogged' do
  67. let(:status) { Fabricate(:status, visibility: :private) }
  68. before do
  69. post "/api/v1/statuses/#{status.id}/unreblog", headers: headers
  70. end
  71. it 'returns http not found' do
  72. expect(response).to have_http_status(404)
  73. end
  74. end
  75. end
  76. end
  77. end