input_fields_operator_renaming_spec.rb 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe InputFieldsOperatorRenaming, type: :db_migration do
  4. context 'when postmaster filters needs to be updated' do
  5. let!(:filter) do
  6. stub_const('PostmasterFilter::VALID_OPERATORS', [
  7. 'contains',
  8. 'contains not',
  9. 'is any of',
  10. 'is none of',
  11. 'starts with one of',
  12. 'ends with one of',
  13. 'is',
  14. 'is not',
  15. 'starts with',
  16. 'ends with',
  17. ])
  18. create(:postmaster_filter,
  19. match: {
  20. 'subject' => {
  21. 'operator' => 'is',
  22. 'value' => 'dummy',
  23. },
  24. 'to' => {
  25. 'operator' => 'is not',
  26. 'value' => 'no-reply@zammad.org',
  27. },
  28. 'from' => {
  29. 'operator' => 'starts with',
  30. 'value' => 'a',
  31. },
  32. 'cc' => {
  33. 'operator' => 'ends with',
  34. 'value' => 'a',
  35. },
  36. 'body' => {
  37. 'operator' => 'contains',
  38. 'value' => 'Zammad',
  39. },
  40. })
  41. end
  42. it 'does migrate the postmaster filters' do
  43. migrate
  44. expect(filter.reload.match).to eq({
  45. 'subject' => {
  46. 'operator' => 'is any of',
  47. 'value' => 'dummy',
  48. },
  49. 'to' => {
  50. 'operator' => 'is none of',
  51. 'value' => 'no-reply@zammad.org',
  52. },
  53. 'from' => {
  54. 'operator' => 'starts with one of',
  55. 'value' => 'a',
  56. },
  57. 'cc' => {
  58. 'operator' => 'ends with one of',
  59. 'value' => 'a',
  60. },
  61. 'body' => {
  62. 'operator' => 'contains',
  63. 'value' => 'Zammad',
  64. },
  65. })
  66. end
  67. end
  68. context 'when core workflows needs to be updated' do
  69. let!(:workflow) do
  70. create(:core_workflow,
  71. object: 'Ticket',
  72. condition_selected: {
  73. 'ticket.title': {
  74. operator: 'is',
  75. value: 'dummy',
  76. },
  77. 'ticket.dummy': {
  78. operator: 'contains',
  79. value: %w[v1 v2],
  80. },
  81. },
  82. condition_saved: {
  83. 'ticket.title': {
  84. operator: 'is not',
  85. value: 'dummy',
  86. },
  87. 'ticket.dummy2': {
  88. operator: 'contains',
  89. value: %w[v3 v4],
  90. },
  91. 'ticket.treeselect': {
  92. operator: 'is',
  93. value: 'dummy',
  94. },
  95. })
  96. end
  97. let!(:workflow_unchanged) do
  98. create(:core_workflow,
  99. object: 'Ticket',
  100. condition_saved: {
  101. 'custom.module': {
  102. operator: 'match all modules',
  103. value: [ 'CoreWorkflow::Custom::TicketTimeAccountingCheck' ],
  104. }
  105. })
  106. end
  107. it 'does not migrate the workflows that do not use new input operators' do
  108. expect { migrate }.to not_change(workflow_unchanged, :reload)
  109. end
  110. it 'does migrate the workflows', :aggregate_failures do
  111. migrate
  112. expect(workflow.reload.condition_selected).to eq({
  113. 'ticket.title' => { 'operator' => 'is any of', 'value' => 'dummy' },
  114. 'ticket.dummy' => { 'operator' => 'contains', 'value' => %w[v1 v2], },
  115. })
  116. expect(workflow.reload.condition_saved).to eq({
  117. 'ticket.title' => { 'operator' => 'is none of', 'value' => 'dummy' },
  118. 'ticket.dummy2' => { 'operator' => 'contains', 'value' => %w[v3 v4], },
  119. 'ticket.treeselect' => { 'operator' => 'is', 'value' => 'dummy' },
  120. })
  121. end
  122. end
  123. end