issue_2715_fix_broken_twitter_urls_job_spec.rb 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. require_dependency 'issue_2715_fix_broken_twitter_urls_job' # Rails autoloading expects `issue2715_fix...`
  4. RSpec.describe Issue2715FixBrokenTwitterUrlsJob, type: :job do
  5. context 'with existing Twitter articles' do
  6. let!(:tweet) { create(:twitter_article, preferences: tweet_preferences) }
  7. let!(:dm) { create(:twitter_dm_article, preferences: dm_preferences) }
  8. let(:tweet_preferences) do
  9. # NOTE: Faker 2.0+ has deprecated the `#number(20)` syntax in favor of `#number(digits: 20)`.
  10. { links: [{ url: "https://twitter.com/statuses/#{Faker::Number.unique.number(digits: 20)}" }] }
  11. end
  12. let(:dm_preferences) do
  13. {
  14. # NOTE: Faker 2.0+ has deprecated the `#number(20)` syntax in favor of `#number(digits: 20)`.
  15. links: [{ url: "https://twitter.com/statuses/#{Faker::Number.unique.number(digits: 20)}" }],
  16. twitter: {
  17. recipient_id: recipient_id,
  18. sender_id: sender_id,
  19. },
  20. }
  21. end
  22. let(:recipient_id) { '1234567890' }
  23. let(:sender_id) { '0987654321' }
  24. it 'reformats all Twitter status URLs' do
  25. expect { described_class.perform_now }
  26. .to change { urls_of(tweet) }
  27. .to all(match(%r{^https://twitter.com/_/status/#{tweet.message_id}$}))
  28. end
  29. it 'reformats all Twitter DM URLs' do
  30. expect { described_class.perform_now }
  31. .to change { urls_of(dm) }
  32. .to all(match(%r{^https://twitter.com/messages/#{recipient_id}-#{sender_id}$}))
  33. end
  34. def urls_of(article)
  35. article.reload.preferences[:links].pluck(:url)
  36. end
  37. end
  38. end