Remove page_json var from ap/replies spec (#32000)

This commit is contained in:
Matt Jankowski 2024-09-26 04:54:01 -04:00 committed by GitHub
parent 278a075b22
commit db57fe80c8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -66,7 +66,6 @@ RSpec.describe ActivityPub::RepliesController do
context 'when status is public' do context 'when status is public' do
let(:parent_visibility) { :public } let(:parent_visibility) { :public }
let(:page_json) { response.parsed_body[:first] }
it 'returns http success and correct media type' do it 'returns http success and correct media type' do
expect(response) expect(response)
@ -78,16 +77,28 @@ RSpec.describe ActivityPub::RepliesController do
context 'without only_other_accounts' do context 'without only_other_accounts' do
it "returns items with thread author's replies" do it "returns items with thread author's replies" do
expect(page_json).to be_a Hash expect(response.parsed_body)
expect(page_json[:items]).to be_an Array .to include(
expect(page_json[:items].size).to eq 1 first: be_a(Hash).and(
expect(page_json[:items].all? { |item| targets_public_collection?(item) }).to be true include(
items: be_an(Array)
.and(have_attributes(size: 1))
.and(all(satisfy { |item| targets_public_collection?(item) }))
)
)
)
end end
context 'when there are few self-replies' do context 'when there are few self-replies' do
it 'points next to replies from other people' do it 'points next to replies from other people' do
expect(page_json).to be_a Hash expect(response.parsed_body)
expect(parsed_uri_query_values(page_json[:next])).to include('only_other_accounts=true', 'page=true') .to include(
first: be_a(Hash).and(
include(
next: satisfy { |value| (parsed_uri_query_values(value) & %w(only_other_accounts=true page=true)).any? }
)
)
)
end end
end end
@ -97,8 +108,14 @@ RSpec.describe ActivityPub::RepliesController do
end end
it 'points next to other self-replies' do it 'points next to other self-replies' do
expect(page_json).to be_a Hash expect(response.parsed_body)
expect(parsed_uri_query_values(page_json[:next])).to include('only_other_accounts=false', 'page=true') .to include(
first: be_a(Hash).and(
include(
next: satisfy { |value| (parsed_uri_query_values(value) & %w(only_other_accounts=false page=true)).any? }
)
)
)
end end
end end
end end
@ -107,26 +124,31 @@ RSpec.describe ActivityPub::RepliesController do
let(:only_other_accounts) { 'true' } let(:only_other_accounts) { 'true' }
it 'returns items with other public or unlisted replies' do it 'returns items with other public or unlisted replies' do
expect(page_json).to be_a Hash expect(response.parsed_body)
expect(page_json[:items]).to be_an Array .to include(
expect(page_json[:items].size).to eq 3 first: be_a(Hash).and(
include(items: be_an(Array).and(have_attributes(size: 3)))
)
)
end end
it 'only inlines items that are local and public or unlisted replies' do it 'only inlines items that are local and public or unlisted replies' do
inlined_replies = page_json[:items].select { |x| x.is_a?(Hash) } expect(inlined_replies)
expect(inlined_replies.all? { |item| targets_public_collection?(item) }).to be true .to all(satisfy { |item| targets_public_collection?(item) })
expect(inlined_replies.all? { |item| ActivityPub::TagManager.instance.local_uri?(item[:id]) }).to be true .and all(satisfy { |item| ActivityPub::TagManager.instance.local_uri?(item[:id]) })
end end
it 'uses ids for remote toots' do it 'uses ids for remote toots' do
remote_replies = page_json[:items].reject { |x| x.is_a?(Hash) } expect(remote_replies)
expect(remote_replies.all? { |item| item.is_a?(String) && !ActivityPub::TagManager.instance.local_uri?(item) }).to be true .to all(satisfy { |item| item.is_a?(String) && !ActivityPub::TagManager.instance.local_uri?(item) })
end end
context 'when there are few replies' do context 'when there are few replies' do
it 'does not have a next page' do it 'does not have a next page' do
expect(page_json).to be_a Hash expect(response.parsed_body)
expect(page_json[:next]).to be_nil .to include(
first: be_a(Hash).and(not_include(next: be_present))
)
end end
end end
@ -136,8 +158,14 @@ RSpec.describe ActivityPub::RepliesController do
end end
it 'points next to other replies' do it 'points next to other replies' do
expect(page_json).to be_a Hash expect(response.parsed_body)
expect(parsed_uri_query_values(page_json[:next])).to include('only_other_accounts=true', 'page=true') .to include(
first: be_a(Hash).and(
include(
next: satisfy { |value| (parsed_uri_query_values(value) & %w(only_other_accounts=true page=true)).any? }
)
)
)
end end
end end
end end
@ -193,6 +221,18 @@ RSpec.describe ActivityPub::RepliesController do
private private
def inlined_replies
response
.parsed_body[:first][:items]
.select { |x| x.is_a?(Hash) }
end
def remote_replies
response
.parsed_body[:first][:items]
.reject { |x| x.is_a?(Hash) }
end
def parsed_uri_query_values(uri) def parsed_uri_query_values(uri)
Addressable::URI Addressable::URI
.parse(uri) .parse(uri)