2024-10-24 10:59:15 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
|
|
RSpec.describe BulkStatsCalculatingJob, type: :job do
|
|
|
|
|
describe '#perform' do
|
2024-12-06 10:52:36 -05:00
|
|
|
let(:user1) { create(:user) }
|
|
|
|
|
let(:user2) { create(:user) }
|
|
|
|
|
|
|
|
|
|
let(:timestamp) { DateTime.new(2024, 1, 1).to_i }
|
2024-10-24 10:59:15 -04:00
|
|
|
|
2025-01-20 11:59:13 -05:00
|
|
|
let!(:points1) do
|
|
|
|
|
(1..10).map do |i|
|
|
|
|
|
create(:point, user_id: user1.id, timestamp: timestamp + i.minutes)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
let!(:points2) do
|
|
|
|
|
(1..10).map do |i|
|
|
|
|
|
create(:point, user_id: user2.id, timestamp: timestamp + i.minutes)
|
|
|
|
|
end
|
|
|
|
|
end
|
2024-12-06 10:52:36 -05:00
|
|
|
|
|
|
|
|
it 'enqueues Stats::CalculatingJob for each user' do
|
|
|
|
|
expect(Stats::CalculatingJob).to receive(:perform_later).with(user1.id, 2024, 1)
|
|
|
|
|
expect(Stats::CalculatingJob).to receive(:perform_later).with(user2.id, 2024, 1)
|
2024-10-24 10:59:15 -04:00
|
|
|
|
|
|
|
|
BulkStatsCalculatingJob.perform_now
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|