From 09017dd8f063926738b253fe964a6b12faaa744f Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Thu, 5 Sep 2024 15:51:17 -0400 Subject: [PATCH] Add worker spec for annual report worker (#31778) --- .../generate_annual_report_worker_spec.rb | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 spec/workers/generate_annual_report_worker_spec.rb 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 0000000000..69b0d4424b --- /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