You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
3.2 KiB

  1. require 'rails_helper'
  2. RSpec.describe UpdateRemoteProfileService, type: :service do
  3. let(:xml) { File.read(Rails.root.join('spec', 'fixtures', 'push', 'feed.atom')) }
  4. subject { UpdateRemoteProfileService.new }
  5. before do
  6. stub_request(:get, 'https://quitter.no/avatar/7477-300-20160211190340.png').to_return(request_fixture('avatar.txt'))
  7. end
  8. context 'with updated details' do
  9. let(:remote_account) { Fabricate(:account, username: 'bob', domain: 'example.com') }
  10. before do
  11. subject.call(xml, remote_account)
  12. end
  13. it 'downloads new avatar' do
  14. expect(a_request(:get, 'https://quitter.no/avatar/7477-300-20160211190340.png')).to have_been_made
  15. end
  16. it 'sets the avatar remote url' do
  17. expect(remote_account.reload.avatar_remote_url).to eq 'https://quitter.no/avatar/7477-300-20160211190340.png'
  18. end
  19. it 'sets display name' do
  20. expect(remote_account.reload.display_name).to eq 'DIGITAL CAT'
  21. end
  22. it 'sets note' do
  23. expect(remote_account.reload.note).to eq 'Software engineer, free time musician and DIGITAL SPORTS enthusiast. Likes cats. Warning: May contain memes'
  24. end
  25. end
  26. context 'with unchanged details' do
  27. let(:remote_account) { Fabricate(:account, username: 'bob', domain: 'example.com', display_name: 'DIGITAL CAT', note: 'Software engineer, free time musician and DIGITAL SPORTS enthusiast. Likes cats. Warning: May contain memes', avatar_remote_url: 'https://quitter.no/avatar/7477-300-20160211190340.png') }
  28. before do
  29. subject.call(xml, remote_account)
  30. end
  31. it 'does not re-download avatar' do
  32. expect(a_request(:get, 'https://quitter.no/avatar/7477-300-20160211190340.png')).to have_been_made.once
  33. end
  34. it 'sets the avatar remote url' do
  35. expect(remote_account.reload.avatar_remote_url).to eq 'https://quitter.no/avatar/7477-300-20160211190340.png'
  36. end
  37. it 'sets display name' do
  38. expect(remote_account.reload.display_name).to eq 'DIGITAL CAT'
  39. end
  40. it 'sets note' do
  41. expect(remote_account.reload.note).to eq 'Software engineer, free time musician and DIGITAL SPORTS enthusiast. Likes cats. Warning: May contain memes'
  42. end
  43. end
  44. context 'with updated details from a domain set to reject media' do
  45. let(:remote_account) { Fabricate(:account, username: 'bob', domain: 'example.com') }
  46. let!(:domain_block) { Fabricate(:domain_block, domain: 'example.com', reject_media: true) }
  47. before do
  48. subject.call(xml, remote_account)
  49. end
  50. it 'does not the avatar remote url' do
  51. expect(remote_account.reload.avatar_remote_url).to be_nil
  52. end
  53. it 'sets display name' do
  54. expect(remote_account.reload.display_name).to eq 'DIGITAL CAT'
  55. end
  56. it 'sets note' do
  57. expect(remote_account.reload.note).to eq 'Software engineer, free time musician and DIGITAL SPORTS enthusiast. Likes cats. Warning: May contain memes'
  58. end
  59. it 'does not set store the avatar' do
  60. expect(remote_account.reload.avatar_file_name).to be_nil
  61. end
  62. end
  63. end