issue_2460_fix_corrupted_twitter_ids_spec.rb 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Issue2460FixCorruptedTwitterIds, type: :db_migration do
  4. before { allow(Twitter::REST::Client).to receive(:new).and_return(client) }
  5. let(:client) { double('Twitter::REST::Client', user: twitter_api_user) }
  6. let(:twitter_api_user) { double('Twitter::User', id: twitter_api_user_id) }
  7. let(:twitter_api_user_id) { 1234567890 } # rubocop:disable Style/NumericLiterals
  8. context 'with existing, corrupted Twitter channel' do
  9. let!(:twitter_channel) { create(:twitter_channel) }
  10. it 'updates the channel’s stored user ID (as string)' do
  11. expect { migrate }
  12. .to change { twitter_channel.reload.options[:user][:id] }
  13. .to(twitter_api_user_id.to_s)
  14. end
  15. context 'with invalid credentials stored' do
  16. before { allow(Twitter::REST::Client).to receive(:new).and_raise(Twitter::Error::Unauthorized.new('Could not authenticate you.')) }
  17. it 'skips the Channel' do
  18. expect { migrate }
  19. .not_to change { twitter_channel.reload.options[:user][:id] }
  20. end
  21. end
  22. end
  23. end