auto_response_check_spec.rb 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Channel::Filter::AutoResponseCheck, type: :channel_filter do
  4. let(:mail) do
  5. {
  6. From: 'me@example.com'
  7. }
  8. end
  9. shared_examples 'check auto response header' do |send_auto_response_state, is_auto_response_state|
  10. let(:mail_auto_response) do
  11. {
  12. 'x-zammad-send-auto-response': send_auto_response_state,
  13. 'x-zammad-is-auto-response': is_auto_response_state,
  14. 'x-zammad-article-preferences': {
  15. 'send-auto-response' => send_auto_response_state,
  16. 'is-auto-response' => is_auto_response_state
  17. }
  18. }
  19. end
  20. it 'check filter result' do
  21. filter(mail)
  22. expect(mail).to include(mail_auto_response)
  23. end
  24. end
  25. context 'with no blocking response header' do
  26. include_examples 'check auto response header', true, false
  27. end
  28. context 'with no blocking response header and x-zammad-send-auto-response:false' do
  29. let(:mail) do
  30. {
  31. 'x-zammad-send-auto-response': 'false'
  32. }
  33. end
  34. include_examples 'check auto response header', false, false
  35. end
  36. context 'with blocking auto response header' do
  37. context 'with header precedence:list' do
  38. let(:mail) do
  39. {
  40. precedence: 'list'
  41. }
  42. end
  43. include_examples 'check auto response header', false, true
  44. end
  45. context 'with header precedence:list and x-zammad-send-auto-response:true' do
  46. let(:mail) do
  47. {
  48. precedence: 'list',
  49. 'x-zammad-send-auto-response': 'true'
  50. }
  51. end
  52. include_examples 'check auto response header', true, true
  53. end
  54. context 'with header precedence:list and x-zammad-send-auto-response:false' do
  55. let(:mail) do
  56. {
  57. precedence: 'list',
  58. 'x-zammad-send-auto-response': 'false'
  59. }
  60. end
  61. include_examples 'check auto response header', false, true
  62. end
  63. context 'with header precedence:list and x-zammad-is-auto-response:false' do
  64. let(:mail) do
  65. {
  66. precedence: 'list',
  67. 'x-zammad-is-auto-response': 'false'
  68. }
  69. end
  70. include_examples 'check auto response header', true, false
  71. end
  72. context 'with header precedence:list, x-zammad-is-auto-response:false and x-zammad-send-auto-response:false' do
  73. let(:mail) do
  74. {
  75. precedence: 'list',
  76. 'x-zammad-is-auto-response': 'false',
  77. 'x-zammad-send-auto-response': 'false'
  78. }
  79. end
  80. include_examples 'check auto response header', false, false
  81. end
  82. context 'with header precedence:list, x-zammad-is-auto-response:true and x-zammad-send-auto-response:true' do
  83. let(:mail) do
  84. {
  85. precedence: 'list',
  86. 'x-zammad-is-auto-response': 'true',
  87. 'x-zammad-send-auto-response': 'true'
  88. }
  89. end
  90. include_examples 'check auto response header', true, true
  91. end
  92. end
  93. end