2023-05-24 09:55:40 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
require 'mastodon/cli/media'
|
|
|
|
|
|
|
|
describe Mastodon::CLI::Media do
|
2023-12-07 13:49:14 +00:00
|
|
|
subject { cli.invoke(action, arguments, options) }
|
|
|
|
|
2023-10-16 16:20:58 +00:00
|
|
|
let(:cli) { described_class.new }
|
2023-12-07 13:49:14 +00:00
|
|
|
let(:arguments) { [] }
|
|
|
|
let(:options) { {} }
|
2023-10-16 16:20:58 +00:00
|
|
|
|
2023-12-01 12:00:34 +00:00
|
|
|
it_behaves_like 'CLI Command'
|
2023-10-16 16:20:58 +00:00
|
|
|
|
|
|
|
describe '#remove' do
|
2023-12-07 13:49:14 +00:00
|
|
|
let(:action) { :remove }
|
|
|
|
|
2023-10-16 16:20:58 +00:00
|
|
|
context 'with --prune-profiles and --remove-headers' do
|
|
|
|
let(:options) { { prune_profiles: true, remove_headers: true } }
|
|
|
|
|
|
|
|
it 'warns about usage and exits' do
|
2023-12-07 13:49:14 +00:00
|
|
|
expect { subject }
|
|
|
|
.to output_results('--prune-profiles and --remove-headers should not be specified simultaneously')
|
|
|
|
.and raise_error(SystemExit)
|
2023-10-16 16:20:58 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with --include-follows but not including --prune-profiles and --remove-headers' do
|
|
|
|
let(:options) { { include_follows: true } }
|
|
|
|
|
|
|
|
it 'warns about usage and exits' do
|
2023-12-07 13:49:14 +00:00
|
|
|
expect { subject }
|
|
|
|
.to output_results('--include-follows can only be used with --prune-profiles or --remove-headers')
|
|
|
|
.and raise_error(SystemExit)
|
2023-10-16 16:20:58 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a relevant account' do
|
|
|
|
let!(:account) do
|
|
|
|
Fabricate(:account, domain: 'example.com', updated_at: 1.month.ago, last_webfingered_at: 1.month.ago, avatar: attachment_fixture('attachment.jpg'), header: attachment_fixture('attachment.jpg'))
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with --prune-profiles' do
|
|
|
|
let(:options) { { prune_profiles: true } }
|
|
|
|
|
|
|
|
it 'removes account avatars' do
|
2023-12-07 13:49:14 +00:00
|
|
|
expect { subject }
|
|
|
|
.to output_results('Visited 1')
|
2023-10-16 16:20:58 +00:00
|
|
|
|
|
|
|
expect(account.reload.avatar).to be_blank
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with --remove-headers' do
|
|
|
|
let(:options) { { remove_headers: true } }
|
|
|
|
|
|
|
|
it 'removes account header' do
|
2023-12-07 13:49:14 +00:00
|
|
|
expect { subject }
|
|
|
|
.to output_results('Visited 1')
|
2023-10-16 16:20:58 +00:00
|
|
|
|
|
|
|
expect(account.reload.header).to be_blank
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a relevant media attachment' do
|
|
|
|
let!(:media_attachment) { Fabricate(:media_attachment, remote_url: 'https://example.com/image.jpg', created_at: 1.month.ago) }
|
|
|
|
|
|
|
|
context 'without options' do
|
|
|
|
it 'removes account avatars' do
|
2023-12-07 13:49:14 +00:00
|
|
|
expect { subject }
|
|
|
|
.to output_results('Removed 1')
|
2023-10-16 16:20:58 +00:00
|
|
|
|
|
|
|
expect(media_attachment.reload.file).to be_blank
|
|
|
|
expect(media_attachment.reload.thumbnail).to be_blank
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2023-12-01 11:56:47 +00:00
|
|
|
|
|
|
|
describe '#usage' do
|
2023-12-07 13:49:14 +00:00
|
|
|
let(:action) { :usage }
|
2023-12-01 11:56:47 +00:00
|
|
|
|
2023-12-07 13:49:14 +00:00
|
|
|
context 'without options' do
|
2023-12-01 11:56:47 +00:00
|
|
|
it 'reports about storage size' do
|
2023-12-07 13:49:14 +00:00
|
|
|
expect { subject }
|
|
|
|
.to output_results('0 Bytes')
|
2023-12-01 11:56:47 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2023-12-01 14:18:45 +00:00
|
|
|
|
2023-12-07 15:27:41 +00:00
|
|
|
describe '#lookup' do
|
|
|
|
let(:action) { :lookup }
|
|
|
|
let(:arguments) { [url] }
|
|
|
|
|
|
|
|
context 'with valid url not connected to a record' do
|
|
|
|
let(:url) { 'https://example.host/assets/1' }
|
|
|
|
|
|
|
|
it 'warns about url and exits' do
|
|
|
|
expect { subject }
|
|
|
|
.to output_results('Not a media URL')
|
|
|
|
.and raise_error(SystemExit)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a valid media url' do
|
|
|
|
let(:status) { Fabricate(:status) }
|
|
|
|
let(:media_attachment) { Fabricate(:media_attachment, status: status) }
|
|
|
|
let(:url) { media_attachment.file.url(:original) }
|
|
|
|
|
|
|
|
it 'displays the url of a connected status' do
|
|
|
|
expect { subject }
|
|
|
|
.to output_results(status.id.to_s)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-12-01 14:18:45 +00:00
|
|
|
describe '#refresh' do
|
2023-12-07 13:49:14 +00:00
|
|
|
let(:action) { :refresh }
|
2023-12-01 14:18:45 +00:00
|
|
|
|
2023-12-07 13:49:14 +00:00
|
|
|
context 'without any options' do
|
2023-12-01 14:18:45 +00:00
|
|
|
it 'warns about usage and exits' do
|
2023-12-07 13:49:14 +00:00
|
|
|
expect { subject }
|
|
|
|
.to output_results('Specify the source')
|
|
|
|
.and raise_error(SystemExit)
|
2023-12-01 14:18:45 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with --status option' do
|
|
|
|
before do
|
|
|
|
media_attachment.update(file_file_name: nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:media_attachment) { Fabricate(:media_attachment, status: status, remote_url: 'https://host.example/asset.jpg') }
|
|
|
|
let(:options) { { status: status.id } }
|
|
|
|
let(:status) { Fabricate(:status) }
|
|
|
|
|
|
|
|
it 'redownloads the attachment file' do
|
2023-12-07 13:49:14 +00:00
|
|
|
expect { subject }
|
|
|
|
.to output_results('Downloaded 1 media')
|
2023-12-01 14:18:45 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with --account option' do
|
|
|
|
context 'when the account does not exist' do
|
|
|
|
let(:options) { { account: 'not-real-user@example.host' } }
|
|
|
|
|
|
|
|
it 'warns about usage and exits' do
|
2023-12-07 13:49:14 +00:00
|
|
|
expect { subject }
|
|
|
|
.to output_results('No such account')
|
|
|
|
.and raise_error(SystemExit)
|
2023-12-01 14:18:45 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the account exists' do
|
|
|
|
before do
|
|
|
|
media_attachment.update(file_file_name: nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:media_attachment) { Fabricate(:media_attachment, account: account) }
|
|
|
|
let(:options) { { account: account.acct } }
|
|
|
|
let(:account) { Fabricate(:account) }
|
|
|
|
|
|
|
|
it 'redownloads the attachment file' do
|
2023-12-07 13:49:14 +00:00
|
|
|
expect { subject }
|
|
|
|
.to output_results('Downloaded 1 media')
|
2023-12-01 14:18:45 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with --domain option' do
|
|
|
|
before do
|
|
|
|
media_attachment.update(file_file_name: nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:domain) { 'example.host' }
|
|
|
|
let(:media_attachment) { Fabricate(:media_attachment, account: account) }
|
|
|
|
let(:options) { { domain: domain } }
|
|
|
|
let(:account) { Fabricate(:account, domain: domain) }
|
|
|
|
|
|
|
|
it 'redownloads the attachment file' do
|
2023-12-07 13:49:14 +00:00
|
|
|
expect { subject }
|
|
|
|
.to output_results('Downloaded 1 media')
|
2023-12-01 14:18:45 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2023-05-24 09:55:40 +00:00
|
|
|
end
|