From 34489591ec4d05fa16049e9e99d39a09a80f2d65 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 2 Apr 2024 09:54:11 -0400 Subject: [PATCH] Add `max_pinned_statuses` to instances serializer and api response (#29441) --- app/serializers/rest/instance_serializer.rb | 1 + spec/requests/api/v2/instance_spec.rb | 20 +++++++++++++++++++ .../rest/instance_serializer_spec.rb | 11 ++++++++++ 3 files changed, 32 insertions(+) diff --git a/app/serializers/rest/instance_serializer.rb b/app/serializers/rest/instance_serializer.rb index fa926cd2872..42b73f4387c 100644 --- a/app/serializers/rest/instance_serializer.rb +++ b/app/serializers/rest/instance_serializer.rb @@ -54,6 +54,7 @@ class REST::InstanceSerializer < ActiveModel::Serializer accounts: { max_featured_tags: FeaturedTag::LIMIT, + max_pinned_statuses: StatusPinValidator::PIN_LIMIT, }, statuses: { diff --git a/spec/requests/api/v2/instance_spec.rb b/spec/requests/api/v2/instance_spec.rb index 74574afbcf7..c5c6a26f49e 100644 --- a/spec/requests/api/v2/instance_spec.rb +++ b/spec/requests/api/v2/instance_spec.rb @@ -18,6 +18,7 @@ describe 'Instances' do expect(body_as_json) .to be_present .and include(title: 'Mastodon') + .and include_configuration_limits end end @@ -31,7 +32,26 @@ describe 'Instances' do expect(body_as_json) .to be_present .and include(title: 'Mastodon') + .and include_configuration_limits end end + + def include_configuration_limits + include( + configuration: include( + accounts: include( + max_featured_tags: FeaturedTag::LIMIT, + max_pinned_statuses: StatusPinValidator::PIN_LIMIT + ), + statuses: include( + max_characters: StatusLengthValidator::MAX_CHARS, + max_media_attachments: 4 # TODO, move to constant somewhere + ), + polls: include( + max_options: PollValidator::MAX_OPTIONS + ) + ) + ) + end end end diff --git a/spec/serializers/rest/instance_serializer_spec.rb b/spec/serializers/rest/instance_serializer_spec.rb index d8f2536d200..39e6b3820b7 100644 --- a/spec/serializers/rest/instance_serializer_spec.rb +++ b/spec/serializers/rest/instance_serializer_spec.rb @@ -10,11 +10,22 @@ describe REST::InstanceSerializer do it 'returns recent usage data' do expect(serialization['usage']).to eq({ 'users' => { 'active_month' => 0 } }) end + end + describe 'configuration' do it 'returns the VAPID public key' do expect(serialization['configuration']['vapid']).to eq({ 'public_key' => Rails.configuration.x.vapid_public_key, }) end + + it 'returns the max pinned statuses limit' do + expect(serialization.deep_symbolize_keys) + .to include( + configuration: include( + accounts: include(max_pinned_statuses: StatusPinValidator::PIN_LIMIT) + ) + ) + end end end