diff --git a/spec/workers/generate_annual_report_worker_spec.rb b/spec/workers/generate_annual_report_worker_spec.rb new file mode 100644 index 000000000..69b0d4424 --- /dev/null +++ b/spec/workers/generate_annual_report_worker_spec.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe GenerateAnnualReportWorker do + let(:worker) { described_class.new } + let(:account) { Fabricate :account } + + describe '#perform' do + it 'generates new report for the account' do + expect { worker.perform(account.id, Date.current.year) } + .to change(account_reports, :count).by(1) + end + + it 'returns true for non-existent record' do + result = worker.perform(123_123_123, Date.current.year) + + expect(result).to be(true) + end + + def account_reports + GeneratedAnnualReport + .where(account: account) + .where(year: Date.current.year) + end + end +end