channel_spec.rb 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. require 'rails_helper'
  2. RSpec.describe Channel, type: :model do
  3. context 'when authentication type is XOAUTH2' do
  4. shared_examples 'common XOAUTH2' do
  5. context 'when non-XOAUTH2 channels are present' do
  6. let!(:email_address) { create(:email_address, channel: create(:channel, area: 'Some::Other')) }
  7. before do
  8. # XOAUTH2 channels refresh their tokens on initialization
  9. allow(ExternalCredential).to receive(:refresh_token).and_return({
  10. access_token: 'S3CR3T'
  11. })
  12. channel
  13. end
  14. it "doesn't remove email address assignments" do
  15. expect { described_class.where(area: channel.area).find_each { nil } }.not_to change { email_address.reload.channel_id }
  16. end
  17. end
  18. end
  19. context 'when provider is Google' do
  20. it_behaves_like 'common XOAUTH2' do
  21. let(:channel) { create(:google_channel) }
  22. end
  23. end
  24. context 'when provider is Microsoft365' do
  25. it_behaves_like 'common XOAUTH2' do
  26. let(:channel) { create(:microsoft365_channel) }
  27. end
  28. end
  29. end
  30. end