regex_operator_renaming_spec.rb 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe RegexOperatorRenaming, type: :db_migration do
  4. context 'when time_accounting_selector needs to be updated' do
  5. before do
  6. Setting.set('time_accounting_selector', {
  7. 'condition' => {
  8. 'ticket.number' => { 'operator' => 'regex match', 'value' => 'test' },
  9. 'ticket.title' => { 'operator' => 'regex mismatch', 'value' => 'test2' },
  10. }
  11. })
  12. migrate
  13. end
  14. it 'does migrate the selector' do
  15. expect(Setting.get('time_accounting_selector')).to eq({ 'condition' =>
  16. { 'ticket.number' => { 'operator' => 'matches regex', 'value' => 'test' },
  17. 'ticket.title' => { 'operator' => 'does not match regex', 'value' => 'test2' }, } })
  18. end
  19. end
  20. context 'when core workflows needs to be updated' do
  21. let!(:workflow) do
  22. create(:core_workflow,
  23. object: 'Ticket',
  24. condition_selected: {
  25. 'ticket.title': {
  26. operator: 'regex mismatch',
  27. value: [ '^dummy' ],
  28. },
  29. 'ticket.dummy': {
  30. operator: 'contains',
  31. value: %w[v1 v2],
  32. },
  33. },
  34. condition_saved: {
  35. 'ticket.title': {
  36. operator: 'regex match',
  37. value: [ '^dummy' ],
  38. },
  39. 'ticket.dummy2': {
  40. operator: 'contains',
  41. value: %w[v3 v4],
  42. },
  43. })
  44. end
  45. let!(:workflow_unchanged) do
  46. create(:core_workflow,
  47. object: 'Ticket',
  48. condition_saved: {
  49. 'custom.module': {
  50. operator: 'match all modules',
  51. value: [ 'CoreWorkflow::Custom::TicketTimeAccountingCheck' ],
  52. }
  53. })
  54. end
  55. it 'does not migrate the workflows that do not use regex operators' do
  56. expect { migrate }.to not_change(workflow_unchanged, :reload)
  57. end
  58. it 'does migrate the workflows', :aggregate_failures do
  59. migrate
  60. expect(workflow.reload.condition_selected).to eq({
  61. 'ticket.title' => { 'operator' => 'does not match regex', 'value' => ['^dummy'] },
  62. 'ticket.dummy' => { 'operator' => 'contains', 'value' => %w[v1 v2], },
  63. })
  64. expect(workflow.reload.condition_saved).to eq({
  65. 'ticket.title' => { 'operator' => 'matches regex', 'value' => ['^dummy'] },
  66. 'ticket.dummy2' => { 'operator' => 'contains', 'value' => %w[v3 v4], },
  67. })
  68. end
  69. end
  70. end