mention_init_spec.rb 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe MentionInit, type: :db_migration do
  4. let(:mocked_table_actions) do
  5. lambda { |migration|
  6. # mock DB connection with null object to "null" all connection actions
  7. allow(migration).to receive(:connection).and_return(double('ActiveRecord::ConnectionAdapters::*').as_null_object) # rubocop:disable RSpec/VerifiedDoubles
  8. }
  9. end
  10. context 'when agent is present' do
  11. subject(:user) do
  12. agent = create(:agent)
  13. agent.preferences['notification_config'] = notification_config
  14. agent.tap(&:save!)
  15. end
  16. context 'when matrix misses type key' do
  17. let(:notification_config) do
  18. {
  19. 'matrix' => {
  20. 'create' => {
  21. 'criteria' => {
  22. 'subscribed' => true
  23. }
  24. },
  25. 'update' => {
  26. # 'criteria' => {
  27. # 'subscribed' => true
  28. # }
  29. },
  30. 'reminder_reached' => {
  31. 'criteria' => {
  32. 'subscribed' => false
  33. }
  34. },
  35. 'escalation' => {
  36. 'criteria' => {
  37. 'subscribed' => false
  38. }
  39. },
  40. }
  41. }
  42. end
  43. it 'adds type' do
  44. expect do
  45. migrate(&mocked_table_actions)
  46. end
  47. .to change {
  48. user.reload.preferences['notification_config']['matrix']['update']
  49. }
  50. .from({})
  51. .to(
  52. {
  53. 'criteria' => {
  54. 'subscribed' => true
  55. }
  56. }
  57. )
  58. end
  59. end
  60. end
  61. end