organization_spec.rb 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Selector::Sql, 'organization' do
  4. describe 'organization.members_existing' do
  5. let(:user_1) { create(:agent, organization: Organization.first) }
  6. let(:organization_unused_1) { create(:organization) }
  7. let(:organization_unused_2) { create(:organization) }
  8. let(:organization_unused_3) { create(:organization) }
  9. before do
  10. user_1
  11. Organization.first.touch
  12. organization_unused_1
  13. organization_unused_2
  14. organization_unused_3
  15. end
  16. it 'does find the organizations with users', :aggregate_failures do
  17. condition = {
  18. operator: 'AND',
  19. conditions: [
  20. {
  21. name: 'organization.id',
  22. operator: 'is',
  23. value: [Organization.first.id.to_s, organization_unused_1.id.to_s, organization_unused_2.id.to_s, organization_unused_3.id.to_s],
  24. },
  25. {
  26. name: 'organization.members_existing',
  27. operator: 'is',
  28. value: 'true',
  29. },
  30. ]
  31. }
  32. count, = Organization.selectors(condition)
  33. expect(count).to eq(1)
  34. end
  35. it 'does find the organizations with no users', :aggregate_failures do
  36. condition = {
  37. operator: 'AND',
  38. conditions: [
  39. {
  40. name: 'organization.id',
  41. operator: 'is',
  42. value: [Organization.first.id.to_s, organization_unused_1.id.to_s, organization_unused_2.id.to_s, organization_unused_3.id.to_s],
  43. },
  44. {
  45. name: 'organization.members_existing',
  46. operator: 'is',
  47. value: 'false',
  48. },
  49. ]
  50. }
  51. count, = Organization.selectors(condition)
  52. expect(count).to eq(3)
  53. end
  54. end
  55. end