Merge commit 'e5655a5f65eb8116640ae434125553e0fe77f35e' into glitch-soc/merge-upstream

This commit is contained in:
Claire
2025-03-06 20:10:00 +01:00
40 changed files with 284 additions and 179 deletions

View File

@@ -193,4 +193,57 @@ RSpec.describe 'Media' do
end
end
end
describe 'DELETE /api/v1/media/:id' do
subject do
delete "/api/v1/media/#{media.id}", headers: headers
end
context 'when media is not attached to a status' do
let(:media) { Fabricate(:media_attachment, account: user.account, status: nil) }
it 'returns http empty response' do
subject
expect(response).to have_http_status(200)
expect(response.content_type)
.to start_with('application/json')
expect(MediaAttachment.where(id: media.id)).to_not exist
end
end
context 'when media is attached to a status' do
let(:media) { Fabricate(:media_attachment, account: user.account, status: Fabricate.build(:status)) }
it 'returns http unprocessable entity' do
subject
expect(response).to have_http_status(422)
expect(response.content_type)
.to start_with('application/json')
expect(response.parsed_body).to match(
a_hash_including(
error: 'Media attachment is currently used by a status'
)
)
expect(MediaAttachment.where(id: media.id)).to exist
end
end
context 'when the media belongs to somebody else' do
let(:media) { Fabricate(:media_attachment, status: nil) }
it 'returns http not found' do
subject
expect(response).to have_http_status(404)
expect(response.content_type)
.to start_with('application/json')
expect(MediaAttachment.where(id: media.id)).to exist
end
end
end
end

View File

@@ -257,13 +257,30 @@ RSpec.describe '/api/v1/statuses' do
it_behaves_like 'forbidden for wrong scope', 'read read:statuses'
it 'removes the status', :aggregate_failures do
it 'discards the status and schedules removal as a redraft', :aggregate_failures do
subject
expect(response).to have_http_status(200)
expect(response.content_type)
.to start_with('application/json')
expect(Status.find_by(id: status.id)).to be_nil
expect(RemovalWorker).to have_enqueued_sidekiq_job(status.id, { 'redraft' => true })
end
context 'when called with truthy delete_media' do
subject do
delete "/api/v1/statuses/#{status.id}?delete_media=true", headers: headers
end
it 'discards the status and schedules removal without the redraft flag', :aggregate_failures do
subject
expect(response).to have_http_status(200)
expect(response.content_type)
.to start_with('application/json')
expect(Status.find_by(id: status.id)).to be_nil
expect(RemovalWorker).to have_enqueued_sidekiq_job(status.id, { 'redraft' => false })
end
end
end