Add spec activity/create

This commit is contained in:
noellabo 2024-12-05 03:00:48 +09:00
parent c1f8763e9b
commit 75707d05a9

View File

@ -26,6 +26,8 @@ RSpec.describe ActivityPub::Activity::Create do
before do
sender.update(uri: ActivityPub::TagManager.instance.uri_for(sender))
Setting.reject_pattern = 'spam'
stub_request(:get, 'http://example.com/attachment.png').to_return(request_fixture('avatar.txt'))
stub_request(:get, 'http://example.com/emoji.png').to_return(body: attachment_fixture('emojo.png'))
stub_request(:get, 'http://example.com/emojib.png').to_return(body: attachment_fixture('emojo.png'), headers: { 'Content-Type' => 'application/octet-stream' })
@ -95,6 +97,24 @@ RSpec.describe ActivityPub::Activity::Create do
}
end
let(:spam_object_json) do
{
id: [ActivityPub::TagManager.instance.uri_for(sender), 'post3'].join('/'),
type: 'Note',
to: [
'https://www.w3.org/ns/activitystreams#Public',
ActivityPub::TagManager.instance.uri_for(follower),
],
content: '@bob lorem ispam',
published: 1.hour.ago.utc.iso8601,
updated: 1.hour.ago.utc.iso8601,
tag: {
type: 'Mention',
href: ActivityPub::TagManager.instance.uri_for(follower),
},
}
end
def activity_for_object(json)
{
'@context': 'https://www.w3.org/ns/activitystreams',
@ -168,6 +188,17 @@ RSpec.describe ActivityPub::Activity::Create do
# It has queued a mention resolve job
expect(MentionResolveWorker).to have_enqueued_sidekiq_job(status.id, invalid_mention_json[:tag][:href], anything)
end
it 'do not process posts that contain reject patterns', :aggregate_failures do
stub_request(:get, spam_object_json[:id]).to_return(status: 500)
described_class.new(activity_for_object(spam_object_json), sender, delivery: true).perform
# …it creates a status
status = Status.find_by(uri: spam_object_json[:id])
# Check the process did crash
expect(status.nil?).to be true
end
end
describe '#perform' do