Skip to content

Commit

Permalink
✅ Update specs for UserStatCollectionJob
Browse files Browse the repository at this point in the history
- Added spec contexts to test behavior when UserStat records are present and absent.
- Defined a FactoryBot factory for UserStat to support spec setup.
  • Loading branch information
Shana Moore committed Jan 22, 2025
1 parent d5da258 commit 72c5ab1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
9 changes: 9 additions & 0 deletions spec/factories/user_stats.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FactoryBot.define do
factory :user_stat do
user_id { create(:user).id }
date { Date.today }
file_views { rand(1..100) }
file_downloads { rand(1..100) }
work_views { rand(1..100) }
end
end
21 changes: 17 additions & 4 deletions spec/jobs/user_stat_collection_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,23 @@

let(:account) { create(:account_with_public_schema) }

describe '#reenqueue' do
it 'Enques an TenantMaintenanceJob after perform' do
switch!(account)
expect { UserStatCollectionJob.perform_now }.to have_enqueued_job(UserStatCollectionJob)
describe '#perform' do
context 'when UserStat records exist' do
before do
FactoryBot.create(:user_stat) # Ensure a UserStat record exists
end

it 'enqueues UserStatCollectionJob after perform' do
switch!(account)
expect { UserStatCollectionJob.perform_now }.to have_enqueued_job(UserStatCollectionJob)
end
end

context 'when no UserStat records exist' do
it 'does not enqueue UserStatCollectionJob' do
switch!(account)
expect { UserStatCollectionJob.perform_now }.not_to have_enqueued_job(UserStatCollectionJob)
end
end
end
end

0 comments on commit 72c5ab1

Please sign in to comment.