calendar_public_holiday_cleanup_spec.rb 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe CalendarPublicHolidayCleanup, type: :db_migration do
  4. let(:ical_url) { Rails.root.join('test/data/calendar/calendar_duplicate_check.ics') }
  5. let(:calendar_with_public_holiday) { create(:calendar, ical_url: ical_url) }
  6. let(:calendar_without_public_holiday) { create(:calendar, ical_url: ical_url) }
  7. let(:calendar_without_ical_url) { create(:calendar) }
  8. let(:calendar_with_custom_public_holiday) { create(:calendar, ical_url: ical_url) }
  9. let(:feed) { Digest::MD5.hexdigest(ical_url.to_s) }
  10. let(:public_holidays) do
  11. {
  12. '2019-01-01' => { 'active' => true, 'feed' => feed, 'summary' => 'Neujahrstag' },
  13. '2019-01-02' => { 'active' => true, 'feed' => feed, 'summary' => 'Neujahrstag' },
  14. '2019-04-22' => { 'active' => true, 'feed' => feed, 'summary' => 'Ostermontag' },
  15. '2019-04-23' => { 'active' => true, 'feed' => feed, 'summary' => 'Ostermontag' },
  16. }
  17. end
  18. let(:public_holidays_uniq) do
  19. {
  20. '2019-01-01' => { 'active' => true, 'feed' => feed, 'summary' => 'Neujahrstag' },
  21. '2019-04-22' => { 'active' => true, 'feed' => feed, 'summary' => 'Ostermontag' },
  22. }
  23. end
  24. let(:public_holidays_custom) do
  25. {
  26. '2019-02-03' => { 'active' => true, 'summary' => 'Super Bowl LIII' },
  27. }
  28. end
  29. let(:public_holidays_uniq_custom) do
  30. public_holidays_custom.merge(public_holidays_uniq)
  31. end
  32. let(:public_holidays_non_uniq_custom) do
  33. public_holidays.merge(public_holidays_custom)
  34. end
  35. before do
  36. travel_to Time.zone.parse('2017-08-24T01:04:44Z0')
  37. calendar_with_public_holiday && calendar_without_public_holiday && calendar_without_ical_url && calendar_with_custom_public_holiday
  38. calendar_with_public_holiday.update!(public_holidays: public_holidays)
  39. calendar_without_ical_url.update!(public_holidays: public_holidays)
  40. calendar_with_custom_public_holiday.update!(public_holidays: public_holidays_non_uniq_custom)
  41. end
  42. it 'does not update calendars without public holidays/ical_urls' do
  43. expect { migrate }.to not_change { calendar_without_public_holiday }.and not_change { calendar_without_ical_url }
  44. end
  45. it 'does remove duplicates' do
  46. expect { migrate }.to change { calendar_with_public_holiday.reload.public_holidays }.from(public_holidays).to(public_holidays_uniq)
  47. end
  48. it 'does remove duplicates but keeps custom entries' do
  49. expect { migrate }.to change { calendar_with_custom_public_holiday.reload.public_holidays }.from(public_holidays_non_uniq_custom).to(public_holidays_uniq_custom)
  50. end
  51. end