mirror of https://github.com/tootsuite/mastodon
Fix 500 error in `GET /api/v2_alpha/notifications` when there are no notifications to return (#31746)
parent
ee55d20fd5
commit
1fcffa573c
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue