Add initial support for ingesting and verifying remote quote posts (#34370)
This commit is contained in:
parent
a324edabdf
commit
df2611a10f
33 changed files with 1643 additions and 22 deletions
44
spec/workers/activitypub/quote_refresh_worker_spec.rb
Normal file
44
spec/workers/activitypub/quote_refresh_worker_spec.rb
Normal file
|
@ -0,0 +1,44 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe ActivityPub::QuoteRefreshWorker do
|
||||
let(:worker) { described_class.new }
|
||||
let(:service) { instance_double(ActivityPub::VerifyQuoteService, call: true) }
|
||||
|
||||
describe '#perform' do
|
||||
before { stub_service }
|
||||
|
||||
let(:account) { Fabricate(:account, domain: 'example.com') }
|
||||
let(:status) { Fabricate(:status, account: account) }
|
||||
let(:quote) { Fabricate(:quote, status: status, quoted_status: nil, updated_at: updated_at) }
|
||||
|
||||
context 'when dealing with an old quote' do
|
||||
let(:updated_at) { (Quote::BACKGROUND_REFRESH_INTERVAL * 2).ago }
|
||||
|
||||
it 'sends the status to the service and bumps the updated date' do
|
||||
expect { worker.perform(quote.id) }
|
||||
.to(change { quote.reload.updated_at })
|
||||
|
||||
expect(service).to have_received(:call).with(quote)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when dealing with a recent quote' do
|
||||
let(:updated_at) { Time.now.utc }
|
||||
|
||||
it 'does not call the service and does not touch the quote' do
|
||||
expect { worker.perform(quote.id) }
|
||||
.to_not(change { quote.reload.updated_at })
|
||||
|
||||
expect(service).to_not have_received(:call).with(quote)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def stub_service
|
||||
allow(ActivityPub::VerifyQuoteService)
|
||||
.to receive(:new)
|
||||
.and_return(service)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,35 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe ActivityPub::RefetchAndVerifyQuoteWorker do
|
||||
let(:worker) { described_class.new }
|
||||
let(:service) { instance_double(ActivityPub::VerifyQuoteService, call: true) }
|
||||
|
||||
describe '#perform' do
|
||||
before { stub_service }
|
||||
|
||||
let(:account) { Fabricate(:account, domain: 'example.com') }
|
||||
let(:status) { Fabricate(:status, account: account) }
|
||||
let(:quote) { Fabricate(:quote, status: status, quoted_status: nil) }
|
||||
let(:url) { 'https://example.com/quoted-status' }
|
||||
|
||||
it 'sends the status to the service' do
|
||||
worker.perform(quote.id, url)
|
||||
|
||||
expect(service).to have_received(:call).with(quote, fetchable_quoted_uri: url, request_id: anything)
|
||||
end
|
||||
|
||||
it 'returns nil for non-existent record' do
|
||||
result = worker.perform(123_123_123, url)
|
||||
|
||||
expect(result).to be(true)
|
||||
end
|
||||
end
|
||||
|
||||
def stub_service
|
||||
allow(ActivityPub::VerifyQuoteService)
|
||||
.to receive(:new)
|
||||
.and_return(service)
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue