ldap_spec.rb 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. require 'lib/import/import_job_backend_examples'
  4. RSpec.describe Import::Ldap, sequencer: :caller do
  5. it_behaves_like 'ImportJob backend'
  6. describe '.queueable?' do
  7. it 'is queueable if LDAP integration is activated and configured' do
  8. allow(Setting).to receive(:get).with('ldap_integration').and_return(true)
  9. allow(Setting).to receive(:get).with('ldap_config').and_return({ host: 'some' })
  10. expect(described_class.queueable?).to be true
  11. end
  12. it "isn't queueable if LDAP integration is deactivated" do
  13. allow(Setting).to receive(:get).with('ldap_integration').and_return(false)
  14. allow(Setting).to receive(:get).with('ldap_config').and_return({ host: 'some' })
  15. expect(described_class.queueable?).to be false
  16. end
  17. it "isn't queueable if LDAP configuration is missing" do
  18. allow(Setting).to receive(:get).with('ldap_integration').and_return(true)
  19. allow(Setting).to receive(:get).with('ldap_config').and_return({})
  20. expect(described_class.queueable?).to be false
  21. end
  22. end
  23. describe '#start' do
  24. it 'starts LDAP import resource factories' do
  25. import_job = create(:import_job)
  26. instance = described_class.new(import_job)
  27. allow(Setting).to receive(:get).with('ldap_integration').and_return(true)
  28. allow(Setting).to receive(:get).with('ldap_config').and_return(true)
  29. expect_sequence
  30. instance.start
  31. end
  32. context 'requirements' do
  33. it 'lets dry runs always start' do
  34. import_job = create(:import_job, dry_run: true)
  35. instance = described_class.new(import_job)
  36. expect_sequence
  37. instance.start
  38. end
  39. it 'informs about deactivated ldap_integration' do
  40. import_job = create(:import_job)
  41. instance = described_class.new(import_job)
  42. allow(Setting).to receive(:get).with('ldap_integration').and_return(false)
  43. expect_no_sequence
  44. expect do
  45. instance.start
  46. import_job.reload
  47. end.to change {
  48. import_job.result
  49. }
  50. expect(import_job.result.key?(:info)).to be true
  51. end
  52. it 'informs about blank ldap_config' do
  53. import_job = create(:import_job)
  54. instance = described_class.new(import_job)
  55. allow(Setting).to receive(:get).with('ldap_integration').and_return(true)
  56. allow(Setting).to receive(:get).with('ldap_config').and_return({})
  57. expect_no_sequence
  58. expect do
  59. instance.start
  60. import_job.reload
  61. end.to change {
  62. import_job.result
  63. }
  64. expect(import_job.result.key?(:info)).to be true
  65. end
  66. end
  67. end
  68. describe '#reschedule?' do
  69. it 'initiates always a rescheduling' do
  70. import_job = create(:import_job)
  71. instance = described_class.new(import_job)
  72. delayed_job = double
  73. expect(instance.reschedule?(delayed_job)).to be true
  74. end
  75. it 'updates the result with an info text' do
  76. import_job = create(:import_job)
  77. instance = described_class.new(import_job)
  78. delayed_job = double
  79. expect do
  80. instance.reschedule?(delayed_job)
  81. end.to change {
  82. import_job.result
  83. }
  84. expect(import_job.result.key?(:info)).to be true
  85. end
  86. end
  87. end