mastodon/spec/requests/activitypub/contexts_spec.rb
Jesse Karmani 65b4a0a6f1
Some checks failed
Check i18n / check-i18n (push) Has been cancelled
Chromatic / Run Chromatic (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
CodeQL / Analyze (ruby) (push) Has been cancelled
Crowdin / Upload translations / upload-translations (push) Has been cancelled
Check formatting / lint (push) Has been cancelled
JavaScript Linting / lint (push) Has been cancelled
Ruby Linting / lint (push) Has been cancelled
JavaScript Testing / test (push) Has been cancelled
Historical data migration test / test (14-alpine) (push) Has been cancelled
Historical data migration test / test (15-alpine) (push) Has been cancelled
Historical data migration test / test (16-alpine) (push) Has been cancelled
Historical data migration test / test (17-alpine) (push) Has been cancelled
Ruby Testing / build (production) (push) Has been cancelled
Ruby Testing / build (test) (push) Has been cancelled
Ruby Testing / test (.ruby-version) (push) Has been cancelled
Ruby Testing / test (3.2) (push) Has been cancelled
Ruby Testing / test (3.3) (push) Has been cancelled
Ruby Testing / ImageMagick tests (.ruby-version) (push) Has been cancelled
Ruby Testing / ImageMagick tests (3.2) (push) Has been cancelled
Ruby Testing / ImageMagick tests (3.3) (push) Has been cancelled
Ruby Testing / End to End testing (.ruby-version) (push) Has been cancelled
Ruby Testing / End to End testing (3.2) (push) Has been cancelled
Ruby Testing / End to End testing (3.3) (push) Has been cancelled
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Has been cancelled
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:8.10.2) (push) Has been cancelled
Ruby Testing / Elastic Search integration testing (.ruby-version, opensearchproject/opensearch:2) (push) Has been cancelled
Ruby Testing / Elastic Search integration testing (3.2, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Has been cancelled
Ruby Testing / Elastic Search integration testing (3.3, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Has been cancelled
Bundler Audit / security (push) Has been cancelled
Implement FEP 7888: Part 1 - publish conversation context (#35959)
2025-09-05 19:28:29 +00:00

128 lines
3.3 KiB
Ruby

# frozen_string_literal: true
require 'rails_helper'
RSpec.describe 'ActivityPub Contexts' do
let(:conversation) { Fabricate(:conversation) }
describe 'GET #show' do
subject { get context_path(id: conversation.id), headers: nil }
let!(:status) { Fabricate(:status, conversation: conversation) }
let!(:unrelated_status) { Fabricate(:status) }
it 'returns http success and correct media type and correct items' do
subject
expect(response)
.to have_http_status(200)
.and have_cacheable_headers
expect(response.media_type)
.to eq 'application/activity+json'
expect(response.parsed_body[:type])
.to eq 'Collection'
expect(response.parsed_body[:first][:items])
.to be_an(Array)
.and have_attributes(size: 1)
.and include(ActivityPub::TagManager.instance.uri_for(status))
.and not_include(ActivityPub::TagManager.instance.uri_for(unrelated_status))
end
context 'with pagination' do
context 'with few statuses' do
before do
3.times do
Fabricate(:status, conversation: conversation)
end
end
it 'does not include a next page link' do
subject
expect(response.parsed_body[:first][:next]).to be_nil
end
end
context 'with many statuses' do
before do
(ActivityPub::ContextsController::DESCENDANTS_LIMIT + 1).times do
Fabricate(:status, conversation: conversation)
end
end
it 'includes a next page link' do
subject
expect(response.parsed_body['first']['next']).to_not be_nil
end
end
end
end
describe 'GET #items' do
subject { get items_context_path(id: conversation.id, page: 0, min_id: nil), headers: nil }
context 'with few statuses' do
before do
3.times do
Fabricate(:status, conversation: conversation)
end
end
it 'returns http success and correct media type and correct items' do
subject
expect(response)
.to have_http_status(200)
expect(response.media_type)
.to eq 'application/activity+json'
expect(response.parsed_body[:type])
.to eq 'Collection'
expect(response.parsed_body[:first][:items])
.to be_an(Array)
.and have_attributes(size: 3)
expect(response.parsed_body[:first][:next]).to be_nil
end
end
context 'with many statuses' do
before do
(ActivityPub::ContextsController::DESCENDANTS_LIMIT + 1).times do
Fabricate(:status, conversation: conversation)
end
end
it 'includes a next page link' do
subject
expect(response.parsed_body['first']['next']).to_not be_nil
end
end
context 'with page requested' do
before do
(ActivityPub::ContextsController::DESCENDANTS_LIMIT + 1).times do |_i|
Fabricate(:status, conversation: conversation)
end
end
it 'returns the correct items' do
get items_context_path(id: conversation.id, page: 0, min_id: nil), headers: nil
next_page = response.parsed_body['first']['next']
get next_page, headers: nil
expect(response.parsed_body['items'])
.to be_an(Array)
.and have_attributes(size: 1)
end
end
end
end