mirror of https://github.com/mastodon/mastodon
Fix 500 error in `GET /api/v2_alpha/notifications` when there are no notifications to return (#31746)
This commit is contained in:
parent
ee55d20fd5
commit
1fcffa573c
|
@ -77,6 +77,8 @@ class Api::V2Alpha::NotificationsController < Api::BaseController
|
|||
end
|
||||
|
||||
def load_grouped_notifications
|
||||
return [] if @notifications.empty?
|
||||
|
||||
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])
|
||||
end
|
||||
|
|
|
@ -116,6 +116,19 @@ RSpec.describe 'Notifications' do
|
|||
|
||||
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
|
||||
it 'returns expected notification types', :aggregate_failures do
|
||||
subject
|
||||
|
|
Loading…
Reference in New Issue