account_filter_spec.rb 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe AccountFilter do
  4. describe 'with empty params' do
  5. it 'excludes instance actor by default' do
  6. filter = described_class.new({})
  7. expect(filter.results).to eq Account.without_instance_actor
  8. end
  9. end
  10. describe 'with invalid params' do
  11. it 'raises with key error' do
  12. filter = described_class.new(wrong: true)
  13. expect { filter.results }.to raise_error(/wrong/)
  14. end
  15. end
  16. describe 'with origin and by_domain interacting' do
  17. let!(:local_account) { Fabricate(:account, domain: nil) }
  18. let!(:remote_account_one) { Fabricate(:account, domain: 'example.org') }
  19. let(:remote_account_two) { Fabricate(:account, domain: 'other.domain') }
  20. it 'works with domain first and origin remote' do
  21. filter = described_class.new(by_domain: 'example.org', origin: 'remote')
  22. expect(filter.results).to contain_exactly(remote_account_one)
  23. end
  24. it 'works with domain last and origin remote' do
  25. filter = described_class.new(origin: 'remote', by_domain: 'example.org')
  26. expect(filter.results).to contain_exactly(remote_account_one)
  27. end
  28. it 'works with domain first and origin local' do
  29. filter = described_class.new(by_domain: 'example.org', origin: 'local')
  30. expect(filter.results).to contain_exactly(local_account)
  31. end
  32. it 'works with domain last and origin local' do
  33. filter = described_class.new(origin: 'local', by_domain: 'example.org')
  34. expect(filter.results).to contain_exactly(remote_account_one)
  35. end
  36. end
  37. describe 'with username' do
  38. let!(:local_account) { Fabricate(:account, domain: nil, username: 'validUserName') }
  39. it 'works with @ at the beginning of the username' do
  40. filter = described_class.new(username: '@validUserName')
  41. expect(filter.results).to contain_exactly(local_account)
  42. end
  43. it 'does not work with more than one @ at the beginning of the username' do
  44. filter = described_class.new(username: '@@validUserName')
  45. expect(filter.results).to_not contain_exactly(local_account)
  46. end
  47. it 'does not work with @ outside the beginning of the username' do
  48. filter = described_class.new(username: 'validUserName@')
  49. expect(filter.results).to_not contain_exactly(local_account)
  50. end
  51. end
  52. end