twitter_sync_spec.rb 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe TwitterSync do
  4. subject(:twitter_sync) { described_class.new(channel.options[:auth]) }
  5. let(:channel) { create(:twitter_channel) }
  6. describe '.preferences_cleanup' do
  7. shared_examples 'for normalizing input' do
  8. it 'is converted (from bare hash)' do
  9. expect(described_class.preferences_cleanup(raw_preferences)).to include(clean_preferences)
  10. end
  11. it 'is converted (from article.preferences hash)' do
  12. expect(described_class.preferences_cleanup(twitter: raw_preferences)).to match({ twitter: hash_including(clean_preferences) })
  13. end
  14. end
  15. describe ':geo key' do
  16. context 'when absent' do
  17. let(:raw_preferences) { {} }
  18. let(:clean_preferences) { { geo: {} } }
  19. include_examples 'for normalizing input'
  20. end
  21. context 'when instance_of(Twitter::NullOjbect)' do
  22. let(:raw_preferences) { { geo: Twitter::NullObject.new } }
  23. let(:clean_preferences) { { geo: {} } }
  24. include_examples 'for normalizing input'
  25. end
  26. context 'when instance_of(Twitter::Geo.new)' do
  27. let(:raw_preferences) { { geo: Twitter::Geo.new(coordinates: [1, 1]) } }
  28. let(:clean_preferences) { { geo: { coordinates: [1, 1] } } }
  29. include_examples 'for normalizing input'
  30. end
  31. end
  32. describe ':place key' do
  33. context 'when absent' do
  34. let(:raw_preferences) { {} }
  35. let(:clean_preferences) { { place: {} } }
  36. include_examples 'for normalizing input'
  37. end
  38. context 'when instance_of(Twitter::NullOjbect)' do
  39. let(:raw_preferences) { { place: Twitter::NullObject.new } }
  40. let(:clean_preferences) { { place: {} } }
  41. include_examples 'for normalizing input'
  42. end
  43. context 'when instance_of(Twitter::Place.new)' do
  44. let(:raw_preferences) { { place: Twitter::Place.new({ country: 'da', name: 'do', woeid: 1, id: 1 }) } }
  45. let(:clean_preferences) { { place: { country: 'da', name: 'do', woeid: 1, id: 1 } } }
  46. include_examples 'for normalizing input'
  47. end
  48. end
  49. describe ':mention_ids key' do
  50. let(:raw_preferences) { { mention_ids: [1_234_567_890] } }
  51. let(:clean_preferences) { { mention_ids: [1_234_567_890] } }
  52. include_examples 'for normalizing input'
  53. end
  54. end
  55. end