forked from glitch-soc/mastodon
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
the most basic test you could imagine
- Loading branch information
1 parent
efa50b8
commit eca0738
Showing
2 changed files
with
82 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
73 changes: 73 additions & 0 deletions
73
spec/services/activitypub/fetch_all_replies_service_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,73 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe ActivityPub::FetchAllRepliesService do | ||
subject { described_class.new } | ||
|
||
let(:actor) { Fabricate(:account, domain: 'example.com', uri: 'http://example.com/account') } | ||
let(:status) { Fabricate(:status, account: actor) } | ||
let(:collection_uri) { 'http://example.com/replies/1' } | ||
|
||
let(:items) do | ||
[ | ||
'http://example.com/self-reply-1', | ||
'http://example.com/self-reply-2', | ||
'http://example.com/self-reply-3', | ||
'http://other.com/other-reply-1', | ||
'http://other.com/other-reply-2', | ||
'http://other.com/other-reply-3', | ||
'http://example.com/self-reply-4', | ||
'http://example.com/self-reply-5', | ||
'http://example.com/self-reply-6', | ||
] | ||
end | ||
|
||
let(:payload) do | ||
{ | ||
'@context': 'https://www.w3.org/ns/activitystreams', | ||
type: 'Collection', | ||
id: collection_uri, | ||
items: items, | ||
}.with_indifferent_access | ||
end | ||
|
||
describe '#call' do | ||
it 'fetches more than the default maximum and from multiple domains' do | ||
allow(FetchReplyWorker).to receive(:push_bulk) | ||
|
||
subject.call(payload) | ||
|
||
expect(FetchReplyWorker).to have_received(:push_bulk).with(%w(http://example.com/self-reply-1 http://example.com/self-reply-2 http://example.com/self-reply-3 http://other.com/other-reply-1 http://other.com/other-reply-2 http://other.com/other-reply-3 http://example.com/self-reply-4 | ||
http://example.com/self-reply-5 http://example.com/self-reply-6)) | ||
end | ||
|
||
context 'with a recent status' do | ||
before do | ||
Fabricate(:status, uri: 'http://example.com/self-reply-2', fetched_replies_at: 1.second.ago, local: false) | ||
end | ||
|
||
it 'skips statuses that have been updated recently' do | ||
allow(FetchReplyWorker).to receive(:push_bulk) | ||
|
||
subject.call(payload) | ||
|
||
expect(FetchReplyWorker).to have_received(:push_bulk).with(%w(http://example.com/self-reply-1 http://example.com/self-reply-3 http://other.com/other-reply-1 http://other.com/other-reply-2 http://other.com/other-reply-3 http://example.com/self-reply-4 http://example.com/self-reply-5 http://example.com/self-reply-6)) | ||
end | ||
end | ||
|
||
context 'with an old status' do | ||
before do | ||
Fabricate(:status, uri: 'http://other.com/other-reply-1', fetched_replies_at: 1.year.ago, created_at: 1.year.ago, account: actor) | ||
end | ||
|
||
it 'updates the time that fetched statuses were last fetched' do | ||
allow(FetchReplyWorker).to receive(:push_bulk) | ||
|
||
subject.call(payload) | ||
|
||
expect(Status.find_by(uri: 'http://other.com/other-reply-1').fetched_replies_at).to be >= 1.minute.ago | ||
end | ||
end | ||
end | ||
end |