calendar.rb 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. FactoryBot.define do
  2. factory :calendar do
  3. sequence(:name) { |n| "Escalation Test #{n}" }
  4. timezone { 'Europe/Berlin' }
  5. default { true }
  6. ical_url { nil }
  7. created_by_id { 1 }
  8. updated_by_id { 1 }
  9. transient do
  10. public_holiday_date { nil }
  11. end
  12. public_holidays do
  13. next if public_holiday_date.blank?
  14. Array(public_holiday_date).each_with_object({}) do |elem, memo|
  15. memo[elem.to_s] = { active: true, summary: 'public holiday trait' }
  16. end
  17. end
  18. business_hours_9_17
  19. trait :business_hours_9_17 do
  20. business_hours do
  21. {
  22. mon: {
  23. active: true,
  24. timeframes: [['09:00', '17:00']]
  25. },
  26. tue: {
  27. active: true,
  28. timeframes: [['09:00', '17:00']]
  29. },
  30. wed: {
  31. active: true,
  32. timeframes: [['09:00', '17:00']]
  33. },
  34. thu: {
  35. active: true,
  36. timeframes: [['09:00', '17:00']]
  37. },
  38. fri: {
  39. active: true,
  40. timeframes: [['09:00', '17:00']]
  41. },
  42. sat: {
  43. active: false,
  44. timeframes: [['09:00', '17:00']]
  45. },
  46. sun: {
  47. active: false,
  48. timeframes: [['09:00', '17:00']]
  49. }
  50. }
  51. end
  52. end
  53. trait :'24/7' do
  54. business_hours do
  55. {
  56. mon: {
  57. active: true,
  58. timeframes: [ ['00:00', '24:00'] ]
  59. },
  60. tue: {
  61. active: true,
  62. timeframes: [ ['00:00', '24:00'] ]
  63. },
  64. wed: {
  65. active: true,
  66. timeframes: [ ['00:00', '24:00'] ]
  67. },
  68. thu: {
  69. active: true,
  70. timeframes: [ ['00:00', '24:00'] ]
  71. },
  72. fri: {
  73. active: true,
  74. timeframes: [ ['00:00', '24:00'] ]
  75. },
  76. sat: {
  77. active: true,
  78. timeframes: [ ['00:00', '24:00'] ]
  79. },
  80. sun: {
  81. active: true,
  82. timeframes: [ ['00:00', '24:00'] ]
  83. },
  84. }
  85. end
  86. end
  87. trait '23:59/7' do
  88. business_hours_generated
  89. timeframe_alldays { ['00:00', '23:59'] }
  90. end
  91. trait :'9-18/7' do
  92. business_hours_generated
  93. timeframe_alldays { ['09:00', '18:00'] }
  94. end
  95. trait :business_hours_generated do
  96. transient do
  97. timeframe_alldays { nil }
  98. timeframe_workdays { timeframe_alldays }
  99. timeframe_weekends { timeframe_alldays }
  100. config_workdays { timeframe_workdays ? { active: true, timeframes: [timeframe_workdays] } : {} }
  101. config_weekends { timeframe_weekends ? { active: true, timeframes: [timeframe_weekends] } : {} }
  102. end
  103. business_hours do
  104. hash = {}
  105. %i[mon tue wed thu fri].each_with_object(hash) { |elem, memo| memo[elem] = config_workdays }
  106. %i[sat sun].each_with_object(hash) { |elem, memo| memo[elem] = config_weekends }
  107. hash
  108. end
  109. end
  110. end
  111. end