issue_3346_xoauth2_token_not_fetched_spec.rb 1.4 KB

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