2023-02-22 00:55:31 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-13 11:04:23 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe AccountFilter do
|
|
|
|
describe 'with empty params' do
|
2021-12-05 20:48:39 +00:00
|
|
|
it 'excludes instance actor by default' do
|
2017-05-05 18:56:00 +00:00
|
|
|
filter = described_class.new({})
|
2017-04-13 11:04:23 +00:00
|
|
|
|
2021-12-05 20:48:39 +00:00
|
|
|
expect(filter.results).to eq Account.without_instance_actor
|
2017-04-13 11:04:23 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'with invalid params' do
|
|
|
|
it 'raises with key error' do
|
2017-05-05 18:56:00 +00:00
|
|
|
filter = described_class.new(wrong: true)
|
2017-04-13 11:04:23 +00:00
|
|
|
|
|
|
|
expect { filter.results }.to raise_error(/wrong/)
|
|
|
|
end
|
|
|
|
end
|
2023-03-02 15:21:04 +00:00
|
|
|
|
|
|
|
describe 'with origin and by_domain interacting' do
|
|
|
|
let!(:local_account) { Fabricate(:account, domain: nil) }
|
|
|
|
let!(:remote_account_one) { Fabricate(:account, domain: 'example.org') }
|
|
|
|
let(:remote_account_two) { Fabricate(:account, domain: 'other.domain') }
|
|
|
|
|
|
|
|
it 'works with domain first and origin remote' do
|
|
|
|
filter = described_class.new(by_domain: 'example.org', origin: 'remote')
|
2023-04-26 18:21:54 +00:00
|
|
|
expect(filter.results).to contain_exactly(remote_account_one)
|
2023-03-02 15:21:04 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'works with domain last and origin remote' do
|
|
|
|
filter = described_class.new(origin: 'remote', by_domain: 'example.org')
|
2023-04-26 18:21:54 +00:00
|
|
|
expect(filter.results).to contain_exactly(remote_account_one)
|
2023-03-02 15:21:04 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'works with domain first and origin local' do
|
|
|
|
filter = described_class.new(by_domain: 'example.org', origin: 'local')
|
2023-04-26 18:21:54 +00:00
|
|
|
expect(filter.results).to contain_exactly(local_account)
|
2023-03-02 15:21:04 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'works with domain last and origin local' do
|
|
|
|
filter = described_class.new(origin: 'local', by_domain: 'example.org')
|
2023-04-26 18:21:54 +00:00
|
|
|
expect(filter.results).to contain_exactly(remote_account_one)
|
2023-03-02 15:21:04 +00:00
|
|
|
end
|
|
|
|
end
|
2023-04-17 12:16:36 +00:00
|
|
|
|
|
|
|
describe 'with username' do
|
|
|
|
let!(:local_account) { Fabricate(:account, domain: nil, username: 'validUserName') }
|
|
|
|
|
|
|
|
it 'works with @ at the beginning of the username' do
|
|
|
|
filter = described_class.new(username: '@validUserName')
|
2023-04-26 19:29:36 +00:00
|
|
|
expect(filter.results).to contain_exactly(local_account)
|
2023-04-17 12:16:36 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not work with more than one @ at the beginning of the username' do
|
|
|
|
filter = described_class.new(username: '@@validUserName')
|
2023-04-26 19:29:36 +00:00
|
|
|
expect(filter.results).to_not contain_exactly(local_account)
|
2023-04-17 12:16:36 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not work with @ outside the beginning of the username' do
|
|
|
|
filter = described_class.new(username: 'validUserName@')
|
2023-04-26 19:29:36 +00:00
|
|
|
expect(filter.results).to_not contain_exactly(local_account)
|
2023-04-17 12:16:36 +00:00
|
|
|
end
|
|
|
|
end
|
2017-04-13 11:04:23 +00:00
|
|
|
end
|