out_of_office_spec.rb 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Service::User::OutOfOffice do
  4. let(:agent) { create(:agent) }
  5. let(:replacement) { create(:agent) }
  6. it 'sets and enables Out of Office' do
  7. described_class
  8. .new(agent,
  9. enabled: true,
  10. start_at: Date.parse('2011-02-03'),
  11. end_at: Date.parse('2011-03-03'),
  12. replacement: replacement,
  13. text: 'Out of office message')
  14. .execute
  15. expect(agent)
  16. .to have_attributes(
  17. out_of_office: true,
  18. out_of_office_start_at: Date.parse('2011-02-03'),
  19. out_of_office_end_at: Date.parse('2011-03-03'),
  20. out_of_office_replacement_id: replacement.id,
  21. preferences: include(out_of_office_text: 'Out of office message')
  22. )
  23. end
  24. it 'disables Out of Office' do
  25. described_class
  26. .new(agent, enabled: false)
  27. .execute
  28. expect(agent)
  29. .to have_attributes(out_of_office: false)
  30. end
  31. it 'raises an error if given data is invalid' do
  32. service = described_class
  33. .new(agent,
  34. enabled: true,
  35. start_at: Date.parse('2011-02-03'),
  36. end_at: Date.parse('2011-03-03'))
  37. expect { service.execute }
  38. .to raise_error(ActiveRecord::RecordInvalid)
  39. end
  40. end