mention_resolve_worker_spec.rb 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe MentionResolveWorker do
  4. let(:status_id) { -42 }
  5. let(:uri) { 'https://example.com/users/unknown' }
  6. describe '#perform' do
  7. subject { described_class.new.perform(status_id, uri, {}) }
  8. context 'with a non-existent status' do
  9. it 'returns nil' do
  10. expect(subject).to be_nil
  11. end
  12. end
  13. context 'with a valid user' do
  14. let(:status) { Fabricate(:status) }
  15. let(:status_id) { status.id }
  16. let(:service_double) { instance_double(ActivityPub::FetchRemoteAccountService) }
  17. before do
  18. allow(ActivityPub::FetchRemoteAccountService).to receive(:new).and_return(service_double)
  19. allow(service_double).to receive(:call).with(uri, anything) { Fabricate(:account, domain: 'example.com', uri: uri) }
  20. end
  21. it 'resolves the account and adds a new mention', :aggregate_failures do
  22. expect { subject }
  23. .to change { status.reload.mentions }.from([]).to(a_collection_including(having_attributes(account: having_attributes(uri: uri), silent: false)))
  24. expect(service_double).to have_received(:call).once
  25. end
  26. end
  27. end
  28. end