chore(correction): passing en_instruction resolve pending corrections

This commit is contained in:
Colin Darie 2023-04-04 10:29:27 +02:00
parent 5ab44fc7a9
commit 62cc9d30d8
No known key found for this signature in database
GPG key ID: 4FB865FDBCA4BCC4
4 changed files with 35 additions and 0 deletions

View file

@ -26,5 +26,9 @@ module DossierCorrectableConcern
corrections.pending.exists?
end
def resolve_pending_correction!
corrections.pending.update(resolved_at: Time.current)
end
end
end

View file

@ -891,6 +891,8 @@ class Dossier < ApplicationRecord
.processed_at
save!
resolve_pending_correction!
if !disable_notification
NotificationMailer.send_en_instruction_notification(self).deliver_later
end

View file

@ -77,4 +77,27 @@ describe DossierCorrectableConcern do
end
end
end
describe "#resolve_pending_correction!" do
let(:dossier) { create(:dossier, :en_construction) }
subject(:resolve) { dossier.resolve_pending_correction! }
context "when dossier has no correction" do
it { expect { resolve }.not_to change { dossier.corrections.pending.count } }
end
context "when dossier has a pending correction" do
let!(:correction) { create(:dossier_correction, dossier:) }
it {
expect { resolve }.to change { correction.reload.resolved_at }.from(nil)
}
end
context "when dossier has a already resolved correction" do
before { create(:dossier_correction, :resolved, dossier:) }
it { expect { resolve }.not_to change { dossier.corrections.pending.count } }
end
end
end

View file

@ -1044,6 +1044,7 @@ describe Dossier do
let(:last_operation) { dossier.dossier_operation_logs.last }
let(:operation_serialized) { last_operation.data }
let(:instructeur) { create(:instructeur) }
let!(:correction) { create(:dossier_correction, dossier:) }
before { dossier.passer_en_instruction!(instructeur: instructeur) }
@ -1055,6 +1056,11 @@ describe Dossier do
it { expect(operation_serialized['operation']).to eq('passer_en_instruction') }
it { expect(operation_serialized['dossier_id']).to eq(dossier.id) }
it { expect(operation_serialized['executed_at']).to eq(last_operation.executed_at.iso8601) }
it "resolve pending correction" do
expect(dossier.pending_correction?).to be_falsey
expect(correction.reload.resolved_at).to be_present
end
end
describe '#passer_automatiquement_en_instruction!' do