issue_1905_exchange_login_from_remote_id_spec.rb 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Issue1905ExchangeLoginFromRemoteId, type: :db_migration do
  4. let(:backend) { Import::Exchange }
  5. it 'removes :item_id from attributes' do
  6. invalid_config = {
  7. attributes: {
  8. item_id: 'login',
  9. some: 'other',
  10. }
  11. }
  12. valid_config = ActiveSupport::HashWithIndifferentAccess.new(
  13. attributes: {
  14. some: 'other',
  15. }
  16. )
  17. expect(backend).to receive(:config).and_return(invalid_config) # rubocop:disable RSpec/StubbedMock
  18. allow(backend).to receive(:config).and_call_original
  19. migrate
  20. expect(backend.config).to eq(valid_config)
  21. end
  22. context 'no changes' do
  23. it 'performs no action for new systems', system_init_done: false do
  24. expect(backend).not_to receive(:config)
  25. migrate
  26. end
  27. shared_examples 'irrelevant config' do
  28. it 'does not change the config' do
  29. allow(backend).to receive(:config).and_return(config)
  30. expect(backend).not_to receive(:config=)
  31. migrate
  32. end
  33. end
  34. context 'blank config' do
  35. let(:config) { nil }
  36. it_behaves_like 'irrelevant config'
  37. end
  38. context 'blank attributes' do
  39. let(:config) do
  40. {
  41. some: 'config'
  42. }
  43. end
  44. it_behaves_like 'irrelevant config'
  45. end
  46. context 'blank attribute :item_id' do
  47. let(:config) do
  48. {
  49. attributes: {
  50. some: 'mapping'
  51. }
  52. }
  53. end
  54. it_behaves_like 'irrelevant config'
  55. end
  56. context 'attribute :item_id not mapping to login' do
  57. let(:config) do
  58. {
  59. attributes: {
  60. item_id: 'other_local_attribute'
  61. }
  62. }
  63. end
  64. it_behaves_like 'irrelevant config'
  65. end
  66. end
  67. end