2023-05-24 09:55:40 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
require 'mastodon/cli/email_domain_blocks'
|
|
|
|
|
2024-09-04 05:12:25 +00:00
|
|
|
RSpec.describe Mastodon::CLI::EmailDomainBlocks do
|
2023-12-07 13:49:14 +00:00
|
|
|
subject { cli.invoke(action, arguments, options) }
|
|
|
|
|
2023-12-04 09:44:54 +00:00
|
|
|
let(:cli) { described_class.new }
|
2023-12-07 13:49:14 +00:00
|
|
|
let(:arguments) { [] }
|
|
|
|
let(:options) { {} }
|
2023-12-04 09:44:54 +00:00
|
|
|
|
2023-12-01 12:00:34 +00:00
|
|
|
it_behaves_like 'CLI Command'
|
2023-12-04 09:44:54 +00:00
|
|
|
|
|
|
|
describe '#list' do
|
2023-12-07 13:49:14 +00:00
|
|
|
let(:action) { :list }
|
|
|
|
|
2023-12-04 09:44:54 +00:00
|
|
|
context 'with email domain block records' do
|
|
|
|
let!(:parent_block) { Fabricate(:email_domain_block) }
|
|
|
|
let!(:child_block) { Fabricate(:email_domain_block, parent: parent_block) }
|
|
|
|
|
|
|
|
it 'lists the blocks' do
|
2023-12-07 13:49:14 +00:00
|
|
|
expect { subject }
|
|
|
|
.to output_results(
|
|
|
|
parent_block.domain,
|
|
|
|
child_block.domain
|
|
|
|
)
|
2023-12-04 09:44:54 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#add' do
|
2023-12-07 13:49:14 +00:00
|
|
|
let(:action) { :add }
|
2023-12-04 09:44:54 +00:00
|
|
|
|
2023-12-07 13:49:14 +00:00
|
|
|
context 'without any options' do
|
2023-12-04 09:44:54 +00:00
|
|
|
it 'warns about usage and exits' do
|
2023-12-07 13:49:14 +00:00
|
|
|
expect { subject }
|
2024-01-26 08:53:44 +00:00
|
|
|
.to raise_error(Thor::Error, 'No domain(s) given')
|
2023-12-04 09:44:54 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when blocks exist' do
|
|
|
|
let(:options) { {} }
|
|
|
|
let(:domain) { 'host.example' }
|
2023-12-07 13:49:14 +00:00
|
|
|
let(:arguments) { [domain] }
|
2023-12-04 09:44:54 +00:00
|
|
|
|
|
|
|
before { Fabricate(:email_domain_block, domain: domain) }
|
|
|
|
|
|
|
|
it 'does not add a new block' do
|
2023-12-07 13:49:14 +00:00
|
|
|
expect { subject }
|
|
|
|
.to output_results('is already blocked')
|
2023-12-04 09:44:54 +00:00
|
|
|
.and(not_change(EmailDomainBlock, :count))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when no blocks exist' do
|
|
|
|
let(:domain) { 'host.example' }
|
2023-12-07 13:49:14 +00:00
|
|
|
let(:arguments) { [domain] }
|
2023-12-04 09:44:54 +00:00
|
|
|
|
|
|
|
it 'adds a new block' do
|
2023-12-07 13:49:14 +00:00
|
|
|
expect { subject }
|
|
|
|
.to output_results('Added 1')
|
2023-12-04 09:44:54 +00:00
|
|
|
.and(change(EmailDomainBlock, :count).by(1))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#remove' do
|
2023-12-07 13:49:14 +00:00
|
|
|
let(:action) { :remove }
|
2023-12-04 09:44:54 +00:00
|
|
|
|
2023-12-07 13:49:14 +00:00
|
|
|
context 'without any options' do
|
2023-12-04 09:44:54 +00:00
|
|
|
it 'warns about usage and exits' do
|
2023-12-07 13:49:14 +00:00
|
|
|
expect { subject }
|
2024-01-26 08:53:44 +00:00
|
|
|
.to raise_error(Thor::Error, 'No domain(s) given')
|
2023-12-04 09:44:54 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when blocks exist' do
|
|
|
|
let(:domain) { 'host.example' }
|
2023-12-07 13:49:14 +00:00
|
|
|
let(:arguments) { [domain] }
|
2023-12-04 09:44:54 +00:00
|
|
|
|
|
|
|
before { Fabricate(:email_domain_block, domain: domain) }
|
|
|
|
|
|
|
|
it 'removes the block' do
|
2023-12-07 13:49:14 +00:00
|
|
|
expect { subject }
|
|
|
|
.to output_results('Removed 1')
|
2023-12-04 09:44:54 +00:00
|
|
|
.and(change(EmailDomainBlock, :count).by(-1))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when no blocks exist' do
|
|
|
|
let(:domain) { 'host.example' }
|
2023-12-07 13:49:14 +00:00
|
|
|
let(:arguments) { [domain] }
|
2023-12-04 09:44:54 +00:00
|
|
|
|
|
|
|
it 'does not remove a block' do
|
2023-12-07 13:49:14 +00:00
|
|
|
expect { subject }
|
|
|
|
.to output_results('is not yet blocked')
|
2023-12-04 09:44:54 +00:00
|
|
|
.and(not_change(EmailDomainBlock, :count))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2023-05-24 09:55:40 +00:00
|
|
|
end
|