app_maintenance_spec.rb 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Gql::Subscriptions::AppMaintenance, type: :graphql do
  4. let(:subscription) do
  5. <<~QUERY
  6. subscription appMaintenance {
  7. appMaintenance {
  8. type
  9. }
  10. }
  11. QUERY
  12. end
  13. let(:mock_channel) { build_mock_channel }
  14. let(:expected_type) { 'app_version' }
  15. let(:expected_msg) do
  16. {
  17. result: {
  18. 'data' => {
  19. 'appMaintenance' => {
  20. 'type' => expected_type
  21. }
  22. }
  23. },
  24. more: true,
  25. }
  26. end
  27. shared_examples 'app maintenance subscription' do
  28. it 'correct app maintenance update/change event' do
  29. expect(mock_channel.mock_broadcasted_messages).to eq([expected_msg])
  30. end
  31. end
  32. context 'when app maintenance update/change events (trigger actions in the frontend) are triggered' do
  33. context 'when browser reload is triggered' do
  34. before do
  35. gql.execute(subscription, context: { channel: mock_channel })
  36. AppVersion.trigger_browser_reload(app_version_set)
  37. end
  38. context 'when app version event is triggered' do
  39. let(:app_version_set) { AppVersion::MSG_APP_VERSION }
  40. include_examples 'app maintenance subscription'
  41. end
  42. context 'when restart auto event is triggered' do
  43. let(:app_version_set) { AppVersion::MSG_RESTART_AUTO }
  44. let(:expected_type) { 'restart_auto' }
  45. include_examples 'app maintenance subscription'
  46. end
  47. context 'when restart manual event is triggered' do
  48. let(:app_version_set) { AppVersion::MSG_RESTART_MANUAL }
  49. let(:expected_type) { 'restart_manual' }
  50. include_examples 'app maintenance subscription'
  51. end
  52. context 'when config change event is triggered' do
  53. let(:app_version_set) { AppVersion::MSG_CONFIG_CHANGED }
  54. let(:expected_type) { 'config_changed' }
  55. include_examples 'app maintenance subscription'
  56. end
  57. end
  58. context 'when system restart is triggered' do
  59. before do
  60. Setting.set('auto_shutdown', auto_shutdown_enabled)
  61. gql.execute(subscription, context: { channel: mock_channel })
  62. AppVersion.trigger_restart
  63. end
  64. context 'when auto restart is enabled' do
  65. let(:auto_shutdown_enabled) { true }
  66. let(:expected_type) { 'restart_auto' }
  67. include_examples 'app maintenance subscription'
  68. end
  69. context 'when auto restart is disabled' do
  70. let(:auto_shutdown_enabled) { false }
  71. let(:expected_type) { 'restart_manual' }
  72. include_examples 'app maintenance subscription'
  73. end
  74. end
  75. end
  76. end