organization_domain_based_assignment_test.rb 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. require 'test_helper'
  2. class OrganizationDomainBasedAssignmentTest < ActiveSupport::TestCase
  3. test 'organization based assignment' do
  4. organization1 = Organization.create_if_not_exists(
  5. name: 'organization based assignment 1',
  6. domain: '@examPle1.com ',
  7. domain_assignment: true,
  8. updated_by_id: 1,
  9. created_by_id: 1,
  10. )
  11. organization2 = Organization.create_if_not_exists(
  12. name: 'organization based assignment 2',
  13. domain: 'example2.com',
  14. domain_assignment: false,
  15. updated_by_id: 1,
  16. created_by_id: 1,
  17. )
  18. roles = Role.where(name: 'Customer')
  19. customer1 = User.create_or_update(
  20. login: 'organization-based_assignment-customer1@example1.com',
  21. firstname: 'Domain',
  22. lastname: 'Agent1',
  23. email: 'organization-based_assignment-customer1@example1.com',
  24. password: 'customerpw',
  25. active: true,
  26. roles: roles,
  27. updated_by_id: 1,
  28. created_by_id: 1,
  29. )
  30. assert_equal(organization1.id, customer1.organization_id)
  31. customer2 = User.create_or_update(
  32. login: 'organization-based_assignment-customer2@example1.com',
  33. firstname: 'Domain',
  34. lastname: 'Agent2',
  35. email: 'organization-based_assignment-customer2@example1.com',
  36. password: 'customerpw',
  37. active: true,
  38. organization_id: organization2.id,
  39. roles: roles,
  40. updated_by_id: 1,
  41. created_by_id: 1,
  42. )
  43. assert_equal(organization2.id, customer2.organization_id)
  44. customer3 = User.create_or_update(
  45. login: 'organization-based_assignment-customer3@example2.com',
  46. firstname: 'Domain',
  47. lastname: 'Agent2',
  48. email: 'organization-based_assignment-customer3@example2.com',
  49. password: 'customerpw',
  50. active: true,
  51. roles: roles,
  52. updated_by_id: 1,
  53. created_by_id: 1,
  54. )
  55. assert_nil(customer3.organization_id)
  56. customer4 = User.create_or_update(
  57. login: 'organization-based_assignment-customer4',
  58. firstname: 'Domain',
  59. lastname: 'Agent2',
  60. email: '@',
  61. password: 'customerpw',
  62. active: true,
  63. roles: roles,
  64. updated_by_id: 1,
  65. created_by_id: 1,
  66. )
  67. assert_nil(customer4.organization_id)
  68. end
  69. end