Chore: FCM Notification Improvements (#957)
Co-authored-by: Pranav Raj Sreepuram <pranavrajs@gmail.com>
This commit is contained in:
@@ -14,7 +14,8 @@ RSpec.describe 'Notifications API', type: :request do
|
||||
|
||||
context 'when it is an authenticated user' do
|
||||
let(:admin) { create(:user, account: account, role: :administrator) }
|
||||
let!(:notification) { create(:notification, account: account, user: admin) }
|
||||
let!(:notification1) { create(:notification, account: account, user: admin) }
|
||||
let!(:notification2) { create(:notification, account: account, user: admin) }
|
||||
|
||||
it 'returns all notifications' do
|
||||
get "/api/v1/accounts/#{account.id}/notifications",
|
||||
@@ -23,8 +24,10 @@ RSpec.describe 'Notifications API', type: :request do
|
||||
|
||||
response_json = JSON.parse(response.body)
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(response.body).to include(notification.notification_type)
|
||||
expect(response_json['data']['meta']['unread_count']).to eq 1
|
||||
expect(response.body).to include(notification1.notification_type)
|
||||
expect(response_json['data']['meta']['unread_count']).to eq 2
|
||||
# notification appear in descending order
|
||||
expect(response_json['data']['payload'].first['id']).to eq notification2.id
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -54,6 +57,20 @@ RSpec.describe 'Notifications API', type: :request do
|
||||
expect(notification1.reload.read_at).not_to eq('')
|
||||
expect(notification2.reload.read_at).not_to eq('')
|
||||
end
|
||||
|
||||
it 'updates only the notifications read at for primary actor when param is passed' do
|
||||
post "/api/v1/accounts/#{account.id}/notifications/read_all",
|
||||
headers: admin.create_new_auth_token,
|
||||
params: {
|
||||
primary_actor_id: notification1.primary_actor_id,
|
||||
primary_actor_type: notification1.primary_actor_type
|
||||
},
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(notification1.reload.read_at).not_to eq('')
|
||||
expect(notification2.reload.read_at).to eq nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
21
spec/models/notification_spec.rb
Normal file
21
spec/models/notification_spec.rb
Normal file
@@ -0,0 +1,21 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Notification do
|
||||
context 'with associations' do
|
||||
it { is_expected.to belong_to(:account) }
|
||||
it { is_expected.to belong_to(:user) }
|
||||
end
|
||||
|
||||
context 'with default order by' do
|
||||
it 'sort by primary id desc' do
|
||||
notification1 = create(:notification)
|
||||
create(:notification)
|
||||
notification3 = create(:notification)
|
||||
|
||||
expect(described_class.all.first).to eq notification3
|
||||
expect(described_class.all.last).to eq notification1
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user