2021-06-01 15:31:47 +02:00
|
|
|
describe Traitement do
|
|
|
|
describe '#count_dossiers_termines_by_month' do
|
|
|
|
let(:procedure) { create(:procedure, :published, groupe_instructeurs: [groupe_instructeurs]) }
|
|
|
|
let(:groupe_instructeurs) { create(:groupe_instructeur) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
create_dossier_for_month(procedure, 2021, 3)
|
|
|
|
create_dossier_for_month(procedure, 2021, 3)
|
|
|
|
create_dossier_for_month(procedure, 2021, 2)
|
2021-06-17 17:11:54 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
subject do
|
|
|
|
Timecop.freeze(Time.zone.local(2021, 3, 5)) do
|
|
|
|
Traitement.count_dossiers_termines_by_month(groupe_instructeurs)
|
|
|
|
end
|
2021-06-01 15:31:47 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'count dossiers_termines by month' do
|
2021-06-17 17:11:54 +02:00
|
|
|
expect(count_for_month(subject, 3)).to eq 2
|
|
|
|
expect(count_for_month(subject, 2)).to eq 1
|
2021-06-01 15:31:47 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns descending order by month' do
|
2021-06-17 17:11:54 +02:00
|
|
|
expect(subject[0]["month"].to_date.month).to eq 3
|
|
|
|
expect(subject[1]["month"].to_date.month).to eq 2
|
2021-06-01 15:31:47 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def count_for_month(count_dossiers_termines_by_month, month)
|
|
|
|
count_dossiers_termines_by_month.find do |count_by_month|
|
|
|
|
count_by_month["month"].to_date.month == month
|
|
|
|
end["count"]
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_dossier_for_month(procedure, year, month)
|
2021-06-17 17:11:54 +02:00
|
|
|
Timecop.freeze(Time.zone.local(year, month, 5)) do
|
|
|
|
create(:dossier, :accepte, :with_attestation, procedure: procedure)
|
|
|
|
end
|
2021-06-01 15:31:47 +02:00
|
|
|
end
|
|
|
|
end
|