Merge branch 'kb_development' into kb_migration
This commit is contained in:
commit
c7fe057f92
40 changed files with 338 additions and 29 deletions
|
@ -290,6 +290,7 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
|
||||
expect(status).to_not be_nil
|
||||
expect(status.visibility).to eq 'limited'
|
||||
expect(status.limited_scope).to eq 'none'
|
||||
end
|
||||
|
||||
it 'creates silent mention' do
|
||||
|
@ -298,6 +299,50 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||
end
|
||||
end
|
||||
|
||||
context 'when limited_scope' do
|
||||
let(:recipient) { Fabricate(:account) }
|
||||
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
content: 'Lorem ipsum',
|
||||
to: ActivityPub::TagManager.instance.uri_for(recipient),
|
||||
limitedScope: 'Mutual',
|
||||
}
|
||||
end
|
||||
|
||||
it 'creates status' do
|
||||
status = sender.statuses.first
|
||||
|
||||
expect(status).to_not be_nil
|
||||
expect(status.visibility).to eq 'limited'
|
||||
expect(status.limited_scope).to eq 'mutual'
|
||||
end
|
||||
end
|
||||
|
||||
context 'when invalid limited_scope' do
|
||||
let(:recipient) { Fabricate(:account) }
|
||||
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
content: 'Lorem ipsum',
|
||||
to: ActivityPub::TagManager.instance.uri_for(recipient),
|
||||
limitedScope: 'IdosdsazsF',
|
||||
}
|
||||
end
|
||||
|
||||
it 'creates status' do
|
||||
status = sender.statuses.first
|
||||
|
||||
expect(status).to_not be_nil
|
||||
expect(status.visibility).to eq 'limited'
|
||||
expect(status.limited_scope).to eq 'none'
|
||||
end
|
||||
end
|
||||
|
||||
context 'when direct' do
|
||||
let(:recipient) { Fabricate(:account) }
|
||||
|
||||
|
|
|
@ -168,7 +168,17 @@ RSpec.describe PostStatusService, type: :service do
|
|||
status = subject.call(account, text: 'test status update')
|
||||
|
||||
expect(ProcessMentionsService).to have_received(:new)
|
||||
expect(mention_service).to have_received(:call).with(status, save_records: false)
|
||||
expect(mention_service).to have_received(:call).with(status, limited_type: '', save_records: false)
|
||||
end
|
||||
|
||||
it 'mutual visibility' do
|
||||
account = Fabricate(:account)
|
||||
text = 'This is an English text.'
|
||||
|
||||
status = subject.call(account, text: text, visibility: 'mutual')
|
||||
|
||||
expect(status.visibility).to eq 'limited'
|
||||
expect(status.limited_scope).to eq 'mutual'
|
||||
end
|
||||
|
||||
it 'safeguards mentions' do
|
||||
|
|
97
spec/workers/activitypub/fetch_instance_info_worker_spec.rb
Normal file
97
spec/workers/activitypub/fetch_instance_info_worker_spec.rb
Normal file
|
@ -0,0 +1,97 @@
|
|||
# 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 update' do
|
||||
let(:new_nodeinfo) do
|
||||
{
|
||||
version: '2.0',
|
||||
software: {
|
||||
name: 'mastodon',
|
||||
version: '4.2.0-beta3',
|
||||
},
|
||||
protocols: ['activitypub'],
|
||||
}
|
||||
end
|
||||
let(:new_nodeinfo_json) { Oj.dump(new_nodeinfo) }
|
||||
|
||||
before do
|
||||
stub_request(:get, 'https://example.com/.well-known/nodeinfo').to_return(status: 200, body: wellknown_nodeinfo_json)
|
||||
Fabricate(:account, domain: 'example.com')
|
||||
Instance.refresh
|
||||
end
|
||||
|
||||
it 'performs a mastodon instance' do
|
||||
stub_request(:get, 'https://example.com/nodeinfo/2.0').to_return(status: 200, body: nodeinfo_json)
|
||||
subject.perform('example.com')
|
||||
stub_request(:get, 'https://example.com/nodeinfo/2.0').to_return(status: 200, body: new_nodeinfo_json)
|
||||
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-beta3'
|
||||
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
|
|
@ -5,6 +5,12 @@ require 'rails_helper'
|
|||
describe Scheduler::UpdateInstanceInfoScheduler do
|
||||
let(:worker) { described_class.new }
|
||||
|
||||
before do
|
||||
stub_request(:get, 'https://example.com/.well-known/nodeinfo').to_return(status: 200, body: '{}')
|
||||
Fabricate(:account, domain: 'example.com')
|
||||
Instance.refresh
|
||||
end
|
||||
|
||||
describe 'perform' do
|
||||
it 'runs without error' do
|
||||
expect { worker.perform }.to_not raise_error
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue