2023-05-24 11:55:40 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
require 'mastodon/cli/domains'
|
|
|
|
|
2024-09-04 07:12:25 +02:00
|
|
|
RSpec.describe Mastodon::CLI::Domains do
|
2023-12-07 14:49:14 +01:00
|
|
|
subject { cli.invoke(action, arguments, options) }
|
|
|
|
|
2023-12-04 10:09:05 +01:00
|
|
|
let(:cli) { described_class.new }
|
2023-12-07 14:49:14 +01:00
|
|
|
let(:arguments) { [] }
|
|
|
|
let(:options) { {} }
|
2023-12-04 10:09:05 +01:00
|
|
|
|
2023-12-01 13:00:34 +01:00
|
|
|
it_behaves_like 'CLI Command'
|
2023-12-04 10:09:05 +01:00
|
|
|
|
|
|
|
describe '#purge' do
|
2023-12-07 14:49:14 +01:00
|
|
|
let(:action) { :purge }
|
|
|
|
|
2024-03-14 09:58:53 +01:00
|
|
|
context 'with invalid limited federation mode argument' do
|
|
|
|
let(:arguments) { ['example.host'] }
|
|
|
|
let(:options) { { limited_federation_mode: true } }
|
|
|
|
|
|
|
|
it 'warns about usage and exits' do
|
|
|
|
expect { subject }
|
|
|
|
.to raise_error(Thor::Error, /DOMAIN parameter not supported/)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'without a domains argument' do
|
|
|
|
it 'warns about usage and exits' do
|
|
|
|
expect { subject }
|
|
|
|
.to raise_error(Thor::Error, 'No domain(s) given')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-12-04 10:09:05 +01:00
|
|
|
context 'with accounts from the domain' do
|
|
|
|
let(:domain) { 'host.example' }
|
|
|
|
let!(:account) { Fabricate(:account, domain: domain) }
|
2023-12-07 14:49:14 +01:00
|
|
|
let(:arguments) { [domain] }
|
2023-12-04 10:09:05 +01:00
|
|
|
|
|
|
|
it 'removes the account' do
|
2023-12-07 14:49:14 +01:00
|
|
|
expect { subject }
|
|
|
|
.to output_results('Removed 1 accounts')
|
|
|
|
|
2023-12-04 10:09:05 +01:00
|
|
|
expect { account.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2023-12-08 10:51:57 +01:00
|
|
|
|
|
|
|
describe '#crawl' do
|
|
|
|
let(:action) { :crawl }
|
|
|
|
|
|
|
|
context 'with accounts from the domain' do
|
|
|
|
let(:domain) { 'host.example' }
|
|
|
|
|
|
|
|
before do
|
|
|
|
Fabricate(:account, domain: domain)
|
|
|
|
stub_request(:get, 'https://host.example/api/v1/instance').to_return(status: 200, body: {}.to_json)
|
|
|
|
stub_request(:get, 'https://host.example/api/v1/instance/peers').to_return(status: 200, body: {}.to_json)
|
|
|
|
stub_request(:get, 'https://host.example/api/v1/instance/activity').to_return(status: 200, body: {}.to_json)
|
|
|
|
stub_const('Mastodon::CLI::Domains::CRAWL_SLEEP_TIME', 0)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with --format of summary' do
|
|
|
|
let(:options) { { format: 'summary' } }
|
|
|
|
|
|
|
|
it 'crawls the domains and summarizes results' do
|
|
|
|
expect { subject }
|
|
|
|
.to output_results('Visited 1 domains, 0 failed')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with --format of domains' do
|
|
|
|
let(:options) { { format: 'domains' } }
|
|
|
|
|
|
|
|
it 'crawls the domains and summarizes results' do
|
|
|
|
expect { subject }
|
|
|
|
.to output_results(domain)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with --format of json' do
|
|
|
|
let(:options) { { format: 'json' } }
|
|
|
|
|
|
|
|
it 'crawls the domains and summarizes results' do
|
|
|
|
expect { subject }
|
|
|
|
.to output_results(json_summary)
|
|
|
|
end
|
|
|
|
|
|
|
|
def json_summary
|
|
|
|
Oj.dump('host.example': { activity: {} })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2023-05-24 11:55:40 +02:00
|
|
|
end
|