2023-06-01 17:37:38 +10:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe 'blocking domains through the moderation interface' do
|
|
|
|
before do
|
2023-10-31 20:40:30 +11:00
|
|
|
allow(DomainBlockWorker).to receive(:perform_async).and_return(true)
|
2023-06-01 17:37:38 +10:00
|
|
|
sign_in Fabricate(:user, role: UserRole.find_by(name: 'Admin')), scope: :user
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when silencing a new domain' do
|
|
|
|
it 'adds a new domain block' do
|
|
|
|
visit new_admin_domain_block_path
|
|
|
|
|
|
|
|
fill_in 'domain_block_domain', with: 'example.com'
|
|
|
|
select I18n.t('admin.domain_blocks.new.severity.silence'), from: 'domain_block_severity'
|
2023-10-18 01:10:50 +11:00
|
|
|
click_button I18n.t('admin.domain_blocks.new.create')
|
2023-06-01 17:37:38 +10:00
|
|
|
|
|
|
|
expect(DomainBlock.exists?(domain: 'example.com', severity: 'silence')).to be true
|
2023-10-31 20:40:30 +11:00
|
|
|
expect(DomainBlockWorker).to have_received(:perform_async)
|
2023-06-01 17:37:38 +10:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when suspending a new domain' do
|
|
|
|
it 'presents a confirmation screen before suspending the domain' do
|
|
|
|
visit new_admin_domain_block_path
|
|
|
|
|
|
|
|
fill_in 'domain_block_domain', with: 'example.com'
|
|
|
|
select I18n.t('admin.domain_blocks.new.severity.suspend'), from: 'domain_block_severity'
|
2023-10-18 01:10:50 +11:00
|
|
|
click_button I18n.t('admin.domain_blocks.new.create')
|
2023-06-01 17:37:38 +10:00
|
|
|
|
2023-10-31 20:40:30 +11:00
|
|
|
# It doesn't immediately block but presents a confirmation screen
|
2023-06-01 17:37:38 +10:00
|
|
|
expect(page).to have_title(I18n.t('admin.domain_blocks.confirm_suspension.title', domain: 'example.com'))
|
2023-10-31 20:40:30 +11:00
|
|
|
expect(DomainBlockWorker).to_not have_received(:perform_async)
|
2023-06-01 17:37:38 +10:00
|
|
|
|
|
|
|
# Confirming creates a block
|
2023-10-18 01:10:50 +11:00
|
|
|
click_button I18n.t('admin.domain_blocks.confirm_suspension.confirm')
|
2023-06-01 17:37:38 +10:00
|
|
|
|
|
|
|
expect(DomainBlock.exists?(domain: 'example.com', severity: 'suspend')).to be true
|
2023-10-31 20:40:30 +11:00
|
|
|
expect(DomainBlockWorker).to have_received(:perform_async)
|
2023-06-01 17:37:38 +10:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when suspending a domain that is already silenced' do
|
|
|
|
it 'presents a confirmation screen before suspending the domain' do
|
|
|
|
domain_block = Fabricate(:domain_block, domain: 'example.com', severity: 'silence')
|
|
|
|
|
|
|
|
visit new_admin_domain_block_path
|
|
|
|
|
|
|
|
fill_in 'domain_block_domain', with: 'example.com'
|
|
|
|
select I18n.t('admin.domain_blocks.new.severity.suspend'), from: 'domain_block_severity'
|
2023-10-18 01:10:50 +11:00
|
|
|
click_button I18n.t('admin.domain_blocks.new.create')
|
2023-06-01 17:37:38 +10:00
|
|
|
|
2023-10-31 20:40:30 +11:00
|
|
|
# It doesn't immediately block but presents a confirmation screen
|
2023-06-01 17:37:38 +10:00
|
|
|
expect(page).to have_title(I18n.t('admin.domain_blocks.confirm_suspension.title', domain: 'example.com'))
|
2023-10-31 20:40:30 +11:00
|
|
|
expect(DomainBlockWorker).to_not have_received(:perform_async)
|
2023-06-01 17:37:38 +10:00
|
|
|
|
|
|
|
# Confirming updates the block
|
2023-10-18 01:10:50 +11:00
|
|
|
click_button I18n.t('admin.domain_blocks.confirm_suspension.confirm')
|
2023-06-01 17:37:38 +10:00
|
|
|
|
2023-06-27 20:32:51 +10:00
|
|
|
expect(domain_block.reload.severity).to eq 'suspend'
|
2023-10-31 20:40:30 +11:00
|
|
|
expect(DomainBlockWorker).to have_received(:perform_async)
|
2023-06-01 17:37:38 +10:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-08-09 17:39:36 +10:00
|
|
|
context 'when suspending a subdomain of an already-silenced domain' do
|
|
|
|
it 'presents a confirmation screen before suspending the domain' do
|
|
|
|
domain_block = Fabricate(:domain_block, domain: 'example.com', severity: 'silence')
|
|
|
|
|
|
|
|
visit new_admin_domain_block_path
|
|
|
|
|
|
|
|
fill_in 'domain_block_domain', with: 'subdomain.example.com'
|
|
|
|
select I18n.t('admin.domain_blocks.new.severity.suspend'), from: 'domain_block_severity'
|
2023-10-18 01:10:50 +11:00
|
|
|
click_button I18n.t('admin.domain_blocks.new.create')
|
2023-08-09 17:39:36 +10:00
|
|
|
|
2023-10-31 20:40:30 +11:00
|
|
|
# It doesn't immediately block but presents a confirmation screen
|
2023-08-09 17:39:36 +10:00
|
|
|
expect(page).to have_title(I18n.t('admin.domain_blocks.confirm_suspension.title', domain: 'subdomain.example.com'))
|
2023-10-31 20:40:30 +11:00
|
|
|
expect(DomainBlockWorker).to_not have_received(:perform_async)
|
2023-08-09 17:39:36 +10:00
|
|
|
|
|
|
|
# Confirming creates the block
|
2023-10-18 01:10:50 +11:00
|
|
|
click_button I18n.t('admin.domain_blocks.confirm_suspension.confirm')
|
2023-08-09 17:39:36 +10:00
|
|
|
|
|
|
|
expect(DomainBlock.where(domain: 'subdomain.example.com', severity: 'suspend')).to exist
|
2023-10-31 20:40:30 +11:00
|
|
|
expect(DomainBlockWorker).to have_received(:perform_async)
|
2023-08-09 17:39:36 +10:00
|
|
|
|
|
|
|
# And leaves the previous block alone
|
|
|
|
expect(domain_block.reload.severity).to eq 'silence'
|
|
|
|
expect(domain_block.reload.domain).to eq 'example.com'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-06-01 17:37:38 +10:00
|
|
|
context 'when editing a domain block' do
|
|
|
|
it 'presents a confirmation screen before suspending the domain' do
|
|
|
|
domain_block = Fabricate(:domain_block, domain: 'example.com', severity: 'silence')
|
|
|
|
|
|
|
|
visit edit_admin_domain_block_path(domain_block)
|
|
|
|
|
|
|
|
select I18n.t('admin.domain_blocks.new.severity.suspend'), from: 'domain_block_severity'
|
2023-10-18 01:10:50 +11:00
|
|
|
click_button I18n.t('generic.save_changes')
|
2023-06-01 17:37:38 +10:00
|
|
|
|
2023-10-31 20:40:30 +11:00
|
|
|
# It doesn't immediately block but presents a confirmation screen
|
2023-06-01 17:37:38 +10:00
|
|
|
expect(page).to have_title(I18n.t('admin.domain_blocks.confirm_suspension.title', domain: 'example.com'))
|
2023-10-31 20:40:30 +11:00
|
|
|
expect(DomainBlockWorker).to_not have_received(:perform_async)
|
2023-06-01 17:37:38 +10:00
|
|
|
|
|
|
|
# Confirming updates the block
|
2023-10-18 01:10:50 +11:00
|
|
|
click_button I18n.t('admin.domain_blocks.confirm_suspension.confirm')
|
2023-10-31 20:40:30 +11:00
|
|
|
expect(DomainBlockWorker).to have_received(:perform_async)
|
2023-06-01 17:37:38 +10:00
|
|
|
|
2023-06-27 20:32:51 +10:00
|
|
|
expect(domain_block.reload.severity).to eq 'suspend'
|
2023-06-01 17:37:38 +10:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|