refactor(sva): dossier can't repasser en construction without pending correction
This commit is contained in:
parent
30df476791
commit
d70278a534
9 changed files with 48 additions and 5 deletions
|
@ -15,7 +15,7 @@ class Instructeurs::EnConstructionMenuComponent < ApplicationComponent
|
|||
end
|
||||
|
||||
def menu_label
|
||||
if dossier.en_construction?
|
||||
if !dossier.may_repasser_en_construction?
|
||||
t('.request_correction')
|
||||
else
|
||||
t(".revert_en_construction")
|
||||
|
|
|
@ -15,13 +15,13 @@ module DossierCorrectableConcern
|
|||
|
||||
return if en_construction?
|
||||
|
||||
repasser_en_construction!(instructeur: commentaire.instructeur)
|
||||
repasser_en_construction_with_pending_correction!(instructeur: commentaire.instructeur)
|
||||
end
|
||||
|
||||
def may_flag_as_pending_correction?
|
||||
return false if pending_corrections.exists?
|
||||
|
||||
en_construction? || may_repasser_en_construction?
|
||||
en_construction? || may_repasser_en_construction_with_pending_correction?
|
||||
end
|
||||
|
||||
def pending_correction?
|
||||
|
|
|
@ -201,6 +201,10 @@ class Dossier < ApplicationRecord
|
|||
end
|
||||
|
||||
event :repasser_en_construction, after: :after_repasser_en_construction do
|
||||
transitions from: :en_instruction, to: :en_construction, guard: :can_repasser_en_construction?
|
||||
end
|
||||
|
||||
event :repasser_en_construction_with_pending_correction, after: :after_repasser_en_construction do
|
||||
transitions from: :en_instruction, to: :en_construction
|
||||
end
|
||||
|
||||
|
@ -581,6 +585,10 @@ class Dossier < ApplicationRecord
|
|||
false
|
||||
end
|
||||
|
||||
def can_repasser_en_construction?
|
||||
!procedure.sva_svr_enabled?
|
||||
end
|
||||
|
||||
def can_repasser_en_instruction?
|
||||
termine? && !user_deleted?
|
||||
end
|
||||
|
|
|
@ -46,7 +46,7 @@
|
|||
%li{ 'data-turbo': turbo ? 'true' : 'false' }
|
||||
= button_to passer_en_instruction_instructeur_dossier_path(procedure_id, dossier_id), method: :post, class: 'fr-btn fr-icon-edit-line' do
|
||||
Passer en instruction
|
||||
- elsif Dossier.states[:en_instruction] == state && !with_menu
|
||||
- elsif Dossier.states[:en_instruction] == state && !with_menu && !sva_svr
|
||||
%li{ 'data-turbo': turbo ? 'true' : 'false' }
|
||||
= button_to repasser_en_construction_instructeur_dossier_path(procedure_id, dossier_id), method: :post, class: 'fr-btn fr-btn--secondary fr-icon-draft-line' do
|
||||
Repasser en construction
|
||||
|
|
|
@ -183,6 +183,7 @@
|
|||
dossier_is_followed: @followed_dossiers_id.include?(p.dossier_id),
|
||||
close_to_expiration: @statut == 'expirant',
|
||||
hidden_by_administration: @statut == 'supprimes_recemment',
|
||||
sva_svr: @procedure.sva_svr_enabled?,
|
||||
turbo: false,
|
||||
with_menu: false }
|
||||
%tfoot
|
||||
|
|
|
@ -101,6 +101,7 @@
|
|||
dossier_is_followed: @followed_dossiers_id.include?(p.dossier_id),
|
||||
close_to_expiration: nil,
|
||||
hidden_by_administration: nil,
|
||||
sva_svr: p.sva_svr_decision_on.present?,
|
||||
turbo: false,
|
||||
with_menu: false }
|
||||
|
||||
|
|
|
@ -49,5 +49,15 @@ RSpec.describe Instructeurs::EnConstructionMenuComponent, type: :component do
|
|||
expect(subject).to have_dropdown_item('Repasser en construction')
|
||||
expect(subject).to have_dropdown_items(count: 3)
|
||||
end
|
||||
|
||||
context 'when procedure is sva' do
|
||||
let(:dossier) { create(:dossier, :en_instruction, procedure: create(:procedure, :sva)) }
|
||||
|
||||
it 'renders a dropdown' do
|
||||
expect(subject).to have_dropdown_title('Demander une correction')
|
||||
expect(subject).to have_dropdown_item('Demander une correction')
|
||||
expect(subject).to have_dropdown_items(count: 2)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -41,7 +41,7 @@ describe DossierCorrectableConcern do
|
|||
end
|
||||
end
|
||||
|
||||
context 'when dossier is not en_instruction' do
|
||||
context 'when dossier is en_instruction' do
|
||||
let(:dossier) { create(:dossier, :en_instruction) }
|
||||
|
||||
it 'creates a correction' do
|
||||
|
@ -76,6 +76,18 @@ describe DossierCorrectableConcern do
|
|||
expect { dossier.flag_as_pending_correction!(commentaire) }.not_to change { dossier.corrections.pending.count }
|
||||
end
|
||||
end
|
||||
|
||||
context 'when procedure is sva' do
|
||||
let(:dossier) { create(:dossier, :en_instruction, procedure: create(:procedure, :published, :sva)) }
|
||||
|
||||
it 'creates a correction' do
|
||||
expect { dossier.flag_as_pending_correction!(commentaire) }.to change { dossier.corrections.pending.count }.by(1)
|
||||
end
|
||||
|
||||
it 'repasse dossier en_construction' do
|
||||
expect { dossier.flag_as_pending_correction!(commentaire) }.to change { dossier.state }.to('en_construction')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#resolve_pending_correction!" do
|
||||
|
|
|
@ -1135,6 +1135,17 @@ describe Dossier, type: :model do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#can_repasser_en_construction?' do
|
||||
let(:dossier) { create(:dossier, :en_instruction) }
|
||||
it { expect(dossier.can_repasser_en_construction?).to be_truthy }
|
||||
|
||||
context 'when procedure is sva' do
|
||||
let(:dossier) { create(:dossier, :en_instruction, procedure: create(:procedure, :sva)) }
|
||||
|
||||
it { expect(dossier.can_repasser_en_construction?).to be_falsey }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#can_passer_automatiquement_en_instruction?' do
|
||||
let(:dossier) { create(:dossier, :en_construction, declarative_triggered_at: declarative_triggered_at) }
|
||||
let(:declarative_triggered_at) { nil }
|
||||
|
|
Loading…
Reference in a new issue