chore(correction): passing en_instruction resolve pending corrections
This commit is contained in:
parent
5ab44fc7a9
commit
62cc9d30d8
4 changed files with 35 additions and 0 deletions
|
@ -26,5 +26,9 @@ module DossierCorrectableConcern
|
||||||
|
|
||||||
corrections.pending.exists?
|
corrections.pending.exists?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def resolve_pending_correction!
|
||||||
|
corrections.pending.update(resolved_at: Time.current)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -891,6 +891,8 @@ class Dossier < ApplicationRecord
|
||||||
.processed_at
|
.processed_at
|
||||||
save!
|
save!
|
||||||
|
|
||||||
|
resolve_pending_correction!
|
||||||
|
|
||||||
if !disable_notification
|
if !disable_notification
|
||||||
NotificationMailer.send_en_instruction_notification(self).deliver_later
|
NotificationMailer.send_en_instruction_notification(self).deliver_later
|
||||||
end
|
end
|
||||||
|
|
|
@ -77,4 +77,27 @@ describe DossierCorrectableConcern do
|
||||||
end
|
end
|
||||||
end
|
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
|
end
|
||||||
|
|
|
@ -1044,6 +1044,7 @@ describe Dossier do
|
||||||
let(:last_operation) { dossier.dossier_operation_logs.last }
|
let(:last_operation) { dossier.dossier_operation_logs.last }
|
||||||
let(:operation_serialized) { last_operation.data }
|
let(:operation_serialized) { last_operation.data }
|
||||||
let(:instructeur) { create(:instructeur) }
|
let(:instructeur) { create(:instructeur) }
|
||||||
|
let!(:correction) { create(:dossier_correction, dossier:) }
|
||||||
|
|
||||||
before { dossier.passer_en_instruction!(instructeur: instructeur) }
|
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['operation']).to eq('passer_en_instruction') }
|
||||||
it { expect(operation_serialized['dossier_id']).to eq(dossier.id) }
|
it { expect(operation_serialized['dossier_id']).to eq(dossier.id) }
|
||||||
it { expect(operation_serialized['executed_at']).to eq(last_operation.executed_at.iso8601) }
|
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
|
end
|
||||||
|
|
||||||
describe '#passer_automatiquement_en_instruction!' do
|
describe '#passer_automatiquement_en_instruction!' do
|
||||||
|
|
Loading…
Add table
Reference in a new issue