chore: Add unread notification count API (#1646)

Co-authored-by: Sojan <sojan@pepalo.com>
This commit is contained in:
Muhsin Keloth
2021-01-17 09:15:31 -08:00
committed by GitHub
parent b6e8173b24
commit dd90e24d02
3 changed files with 31 additions and 0 deletions

View File

@@ -102,4 +102,29 @@ RSpec.describe 'Notifications API', type: :request do
end
end
end
describe 'GET /api/v1/accounts/{account.id}/notifications/unread_count' do
context 'when it is an unauthenticated user' do
it 'returns unauthorized' do
get "/api/v1/accounts/#{account.id}/notifications/unread_count"
expect(response).to have_http_status(:unauthorized)
end
end
context 'when it is an authenticated user' do
let(:admin) { create(:user, account: account, role: :administrator) }
it 'returns notifications unread count' do
2.times.each { create(:notification, account: account, user: admin) }
get "/api/v1/accounts/#{account.id}/notifications/unread_count",
headers: admin.create_new_auth_token,
as: :json
response_json = JSON.parse(response.body)
expect(response).to have_http_status(:success)
expect(response_json).to eq 2
end
end
end
end