forked from mastodon/mastodon
-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
151 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
Fabricator(:pending_status) do | ||
account { Fabricate.build(:account) } | ||
fetch_account { Fabricate.build(:account) } | ||
uri { "https://example.com/#{Time.now.utc.nsec}" } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe ActivateRemoteStatusesService, type: :service do | ||
subject { described_class.new.call(sender) } | ||
|
||
let(:sender) { Fabricate(:account, domain: 'example.com', uri: 'https://example.com/actor') } | ||
let(:alice) { Fabricate(:account) } | ||
let!(:pending_status) { Fabricate(:pending_status, account: sender, fetch_account: alice, uri: 'https://example.com/note') } | ||
|
||
let(:payload) do | ||
{ | ||
'@context': 'https://www.w3.org/ns/activitystreams', | ||
id: pending_status.uri, | ||
attributedTo: sender.uri, | ||
type: 'Note', | ||
content: 'Lorem ipsum', | ||
to: 'https://www.w3.org/ns/activitystreams#Public', | ||
tag: [ | ||
{ | ||
type: 'Mention', | ||
href: ActivityPub::TagManager.instance.uri_for(alice), | ||
}, | ||
], | ||
} | ||
end | ||
let(:json) { Oj.dump(payload) } | ||
|
||
before do | ||
stub_request(:get, 'https://example.com/note').to_return(status: 200, body: json, headers: { 'Content-Type': 'application/activity+json' }) | ||
end | ||
|
||
context 'when has a pending status' do | ||
before do | ||
subject | ||
end | ||
|
||
it 'original status is fetched', :sidekiq_inline do | ||
status = sender.statuses.first | ||
|
||
expect(status).to_not be_nil | ||
expect(status.text).to eq 'Lorem ipsum' | ||
end | ||
|
||
it 'pending request is removed' do | ||
expect { pending_status.reload }.to raise_error ActiveRecord::RecordNotFound | ||
end | ||
end | ||
|
||
context 'when target_account is suspended' do | ||
before do | ||
alice.suspend! | ||
subject | ||
end | ||
|
||
it 'original status is not fetched', :sidekiq_inline do | ||
status = sender.statuses.first | ||
|
||
expect(status).to be_nil | ||
end | ||
|
||
it 'pending request is removed' do | ||
expect { pending_status.reload }.to raise_error ActiveRecord::RecordNotFound | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
spec/workers/activitypub/fetch_remote_status_worker_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
describe ActivityPub::FetchRemoteStatusWorker do | ||
subject { described_class.new } | ||
|
||
let(:sender) { Fabricate(:account, domain: 'example.com', uri: 'https://example.com/actor') } | ||
let(:payload) do | ||
{ | ||
'@context': 'https://www.w3.org/ns/activitystreams', | ||
id: 'https://example.com/note', | ||
attributedTo: sender.uri, | ||
type: 'Note', | ||
content: 'Lorem ipsum', | ||
to: 'https://www.w3.org/ns/activitystreams#Public', | ||
tag: [ | ||
{ | ||
type: 'Mention', | ||
href: ActivityPub::TagManager.instance.uri_for(Fabricate(:account)), | ||
}, | ||
], | ||
} | ||
end | ||
let(:json) { Oj.dump(payload) } | ||
|
||
before do | ||
stub_request(:get, 'https://example.com/note').to_return(status: 200, body: json, headers: { 'Content-Type': 'application/activity+json' }) | ||
end | ||
|
||
describe '#perform' do | ||
it 'original status is fetched' do | ||
subject.perform('https://example.com/note', sender.id, Fabricate(:account).id) | ||
|
||
status = sender.statuses.first | ||
|
||
expect(status).to_not be_nil | ||
expect(status.text).to eq 'Lorem ipsum' | ||
end | ||
end | ||
end |