issue_3346_xoauth2_token_not_fetched_spec.rb 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Issue3346Xoauth2TokenNotFetched, type: :db_migration do
  4. shared_examples 'XOAUTH2 channel migration' do |channel_type|
  5. context 'when valid Channel is present' do
  6. before do
  7. channel = create(channel_type)
  8. channel.options[:inbound][:options][:password] = 'some_password'
  9. channel.save!
  10. end
  11. it "doesn't refresh the token" do
  12. allow(ExternalCredential).to receive(:refresh_token)
  13. migrate
  14. expect(ExternalCredential).not_to have_received(:refresh_token)
  15. end
  16. end
  17. context 'when broken Channel is present' do
  18. before do
  19. channel = create(channel_type)
  20. channel.options[:inbound][:options].delete(:password)
  21. channel.save!
  22. end
  23. it 'refreshes the token' do
  24. allow(ExternalCredential).to receive(:refresh_token)
  25. migrate
  26. expect(ExternalCredential).to have_received(:refresh_token)
  27. end
  28. it "doesn't break if refresh fails" do
  29. allow(ExternalCredential).to receive(:refresh_token).and_raise(RuntimeError)
  30. expect { migrate }.not_to raise_error
  31. end
  32. end
  33. end
  34. context 'when Microsoft365 Channel is present' do
  35. it_behaves_like 'XOAUTH2 channel migration', :microsoft365_channel
  36. end
  37. context 'when Google Channel is present' do
  38. it_behaves_like 'XOAUTH2 channel migration', :google_channel
  39. end
  40. end