mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 16:21:18 +08:00
FIX: Ensure username
param is valid in NotificationsController
.
This commit is contained in:
@ -5,14 +5,41 @@ describe NotificationsController do
|
||||
context 'when logged in' do
|
||||
let!(:user) { log_in }
|
||||
|
||||
it 'should succeed for recent' do
|
||||
xhr :get, :index, recent: true
|
||||
expect(response).to be_success
|
||||
end
|
||||
describe '#index' do
|
||||
it 'should succeed for recent' do
|
||||
xhr :get, :index, recent: true
|
||||
expect(response).to be_success
|
||||
end
|
||||
|
||||
it 'should succeed for history' do
|
||||
xhr :get, :index
|
||||
expect(response).to be_success
|
||||
it 'should succeed for history' do
|
||||
xhr :get, :index
|
||||
expect(response).to be_success
|
||||
end
|
||||
|
||||
it 'should mark notifications as viewed' do
|
||||
notification = Fabricate(:notification, user: user)
|
||||
expect(user.reload.unread_notifications).to eq(1)
|
||||
expect(user.reload.total_unread_notifications).to eq(1)
|
||||
xhr :get, :index, recent: true
|
||||
expect(user.reload.unread_notifications).to eq(0)
|
||||
expect(user.reload.total_unread_notifications).to eq(1)
|
||||
end
|
||||
|
||||
it 'should not mark notifications as viewed if silent param is present' do
|
||||
notification = Fabricate(:notification, user: user)
|
||||
expect(user.reload.unread_notifications).to eq(1)
|
||||
expect(user.reload.total_unread_notifications).to eq(1)
|
||||
xhr :get, :index, recent: true, silent: true
|
||||
expect(user.reload.unread_notifications).to eq(1)
|
||||
expect(user.reload.total_unread_notifications).to eq(1)
|
||||
end
|
||||
|
||||
context 'when username params is not valid' do
|
||||
it 'should raise the right error' do
|
||||
expect { xhr :get, :index, username: 'somedude' }
|
||||
.to raise_error(Discourse::InvalidParameters)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it 'should succeed' do
|
||||
@ -20,24 +47,6 @@ describe NotificationsController do
|
||||
expect(response).to be_success
|
||||
end
|
||||
|
||||
it 'should mark notifications as viewed' do
|
||||
notification = Fabricate(:notification, user: user)
|
||||
expect(user.reload.unread_notifications).to eq(1)
|
||||
expect(user.reload.total_unread_notifications).to eq(1)
|
||||
xhr :get, :index, recent: true
|
||||
expect(user.reload.unread_notifications).to eq(0)
|
||||
expect(user.reload.total_unread_notifications).to eq(1)
|
||||
end
|
||||
|
||||
it 'should not mark notifications as viewed if silent param is present' do
|
||||
notification = Fabricate(:notification, user: user)
|
||||
expect(user.reload.unread_notifications).to eq(1)
|
||||
expect(user.reload.total_unread_notifications).to eq(1)
|
||||
xhr :get, :index, recent: true, silent: true
|
||||
expect(user.reload.unread_notifications).to eq(1)
|
||||
expect(user.reload.total_unread_notifications).to eq(1)
|
||||
end
|
||||
|
||||
it "can update a single notification" do
|
||||
notification = Fabricate(:notification, user: user)
|
||||
notification2 = Fabricate(:notification, user: user)
|
||||
|
Reference in New Issue
Block a user