Add test to cover proper URL for media in DELETE /api/v1/statuses/:id (#38037)

This commit is contained in:
Claire
2026-03-03 16:36:54 +01:00
committed by GitHub
parent de4ee8565c
commit a3aeae0288
2 changed files with 12 additions and 0 deletions

View File

@@ -127,6 +127,8 @@ class Api::V1::StatusesController < Api::BaseController
@status = Status.where(account: current_account).find(params[:id])
authorize @status, :destroy?
# JSON is generated before `discard_with_reblogs` in order to have the proper URL
# for media attachments, as it would otherwise redirect to the media proxy
json = render_to_body json: @status, serializer: REST::StatusSerializer, source_requested: true
@status.discard_with_reblogs

View File

@@ -459,6 +459,7 @@ RSpec.describe '/api/v1/statuses' do
let(:scopes) { 'write:statuses' }
let(:status) { Fabricate(:status, account: user.account) }
let!(:media) { Fabricate(:media_attachment, status: status) }
it_behaves_like 'forbidden for wrong scope', 'read read:statuses'
@@ -468,6 +469,15 @@ RSpec.describe '/api/v1/statuses' do
expect(response).to have_http_status(200)
expect(response.content_type)
.to start_with('application/json')
expect(response.parsed_body).to include(
id: status.id.to_s,
media_attachments: contain_exactly(
a_hash_including(
id: media.id.to_s,
url: %r{/system/media_attachments/files/}
)
)
)
expect(Status.find_by(id: status.id)).to be_nil
expect(RemovalWorker).to have_enqueued_sidekiq_job(status.id, { 'redraft' => true })
end