messaging_spec.rb 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe NotificationFactory::Messaging do
  4. describe '.template' do
  5. subject(:template) do
  6. described_class.template(
  7. template: action,
  8. locale: 'en-us',
  9. timezone: 'Europe/Berlin',
  10. objects: {
  11. ticket: ticket,
  12. article: article,
  13. recipient: agent,
  14. current_user: current_user,
  15. changes: changes,
  16. }
  17. )
  18. end
  19. let(:ticket) { article.ticket }
  20. let(:article) { create(:ticket_article) }
  21. let(:agent) { create(:agent) }
  22. let(:current_user) { create(:agent) }
  23. context 'with an empty "changes" hash for "ticket_create"' do
  24. let(:action) { 'ticket_create' }
  25. let(:changes) { {} }
  26. it 'returns a hash with subject: <ticket title> (as Markdown heading)' do
  27. expect(template).to include(subject: "# #{ticket.title}")
  28. end
  29. it 'returns a hash with body: <article author & body>' do
  30. expect(template[:body])
  31. .to match(%r{Created by #{current_user.fullname}})
  32. .and match(%r{#{article.body}\z})
  33. end
  34. end
  35. context 'with a populated "changes" hash for "ticket_update"' do
  36. let(:action) { 'ticket_update' }
  37. let(:changes) do
  38. {
  39. state: %w[aaa bbb],
  40. group: %w[xxx yyy],
  41. pending_time: [Time.zone.parse('2019-04-01T10:00:00Z0'), Time.zone.parse('2019-04-01T23:00:00Z0')],
  42. }
  43. end
  44. it 'returns a hash with subject: <ticket title> (as Markdown heading)' do
  45. expect(template).to include(subject: "# #{ticket.title}")
  46. end
  47. it 'returns a hash with body: <article editor, changes, & body>' do
  48. expect(template[:body])
  49. .to match(%r{Updated by #{current_user.fullname}})
  50. .and match(%r{state: aaa -> bbb})
  51. .and match(%r{group: xxx -> yyy})
  52. .and match(%r{pending_time: 04/01/2019 12:00 pm \(Europe/Berlin\) -> 04/02/2019 1:00 am \(Europe/Berlin\)})
  53. .and match(%r{#{article.body}\z})
  54. end
  55. end
  56. context 'when "ticket_escalate"' do
  57. subject(:template) do
  58. described_class.template(
  59. template: 'ticket_escalation',
  60. locale: 'en-us',
  61. timezone: 'Europe/Berlin',
  62. objects: {
  63. ticket: ticket,
  64. article: article,
  65. recipient: agent,
  66. }
  67. )
  68. end
  69. before { ticket.escalation_at = escalation_time }
  70. let(:escalation_time) { Time.zone.parse('2019-04-01T10:00:00Z') }
  71. it 'returns a hash with subject: <ticket title> (as Markdown heading)' do
  72. expect(template).to include(subject: "# #{ticket.title}")
  73. end
  74. it 'returns a hash with body: <ticket customer, escalation time, & body>' do
  75. expect(template[:body])
  76. .to match(%r{The ticket \(#{ticket.title}\) from "#{ticket.customer.fullname}"})
  77. .and match(%r{escalated since "04/01/2019 12:00 pm \(Europe/Berlin\)"!})
  78. end
  79. end
  80. end
  81. end