Add fetch_instance_info_worker_spec
This commit is contained in:
parent
18583e5275
commit
15d0117b3b
4 changed files with 70 additions and 5 deletions
|
@ -209,7 +209,7 @@ class ActivityPub::ProcessAccountService < BaseService
|
|||
end
|
||||
|
||||
def fetch_instance_info
|
||||
FetchInstanceInfoWorker.perform_async(@account.domain) unless InstanceInfo.exists?(domain: @account.domain)
|
||||
ActivityPub::FetchInstanceInfoWorker.perform_async(@account.domain) unless InstanceInfo.exists?(domain: @account.domain)
|
||||
end
|
||||
|
||||
def actor_type
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class FetchInstanceInfoWorker
|
||||
class ActivityPub::FetchInstanceInfoWorker
|
||||
include Sidekiq::Worker
|
||||
include JsonLdHelper
|
||||
include Redisable
|
||||
|
@ -64,9 +64,9 @@ class FetchInstanceInfoWorker
|
|||
|
||||
body_to_json(response.body_with_limit)
|
||||
elsif response.code == 410
|
||||
raise FetchInstanceInfoWorker::GoneError, "#{domain} is gone from the server"
|
||||
raise ActivityPub::FetchInstanceInfoWorker::GoneError, "#{@instance.domain} is gone from the server"
|
||||
else
|
||||
raise FetchInstanceInfoWorker::RequestError, "Request for #{domain} returned HTTP #{response.code}"
|
||||
raise ActivityPub::FetchInstanceInfoWorker::RequestError, "Request for #{@instance.domain} returned HTTP #{response.code}"
|
||||
end
|
||||
end
|
||||
end
|
|
@ -7,7 +7,7 @@ class Scheduler::UpdateInstanceInfoScheduler
|
|||
|
||||
def perform
|
||||
Instance.select(:domain).reorder(nil).find_in_batches do |instances|
|
||||
FetchInstanceInfoWorker.push_bulk(instances) do |instance|
|
||||
ActivityPub::FetchInstanceInfoWorker.push_bulk(instances) do |instance|
|
||||
[instance.domain]
|
||||
end
|
||||
end
|
||||
|
|
65
spec/workers/activitypub/fetch_instance_info_worker_spec.rb
Normal file
65
spec/workers/activitypub/fetch_instance_info_worker_spec.rb
Normal file
|
@ -0,0 +1,65 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe ActivityPub::FetchInstanceInfoWorker do
|
||||
subject { described_class.new }
|
||||
|
||||
let(:wellknown_nodeinfo) do
|
||||
{
|
||||
links: [
|
||||
{
|
||||
rel: 'http://nodeinfo.diaspora.software/ns/schema/2.0',
|
||||
href: 'https://example.com/nodeinfo/2.0',
|
||||
},
|
||||
],
|
||||
}
|
||||
end
|
||||
|
||||
let(:nodeinfo) do
|
||||
{
|
||||
version: '2.0',
|
||||
software: {
|
||||
name: 'mastodon',
|
||||
version: '4.2.0-beta1',
|
||||
},
|
||||
protocols: ['activitypub'],
|
||||
}
|
||||
end
|
||||
|
||||
let(:wellknown_nodeinfo_json) { Oj.dump(wellknown_nodeinfo) }
|
||||
let(:nodeinfo_json) { Oj.dump(nodeinfo) }
|
||||
|
||||
context 'when success' do
|
||||
before do
|
||||
stub_request(:get, 'https://example.com/.well-known/nodeinfo').to_return(status: 200, body: wellknown_nodeinfo_json)
|
||||
stub_request(:get, 'https://example.com/nodeinfo/2.0').to_return(status: 200, body: nodeinfo_json)
|
||||
Fabricate(:account, domain: 'example.com')
|
||||
Instance.refresh
|
||||
end
|
||||
|
||||
it 'performs a mastodon instance' do
|
||||
subject.perform('example.com')
|
||||
|
||||
info = InstanceInfo.find_by(domain: 'example.com')
|
||||
expect(info).to_not be_nil
|
||||
expect(info.software).to eq 'mastodon'
|
||||
expect(info.version).to eq '4.2.0-beta1'
|
||||
end
|
||||
end
|
||||
|
||||
context 'when failed' do
|
||||
before do
|
||||
stub_request(:get, 'https://example.com/.well-known/nodeinfo').to_return(status: 404)
|
||||
Fabricate(:account, domain: 'example.com')
|
||||
Instance.refresh
|
||||
end
|
||||
|
||||
it 'performs a mastodon instance' do
|
||||
expect { subject.perform('example.com') }.to raise_error(ActivityPub::FetchInstanceInfoWorker::RequestError, 'Request for example.com returned HTTP 404')
|
||||
|
||||
info = InstanceInfo.find_by(domain: 'example.com')
|
||||
expect(info).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue