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

58 lines
1.6 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::Areas, type: :service do
let(:user) { create(:user) }
let(:service) { described_class.new(user) }
2025-06-26 16:05:32 -04:00
subject { service.call }
2025-06-26 13:24:40 -04:00
describe '#call' do
context 'when user has no areas' do
it 'returns an empty array' do
2025-06-26 16:05:32 -04:00
expect(subject).to eq([])
2025-06-26 13:24:40 -04:00
end
end
context 'when user has areas' do
let!(:area1) { create(:area, user: user, name: 'Home', radius: 100) }
let!(:area2) { create(:area, user: user, name: 'Work', radius: 200) }
it 'returns all user areas' 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 |area_data|
2025-06-26 13:24:40 -04:00
expect(area_data).not_to have_key('user_id')
expect(area_data).not_to have_key('id')
end
end
it 'includes expected area attributes' do
2025-06-26 13:48:42 -04:00
area_data = subject.find { |a| a['name'] == 'Home' }
2025-06-26 13:24:40 -04:00
expect(area_data).to include(
'name' => 'Home',
'radius' => 100
)
expect(area_data).to have_key('created_at')
expect(area_data).to have_key('updated_at')
end
end
context 'with multiple users' do
let(:other_user) { create(:user) }
let!(:user_area) { create(:area, user: user, name: 'User Area') }
let!(:other_user_area) { create(:area, user: other_user, name: 'Other User Area') }
2025-06-26 13:48:42 -04:00
it 'only returns areas for the specified user' do
expect(subject.size).to eq(1)
expect(subject.first['name']).to eq('User Area')
2025-06-26 13:24:40 -04:00
end
end
end
end