reblogs_spec.rb 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.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(response.content_type)
  18. .to start_with('application/json')
  19. expect(status.reblogs.count).to eq 1
  20. expect(user.account.reblogged?(status)).to be true
  21. expect(response.parsed_body)
  22. .to include(
  23. reblog: include(
  24. id: status.id.to_s,
  25. reblogs_count: 1,
  26. reblogged: true
  27. )
  28. )
  29. end
  30. end
  31. context 'with private status of not-followed account' do
  32. let(:status) { Fabricate(:status, visibility: :private) }
  33. it 'returns http not found' do
  34. expect(response).to have_http_status(404)
  35. expect(response.content_type)
  36. .to start_with('application/json')
  37. end
  38. end
  39. end
  40. describe 'POST /api/v1/statuses/:status_id/unreblog', :inline_jobs do
  41. context 'with public status' do
  42. let(:status) { Fabricate(:status, account: user.account) }
  43. before do
  44. ReblogService.new.call(user.account, status)
  45. post "/api/v1/statuses/#{status.id}/unreblog", headers: headers
  46. end
  47. it 'destroys the reblog', :aggregate_failures do
  48. expect(response).to have_http_status(200)
  49. expect(response.content_type)
  50. .to start_with('application/json')
  51. expect(status.reblogs.count).to eq 0
  52. expect(user.account.reblogged?(status)).to be false
  53. expect(response.parsed_body)
  54. .to include(
  55. id: status.id.to_s,
  56. reblogs_count: 0,
  57. reblogged: false
  58. )
  59. end
  60. end
  61. context 'with public status when blocked by its author' do
  62. let(:status) { Fabricate(:status, account: user.account) }
  63. before do
  64. ReblogService.new.call(user.account, status)
  65. status.account.block!(user.account)
  66. post "/api/v1/statuses/#{status.id}/unreblog", headers: headers
  67. end
  68. it 'destroys the reblog', :aggregate_failures do
  69. expect(response).to have_http_status(200)
  70. expect(response.content_type)
  71. .to start_with('application/json')
  72. expect(status.reblogs.count).to eq 0
  73. expect(user.account.reblogged?(status)).to be false
  74. expect(response.parsed_body)
  75. .to include(
  76. id: status.id.to_s,
  77. reblogs_count: 0,
  78. reblogged: false
  79. )
  80. end
  81. end
  82. context 'with private status that was not reblogged' do
  83. let(:status) { Fabricate(:status, visibility: :private) }
  84. before do
  85. post "/api/v1/statuses/#{status.id}/unreblog", headers: headers
  86. end
  87. it 'returns http not found' do
  88. expect(response).to have_http_status(404)
  89. expect(response.content_type)
  90. .to start_with('application/json')
  91. end
  92. end
  93. end
  94. end
  95. end