2023-05-24 18:55:40 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
require 'mastodon/cli/canonical_email_blocks'
|
|
|
|
|
2024-09-04 14:12:25 +09:00
|
|
|
RSpec.describe Mastodon::CLI::CanonicalEmailBlocks do
|
2023-12-07 22:49:14 +09:00
|
|
|
subject { cli.invoke(action, arguments, options) }
|
|
|
|
|
2023-06-05 15:20:18 +09:00
|
|
|
let(:cli) { described_class.new }
|
2023-12-07 22:49:14 +09:00
|
|
|
let(:arguments) { [] }
|
|
|
|
let(:options) { {} }
|
2023-06-05 15:20:18 +09:00
|
|
|
|
2023-12-01 21:00:34 +09:00
|
|
|
it_behaves_like 'CLI Command'
|
2023-06-05 15:20:18 +09:00
|
|
|
|
|
|
|
describe '#find' do
|
2023-12-07 22:49:14 +09:00
|
|
|
let(:action) { :find }
|
2023-06-05 15:20:18 +09:00
|
|
|
let(:arguments) { ['user@example.com'] }
|
|
|
|
|
|
|
|
context 'when a block is present' do
|
|
|
|
before { Fabricate(:canonical_email_block, email: 'user@example.com') }
|
|
|
|
|
|
|
|
it 'announces the presence of the block' do
|
2023-12-07 22:49:14 +09:00
|
|
|
expect { subject }
|
|
|
|
.to output_results('user@example.com is blocked')
|
2023-06-05 15:20:18 +09:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a block is not present' do
|
|
|
|
it 'announces the absence of the block' do
|
2023-12-07 22:49:14 +09:00
|
|
|
expect { subject }
|
|
|
|
.to output_results('user@example.com is not blocked')
|
2023-06-05 15:20:18 +09:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#remove' do
|
2023-12-07 22:49:14 +09:00
|
|
|
let(:action) { :remove }
|
2023-06-05 15:20:18 +09:00
|
|
|
let(:arguments) { ['user@example.com'] }
|
|
|
|
|
|
|
|
context 'when a block is present' do
|
|
|
|
before { Fabricate(:canonical_email_block, email: 'user@example.com') }
|
|
|
|
|
|
|
|
it 'removes the block' do
|
2023-12-07 22:49:14 +09:00
|
|
|
expect { subject }
|
|
|
|
.to output_results('Unblocked user@example.com')
|
2023-06-05 15:20:18 +09:00
|
|
|
|
|
|
|
expect(CanonicalEmailBlock.matching_email('user@example.com')).to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a block is not present' do
|
|
|
|
it 'announces the absence of the block' do
|
2023-12-07 22:49:14 +09:00
|
|
|
expect { subject }
|
|
|
|
.to output_results('user@example.com is not blocked')
|
2023-06-05 15:20:18 +09:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2023-05-24 18:55:40 +09:00
|
|
|
end
|