Browse Source

Fixes #4654 - Online notification list is not ordered in correct way inside mobile view.

Florian Liebe 1 year ago
parent
commit
d5235adcd3

+ 1 - 1
app/graphql/gql/queries/online_notifications.rb

@@ -8,7 +8,7 @@ module Gql::Queries
     type Gql::Types::OnlineNotificationType.connection_type, null: false
 
     def resolve(...)
-      OnlineNotification.where(user: context.current_user)
+      OnlineNotification.where(user: context.current_user).reorder(created_at: :desc)
     end
   end
 end

+ 13 - 0
spec/graphql/gql/queries/online_notifications_spec.rb

@@ -79,5 +79,18 @@ RSpec.describe Gql::Queries::OnlineNotifications, authenticated_as: :user, type:
           .to include(include('id' => gql.id(inaccessible_notification), 'metaObject' => nil, 'createdBy' => nil))
       end
     end
+
+    context 'with some more notifications' do
+      let(:notification)              { nil }
+      let(:another_user_notification) { nil }
+      let(:notifications)             { Array.new(10) { create(:online_notification, user: user, created_at: Faker::Date.between(from: 1.year.ago, to: 50.weeks.from_now).to_datetime) } }
+
+      it 'returns notifications in correct order' do
+        notifications
+        gql.execute(query)
+
+        expect(gql.result.nodes.pluck('id')).to eq(notifications.sort_by { |n| n[:created_at] }.reverse.map { |n| gql.id(n) })
+      end
+    end
   end
 end