mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-11 01:31:39 -05:00
* Add yearly digest * Rename YearlyDigests to Users::Digests * Minor changes * Update yearly digest layout and styles * Add flags and chart to email * Update colors * Fix layout of stats in yearly digest view * Remove cron job for yearly digest scheduling * Update CHANGELOG.md * Update digest email setting handling * Allow sharing digest for 1 week or 1 month * Change Digests Distance to Bigint * Fix settings page
49 lines
1.5 KiB
Ruby
49 lines
1.5 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'rails_helper'
|
|
|
|
RSpec.describe Users::Digests::CalculatingJob, type: :job do
|
|
describe '#perform' do
|
|
let!(:user) { create(:user) }
|
|
let(:year) { 2024 }
|
|
|
|
subject { described_class.perform_now(user.id, year) }
|
|
|
|
before do
|
|
allow(Users::Digests::CalculateYear).to receive(:new).and_call_original
|
|
allow_any_instance_of(Users::Digests::CalculateYear).to receive(:call)
|
|
end
|
|
|
|
it 'calls Users::Digests::CalculateYear service' do
|
|
subject
|
|
|
|
expect(Users::Digests::CalculateYear).to have_received(:new).with(user.id, year)
|
|
end
|
|
|
|
it 'enqueues to the digests queue' do
|
|
expect(described_class.new.queue_name).to eq('digests')
|
|
end
|
|
|
|
context 'when Users::Digests::CalculateYear raises an error' do
|
|
before do
|
|
allow_any_instance_of(Users::Digests::CalculateYear).to receive(:call).and_raise(StandardError.new('Test error'))
|
|
end
|
|
|
|
it 'creates an error notification' do
|
|
expect { subject }.to change { Notification.count }.by(1)
|
|
expect(Notification.last.kind).to eq('error')
|
|
expect(Notification.last.title).to include('Year-End Digest')
|
|
end
|
|
end
|
|
|
|
context 'when user does not exist' do
|
|
before do
|
|
allow_any_instance_of(Users::Digests::CalculateYear).to receive(:call).and_raise(ActiveRecord::RecordNotFound)
|
|
end
|
|
|
|
it 'does not raise error' do
|
|
expect { subject }.not_to raise_error
|
|
end
|
|
end
|
|
end
|
|
end
|