1
0
mirror of https://github.com/funamitech/mastodon synced 2024-11-27 14:29:03 +09:00

Fix 500 error in GET /api/v2_alpha/notifications when there are no notifications to return (#31746)

This commit is contained in:
Claire 2024-09-04 14:54:15 +02:00 committed by GitHub
parent ee55d20fd5
commit 1fcffa573c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 0 deletions

View File

@ -77,6 +77,8 @@ class Api::V2Alpha::NotificationsController < Api::BaseController
end end
def load_grouped_notifications def load_grouped_notifications
return [] if @notifications.empty?
MastodonOTELTracer.in_span('Api::V2Alpha::NotificationsController#load_grouped_notifications') do MastodonOTELTracer.in_span('Api::V2Alpha::NotificationsController#load_grouped_notifications') do
NotificationGroup.from_notifications(@notifications, pagination_range: (@notifications.last.id)..(@notifications.first.id), grouped_types: params[:grouped_types]) NotificationGroup.from_notifications(@notifications, pagination_range: (@notifications.last.id)..(@notifications.first.id), grouped_types: params[:grouped_types])
end end

View File

@ -116,6 +116,19 @@ RSpec.describe 'Notifications' do
it_behaves_like 'forbidden for wrong scope', 'write write:notifications' it_behaves_like 'forbidden for wrong scope', 'write write:notifications'
context 'when there are no notifications' do
before do
user.account.notifications.destroy_all
end
it 'returns 0 notifications' do
subject
expect(response).to have_http_status(200)
expect(body_as_json[:notification_groups]).to eq []
end
end
context 'with no options' do context 'with no options' do
it 'returns expected notification types', :aggregate_failures do it 'returns expected notification types', :aggregate_failures do
subject subject