diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb index 1d28fb4caf0..baa9aca3a43 100644 --- a/app/controllers/notifications_controller.rb +++ b/app/controllers/notifications_controller.rb @@ -25,7 +25,7 @@ class NotificationsController < ApplicationController notifications = Notification.recent_report(current_user, limit) changed = false - if notifications.present? && !(params.has_key?(:slient) || @readonly_mode) + if notifications.present? && !(params.has_key?(:silent) || @readonly_mode) # ordering can be off due to PMs max_id = notifications.map(&:id).max changed = current_user.saw_notification_id(max_id) diff --git a/spec/requests/notifications_controller_spec.rb b/spec/requests/notifications_controller_spec.rb index 495ae5afbe5..3e903280f89 100644 --- a/spec/requests/notifications_controller_spec.rb +++ b/spec/requests/notifications_controller_spec.rb @@ -43,14 +43,23 @@ describe NotificationsController do end it 'should succeed for history' do - get "/notifications" + get "/notifications.json" + expect(response.status).to eq(200) + + notifications = response.parsed_body["notifications"] + + expect(notifications.length).to eq(1) + expect(notifications.first["id"]).to eq(notification.id) end it 'should mark notifications as viewed' do expect(user.reload.unread_notifications).to eq(1) expect(user.reload.total_unread_notifications).to eq(1) + get "/notifications.json", params: { recent: true } + + expect(response.status).to eq(200) expect(user.reload.unread_notifications).to eq(0) expect(user.reload.total_unread_notifications).to eq(1) end @@ -58,7 +67,10 @@ describe NotificationsController do it 'should not mark notifications as viewed if silent param is present' do expect(user.reload.unread_notifications).to eq(1) expect(user.reload.total_unread_notifications).to eq(1) - get "/notifications", params: { recent: true, silent: true } + + get "/notifications.json", params: { recent: true, silent: true } + + expect(response.status).to eq(200) expect(user.reload.unread_notifications).to eq(1) expect(user.reload.total_unread_notifications).to eq(1) end @@ -67,7 +79,10 @@ describe NotificationsController do Discourse.received_redis_readonly! expect(user.reload.unread_notifications).to eq(1) expect(user.reload.total_unread_notifications).to eq(1) - get "/notifications", params: { recent: true, silent: true } + + get "/notifications.json", params: { recent: true, silent: true } + + expect(response.status).to eq(200) expect(user.reload.unread_notifications).to eq(1) expect(user.reload.total_unread_notifications).to eq(1) ensure @@ -81,13 +96,19 @@ describe NotificationsController do expect(response.status).to eq(200) get "/notifications.json" + + expect(response.status).to eq(200) expect(JSON.parse(response.body)['notifications'].length).to be >= 2 get "/notifications.json", params: { filter: "read" } + + expect(response.status).to eq(200) expect(JSON.parse(response.body)['notifications'].length).to be >= 1 expect(JSON.parse(response.body)['notifications'][0]['read']).to eq(true) get "/notifications.json", params: { filter: "unread" } + + expect(response.status).to eq(200) expect(JSON.parse(response.body)['notifications'].length).to be >= 1 expect(JSON.parse(response.body)['notifications'][0]['read']).to eq(false) end @@ -120,7 +141,10 @@ describe NotificationsController do it "updates the `read` status" do expect(user.reload.unread_notifications).to eq(1) expect(user.reload.total_unread_notifications).to eq(1) + put "/notifications/mark-read.json" + + expect(response.status).to eq(200) user.reload expect(user.reload.unread_notifications).to eq(0) expect(user.reload.total_unread_notifications).to eq(0)