dawarich/spec/services/users/export_data/notifications_spec.rb

58 lines
1.8 KiB
Ruby
Raw Normal View History

2025-06-26 13:24:40 -04:00
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Users::ExportData::Notifications, type: :service do
let(:user) { create(:user) }
let(:service) { described_class.new(user) }
2025-06-26 13:48:42 -04:00
subject { service.call }
2025-06-26 13:24:40 -04:00
describe '#call' do
context 'when user has no notifications' do
it 'returns an empty array' do
2025-06-26 13:48:42 -04:00
expect(subject).to eq([])
2025-06-26 13:24:40 -04:00
end
end
context 'when user has notifications' do
let!(:notification1) { create(:notification, user: user, title: 'Test 1', kind: :info) }
let!(:notification2) { create(:notification, user: user, title: 'Test 2', kind: :warning) }
it 'returns all user notifications' do
2025-06-26 13:48:42 -04:00
expect(subject).to be_an(Array)
expect(subject.size).to eq(2)
2025-06-26 13:24:40 -04:00
end
it 'excludes user_id and id fields' do
2025-06-26 13:48:42 -04:00
subject.each do |notification_data|
2025-06-26 13:24:40 -04:00
expect(notification_data).not_to have_key('user_id')
expect(notification_data).not_to have_key('id')
end
end
it 'includes expected notification attributes' do
2025-06-26 13:48:42 -04:00
notification_data = subject.find { |n| n['title'] == 'Test 1' }
2025-06-26 13:24:40 -04:00
expect(notification_data).to include(
'title' => 'Test 1',
'kind' => 'info'
)
expect(notification_data).to have_key('created_at')
expect(notification_data).to have_key('updated_at')
end
end
context 'with multiple users' do
let(:other_user) { create(:user) }
let!(:user_notification) { create(:notification, user: user, title: 'User Notification') }
let!(:other_user_notification) { create(:notification, user: other_user, title: 'Other Notification') }
it 'only returns notifications for the specified user' do
2025-06-26 13:48:42 -04:00
expect(subject.size).to eq(1)
expect(subject.first['title']).to eq('User Notification')
2025-06-26 13:24:40 -04:00
end
end
end
end