dawarich/spec/jobs/stats/calculating_job_spec.rb

34 lines
921 B
Ruby
Raw Permalink Normal View History

# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Stats::CalculatingJob, type: :job do
describe '#perform' do
let!(:user) { create(:user) }
2024-12-06 10:52:36 -05:00
subject { described_class.perform_now(user.id, 2024, 1) }
before do
2024-12-06 10:52:36 -05:00
allow(Stats::CalculateMonth).to receive(:new).and_call_original
allow_any_instance_of(Stats::CalculateMonth).to receive(:call)
end
2024-12-06 10:52:36 -05:00
it 'calls Stats::CalculateMonth service' do
subject
2024-12-06 10:52:36 -05:00
expect(Stats::CalculateMonth).to have_received(:new).with(user.id, 2024, 1)
end
2024-12-06 10:52:36 -05:00
context 'when Stats::CalculateMonth raises an error' do
before do
allow_any_instance_of(Stats::CalculateMonth).to receive(:call).and_raise(StandardError)
end
it 'creates an error notification' do
expect { subject }.to change { Notification.count }.by(1)
expect(Notification.last.kind).to eq('error')
end
end
end
end