logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

after_remote_follow_request_worker_spec.rb (2060B)


  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe AfterRemoteFollowRequestWorker do
  4. subject { described_class.new }
  5. let(:follow_request) { Fabricate(:follow_request) }
  6. describe 'perform' do
  7. context 'when the follow_request does not exist' do
  8. it 'catches a raise and returns true' do
  9. allow(FollowService).to receive(:new)
  10. result = subject.perform('aaa')
  11. expect(result).to eq(true)
  12. expect(FollowService).not_to have_received(:new)
  13. end
  14. end
  15. context 'when the account cannot be updated' do
  16. it 'returns nil and does not call service when account is nil' do
  17. allow(FollowService).to receive(:new)
  18. service = double(call: nil)
  19. allow(FetchRemoteAccountService).to receive(:new).and_return(service)
  20. result = subject.perform(follow_request.id)
  21. expect(result).to be_nil
  22. expect(FollowService).not_to have_received(:new)
  23. end
  24. it 'returns nil and does not call service when account is locked' do
  25. allow(FollowService).to receive(:new)
  26. service = double(call: double(locked?: true))
  27. allow(FetchRemoteAccountService).to receive(:new).and_return(service)
  28. result = subject.perform(follow_request.id)
  29. expect(result).to be_nil
  30. expect(FollowService).not_to have_received(:new)
  31. end
  32. end
  33. context 'when the account is updated' do
  34. it 'calls the follow service and destroys the follow' do
  35. follow_service = double(call: nil)
  36. allow(FollowService).to receive(:new).and_return(follow_service)
  37. account = Fabricate(:account, locked: false)
  38. service = double(call: account)
  39. allow(FetchRemoteAccountService).to receive(:new).and_return(service)
  40. result = subject.perform(follow_request.id)
  41. expect(result).to be_nil
  42. expect(follow_service).to have_received(:call).with(follow_request.account, account.acct)
  43. expect { follow_request.reload }.to raise_error(ActiveRecord::RecordNotFound)
  44. end
  45. end
  46. end
  47. end