organization_domain_based_assignment_test.rb 2.2 KB

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