calendar.rb 3.1 KB

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