From 545ee0f7e026725ce20232796e7303de766887d8 Mon Sep 17 00:00:00 2001 From: Claire Date: Mon, 4 Nov 2024 17:25:15 +0100 Subject: [PATCH] Add test coverage to ActivityPub::TagManager --- spec/lib/activitypub/tag_manager_spec.rb | 41 +++++++++++++++++++++--- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/spec/lib/activitypub/tag_manager_spec.rb b/spec/lib/activitypub/tag_manager_spec.rb index 05d2609b0d..4dcfc69824 100644 --- a/spec/lib/activitypub/tag_manager_spec.rb +++ b/spec/lib/activitypub/tag_manager_spec.rb @@ -7,17 +7,50 @@ RSpec.describe ActivityPub::TagManager do subject { described_class.instance } + let(:domain) { "#{Rails.configuration.x.use_https ? 'https' : 'http'}://#{Rails.configuration.x.web_domain}" } + + describe '#public_collection?' do + it 'returns true for the special public collection and common shorthands' do + expect(subject.public_collection?('https://www.w3.org/ns/activitystreams#Public')).to be true + expect(subject.public_collection?('as:Public')).to be true + expect(subject.public_collection?('Public')).to be true + end + + it 'returns false for other URIs' do + expect(subject.public_collection?('https://example.com/foo/bar')).to be false + end + end + describe '#url_for' do - it 'returns a string' do + it 'returns a string starting with web domain' do account = Fabricate(:account) - expect(subject.url_for(account)).to be_a String + expect(subject.url_for(account)).to be_a(String) + .and start_with(domain) end end describe '#uri_for' do - it 'returns a string' do + it 'returns a string starting with web domain' do account = Fabricate(:account) - expect(subject.uri_for(account)).to be_a String + expect(subject.uri_for(account)).to be_a(String) + .and start_with(domain) + end + end + + describe '#activity_uri_for' do + context 'when given an account' do + it 'raises an exception' do + account = Fabricate(:account) + expect { subject.activity_uri_for(account) }.to raise_error(ArgumentError) + end + end + + context 'when given a local activity' do + it 'returns a string starting with web domain' do + status = Fabricate(:status) + expect(subject.uri_for(status)).to be_a(String) + .and start_with(domain) + end end end