diff --git a/app/components/instructeurs/en_construction_menu_component/en_construction_menu_component.html.haml b/app/components/instructeurs/en_construction_menu_component/en_construction_menu_component.html.haml
index cc7359f33..b5c6c728c 100644
--- a/app/components/instructeurs/en_construction_menu_component/en_construction_menu_component.html.haml
+++ b/app/components/instructeurs/en_construction_menu_component/en_construction_menu_component.html.haml
@@ -48,7 +48,7 @@
- menu.with_item(class: "inactive form-inside fr-pt-1v") do
= render partial: 'instructeurs/dossiers/instruction_button_motivation', locals: { dossier:,
visible: false,
- form_path: pending_correction_instructeur_dossier_path(dossier.procedure, dossier, kind: :incomplete),
+ form_path: pending_correction_instructeur_dossier_path(dossier.procedure, dossier, reason: :incomplete),
placeholder: 'Expliquez au demandeur comment compléter son dossier',
popup_class: 'pending_completion',
button_justificatif_label: "Ajouter une pièce jointe (facultatif)",
diff --git a/app/controllers/instructeurs/dossiers_controller.rb b/app/controllers/instructeurs/dossiers_controller.rb
index 2f1ec2448..848292abc 100644
--- a/app/controllers/instructeurs/dossiers_controller.rb
+++ b/app/controllers/instructeurs/dossiers_controller.rb
@@ -235,7 +235,7 @@ module Instructeurs
commentaire = CommentaireService.build(current_instructeur, dossier, { body: message, piece_jointe: })
if commentaire.valid?
- dossier.flag_as_pending_correction!(commentaire, params[:kind].presence)
+ dossier.flag_as_pending_correction!(commentaire, params[:reason].presence)
dossier.update!(last_commentaire_updated_at: Time.zone.now)
current_instructeur.follow(dossier)
diff --git a/app/graphql/mutations/dossier_envoyer_message.rb b/app/graphql/mutations/dossier_envoyer_message.rb
index b941afa17..5f5c5f8c0 100644
--- a/app/graphql/mutations/dossier_envoyer_message.rb
+++ b/app/graphql/mutations/dossier_envoyer_message.rb
@@ -6,14 +6,19 @@ module Mutations
argument :instructeur_id, ID, required: true, loads: Types::ProfileType
argument :body, String, required: true
argument :attachment, ID, required: false
+ argument :correction, Types::CorrectionType::CorrectionReason, 'Préciser qu’il s’agit d’une demande de correction. Le dossier repasssera en construction.', required: false
field :message, Types::MessageType, null: true
field :errors, [Types::ValidationErrorType], null: true
- def resolve(dossier:, instructeur:, body:, attachment: nil)
+ def resolve(dossier:, instructeur:, body:, attachment: nil, correction: nil)
message = CommentaireService.create(instructeur, dossier, body: body, piece_jointe: attachment)
if message.errors.empty?
+ if correction
+ dossier.flag_as_pending_correction!(message, correction)
+ end
+
{ message: }
else
{ errors: message.errors.full_messages }
diff --git a/app/graphql/schema.graphql b/app/graphql/schema.graphql
index eae5f5945..773df9474 100644
--- a/app/graphql/schema.graphql
+++ b/app/graphql/schema.graphql
@@ -542,6 +542,23 @@ GeoJSON coordinates
"""
scalar Coordinates
+type Correction {
+ dateResolution: ISO8601DateTime
+ reason: CorrectionReason!
+}
+
+enum CorrectionReason {
+ """
+ Le dossier est incomplet et nécessite d’être complété
+ """
+ incomplete
+
+ """
+ Le dossier n’est pas valide et nécessite une correction
+ """
+ incorrect
+}
+
"""
Autogenerated input type of CreateDirectUpload
"""
@@ -1301,6 +1318,11 @@ type Dossier {
"""
dateDepot: ISO8601DateTime!
+ """
+ Date de la dernière demande de correction qui n’a pas encore été traitée par l’usager.
+ """
+ dateDerniereCorrectionEnAttente: ISO8601DateTime
+
"""
Date de la dernière modification.
"""
@@ -1568,6 +1590,11 @@ input DossierEnvoyerMessageInput {
A unique identifier for the client performing the mutation.
"""
clientMutationId: String
+
+ """
+ Préciser qu’il s’agit d’une demande de correction. Le dossier repasssera en construction.
+ """
+ correction: CorrectionReason
dossierId: ID!
instructeurId: ID!
}
@@ -2826,6 +2853,7 @@ type Message {
attachment: File @deprecated(reason: "Utilisez le champ `attachments` à la place.")
attachments: [File!]!
body: String!
+ correction: Correction
createdAt: ISO8601DateTime!
email: String!
id: ID!
diff --git a/app/graphql/types/correction_type.rb b/app/graphql/types/correction_type.rb
new file mode 100644
index 000000000..db897f9c2
--- /dev/null
+++ b/app/graphql/types/correction_type.rb
@@ -0,0 +1,23 @@
+module Types
+ class CorrectionType < Types::BaseObject
+ class CorrectionReason < Types::BaseEnum
+ # i18n-tasks-use t('dossier_correction.reasons.incorrect'), t('dossier_correction.reasons.incomplete')
+ DossierCorrection.reasons.each do |symbol_name, string_name|
+ value(string_name,
+ I18n.t(symbol_name, scope: [:activerecord, :attributes, :dossier_correction, :reasons]),
+ value: symbol_name)
+ end
+ end
+
+ field :reason, CorrectionReason, null: false
+ field :date_resolution, GraphQL::Types::ISO8601DateTime, null: true
+
+ def date_resolution
+ object.resolved_at
+ end
+
+ def message
+ object.commentaire
+ end
+ end
+end
diff --git a/app/graphql/types/dossier_type.rb b/app/graphql/types/dossier_type.rb
index 66476b334..07d188642 100644
--- a/app/graphql/types/dossier_type.rb
+++ b/app/graphql/types/dossier_type.rb
@@ -30,6 +30,8 @@ module Types
field :date_suppression_par_administration, GraphQL::Types::ISO8601DateTime, "Date de la suppression par l’administration.", null: true, method: :hidden_by_administration_at
field :date_expiration, GraphQL::Types::ISO8601DateTime, "Date d’expiration.", null: true
+ field :date_derniere_correction_en_attente, GraphQL::Types::ISO8601DateTime, "Date de la dernière demande de correction qui n’a pas encore été traitée par l’usager.", null: true
+
field :archived, Boolean, null: false
field :connection_usager, ConnectionUsager, null: false
@@ -75,6 +77,10 @@ module Types
end
end
+ def date_derniere_correction_en_attente
+ Loaders::Association.for(object.class, :pending_correction).load(object).then { _1&.created_at }
+ end
+
def connection_usager
if object.user_deleted?
:deleted
diff --git a/app/graphql/types/message_type.rb b/app/graphql/types/message_type.rb
index 1bf29a3cd..665c2dd0b 100644
--- a/app/graphql/types/message_type.rb
+++ b/app/graphql/types/message_type.rb
@@ -10,9 +10,14 @@ module Types
field :attachments, [Types::File], null: false, extensions: [
{ Extensions::Attachment => { attachment: :piece_jointe, as: :multiple } }
]
+ field :correction, CorrectionType, null: true
def body
object.body.nil? ? "" : object.body
end
+
+ def correction
+ Loaders::Association.for(object.class, :dossier_correction).load(object)
+ end
end
end
diff --git a/app/models/concerns/dossier_correctable_concern.rb b/app/models/concerns/dossier_correctable_concern.rb
index 7e43a6e7d..69790fa9e 100644
--- a/app/models/concerns/dossier_correctable_concern.rb
+++ b/app/models/concerns/dossier_correctable_concern.rb
@@ -5,17 +5,18 @@ module DossierCorrectableConcern
A_CORRIGER = 'a_corriger'
has_many :corrections, class_name: 'DossierCorrection', dependent: :destroy
has_many :pending_corrections, -> { DossierCorrection.pending }, class_name: 'DossierCorrection', inverse_of: :dossier
+ has_one :pending_correction, -> { DossierCorrection.pending }, class_name: 'DossierCorrection', inverse_of: :dossier
scope :with_pending_corrections, -> { joins(:corrections).where(corrections: { resolved_at: nil }) }
- def flag_as_pending_correction!(commentaire, kind = nil)
+ def flag_as_pending_correction!(commentaire, reason = nil)
return unless may_flag_as_pending_correction?
- kind ||= :correction
+ reason ||= :incorrect
- corrections.create!(commentaire:, kind:)
+ corrections.create!(commentaire:, reason:)
- log_pending_correction_operation(commentaire, kind) if procedure.sva_svr_enabled?
+ log_pending_correction_operation(commentaire, reason) if procedure.sva_svr_enabled?
return if en_construction?
@@ -37,10 +38,6 @@ module DossierCorrectableConcern
pending_corrections.exists?
end
- def pending_correction
- pending_corrections.first
- end
-
def resolve_pending_correction!
pending_corrections.update!(resolved_at: Time.current)
pending_corrections.reset
@@ -48,9 +45,9 @@ module DossierCorrectableConcern
private
- def log_pending_correction_operation(commentaire, kind)
- operation = case kind.to_sym
- when :correction
+ def log_pending_correction_operation(commentaire, reason)
+ operation = case reason.to_sym
+ when :incorrect
"demander_une_correction"
when :incomplete
"demander_a_completer"
diff --git a/app/models/dossier_correction.rb b/app/models/dossier_correction.rb
index a27524540..c2ff19b13 100644
--- a/app/models/dossier_correction.rb
+++ b/app/models/dossier_correction.rb
@@ -3,7 +3,7 @@
# Table name: dossier_corrections
#
# id :bigint not null, primary key
-# kind :string default("correction"), not null
+# reason :string default("incorrect"), not null
# resolved_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
@@ -14,11 +14,13 @@ class DossierCorrection < ApplicationRecord
belongs_to :dossier
belongs_to :commentaire
+ self.ignored_columns += ['kind']
+
validates_associated :commentaire
scope :pending, -> { where(resolved_at: nil) }
- enum kind: { correction: 'correction', incomplete: 'incomplete' }
+ enum reason: { incorrect: 'incorrect', incomplete: 'incomplete' }, _prefix: :dossier
def resolved?
resolved_at.present?
diff --git a/app/services/sva_svr_decision_date_calculator_service.rb b/app/services/sva_svr_decision_date_calculator_service.rb
index 93b06258e..66614e524 100644
--- a/app/services/sva_svr_decision_date_calculator_service.rb
+++ b/app/services/sva_svr_decision_date_calculator_service.rb
@@ -47,13 +47,13 @@ class SVASVRDecisionDateCalculatorService
def determine_start_date
return dossier.depose_at.to_date if dossier.corrections.empty?
return latest_correction_date if resume_method == :reset
- return latest_incomplete_correction_date if dossier.corrections.any?(&:incomplete?)
+ return latest_incomplete_correction_date if dossier.corrections.any?(&:dossier_incomplete?)
dossier.depose_at.to_date
end
def latest_incomplete_correction_date
- correction_date dossier.corrections.filter(&:incomplete?).max_by(&:resolved_at)
+ correction_date dossier.corrections.filter(&:dossier_incomplete?).max_by(&:resolved_at)
end
def latest_correction_date
diff --git a/app/views/dossier_mailer/notify_pending_correction.html.haml b/app/views/dossier_mailer/notify_pending_correction.html.haml
index a0163ab8e..bd5d24603 100644
--- a/app/views/dossier_mailer/notify_pending_correction.html.haml
+++ b/app/views/dossier_mailer/notify_pending_correction.html.haml
@@ -3,12 +3,12 @@
%p= t(:hello, scope: [:views, :shared, :greetings])
-%p= t(".#{@correction.kind}.explanation_html", dossier_id: @dossier.id, libelle_demarche: @dossier.procedure.libelle)
+%p= t(".#{@correction.reason}.explanation_html", dossier_id: @dossier.id, libelle_demarche: @dossier.procedure.libelle)
%p= t('.link')
= round_button(t('.access_message'), messagerie_dossier_url(@dossier), :primary)
- if @dossier.sva_svr_decision_on.present?
- %p= t(".#{@correction.kind}.sva_svr", rule_name: t(@dossier.procedure.sva? ? :sva : :svr, scope: 'shared.procedures.sva_svr_rule_name'))
+ %p= t(".#{@correction.reason}.sva_svr", rule_name: t(@dossier.procedure.sva? ? :sva : :svr, scope: 'shared.procedures.sva_svr_rule_name'))
= render 'layouts/mailers/signature', service: @service
diff --git a/config/locales/models/dossier_correction/en.yml b/config/locales/models/dossier_correction/en.yml
new file mode 100644
index 000000000..ae14b3766
--- /dev/null
+++ b/config/locales/models/dossier_correction/en.yml
@@ -0,0 +1,7 @@
+en:
+ activerecord:
+ attributes:
+ dossier_correction:
+ reasons:
+ incorrect: "The file is invalid and needs to be corrected"
+ incomplete: "The file is incomplete and needs to be completed"
diff --git a/config/locales/models/dossier_correction/fr.yml b/config/locales/models/dossier_correction/fr.yml
new file mode 100644
index 000000000..f80d37a8c
--- /dev/null
+++ b/config/locales/models/dossier_correction/fr.yml
@@ -0,0 +1,7 @@
+fr:
+ activerecord:
+ attributes:
+ dossier_correction:
+ reasons:
+ incorrect: "Le dossier n’est pas valide et nécessite une correction"
+ incomplete: "Le dossier est incomplet et nécessite d’être complété"
diff --git a/config/locales/views/dossier_mailer/notify_pending_correction/en.yml b/config/locales/views/dossier_mailer/notify_pending_correction/en.yml
index cd749d2df..084b66f08 100644
--- a/config/locales/views/dossier_mailer/notify_pending_correction/en.yml
+++ b/config/locales/views/dossier_mailer/notify_pending_correction/en.yml
@@ -3,7 +3,7 @@ en:
dossier_mailer:
notify_pending_correction:
subject: You need to modify your file no. %{dossier_id} « %{libelle_demarche} »
- correction:
+ incorrect:
explanation_html:
In order to continue its instruction, an instructor requested you to edit information to your file no. %{dossier_id} of the « %{libelle_demarche} » procedure.
sva_svr:
diff --git a/config/locales/views/dossier_mailer/notify_pending_correction/fr.yml b/config/locales/views/dossier_mailer/notify_pending_correction/fr.yml
index 8d8dcd161..3de37804e 100644
--- a/config/locales/views/dossier_mailer/notify_pending_correction/fr.yml
+++ b/config/locales/views/dossier_mailer/notify_pending_correction/fr.yml
@@ -3,7 +3,7 @@ fr:
dossier_mailer:
notify_pending_correction:
subject: Vous devez corriger votre dossier nº %{dossier_id} « %{libelle_demarche} »
- correction:
+ incorrect:
explanation_html:
Afin de poursuivre son instruction, un instructeur vous demande d’apporter des corrections à votre dossier nº %{dossier_id} de la démarche « %{libelle_demarche} ».
sva_svr:
diff --git a/db/migrate/20230712095037_add_reason_to_dossier_corrections.rb b/db/migrate/20230712095037_add_reason_to_dossier_corrections.rb
new file mode 100644
index 000000000..dcdab1f9d
--- /dev/null
+++ b/db/migrate/20230712095037_add_reason_to_dossier_corrections.rb
@@ -0,0 +1,5 @@
+class AddReasonToDossierCorrections < ActiveRecord::Migration[7.0]
+ def change
+ add_column :dossier_corrections, :reason, :string, default: 'incorrect', null: false
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 12983a65a..675a76a15 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema[7.0].define(version: 2023_07_18_113920) do
+ActiveRecord::Schema[7.0].define(version: 2023_07_19_112020) do
# These are extensions that must be enabled in order to support this database
enable_extension "pgcrypto"
enable_extension "plpgsql"
@@ -337,6 +337,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_07_18_113920) do
t.datetime "resolved_at", precision: 6
t.datetime "updated_at", precision: 6, null: false
t.string "kind", default: "correction", null: false
+ t.string "reason", default: "incorrect", null: false
t.index ["commentaire_id"], name: "index_dossier_corrections_on_commentaire_id"
t.index ["dossier_id"], name: "index_dossier_corrections_on_dossier_id"
t.index ["resolved_at"], name: "index_dossier_corrections_on_resolved_at", where: "((resolved_at IS NULL) OR (resolved_at IS NOT NULL))"
diff --git a/lib/tasks/deployment/20230712095348_backfill_dossier_correction_reason.rake b/lib/tasks/deployment/20230712095348_backfill_dossier_correction_reason.rake
new file mode 100644
index 000000000..9b74c041d
--- /dev/null
+++ b/lib/tasks/deployment/20230712095348_backfill_dossier_correction_reason.rake
@@ -0,0 +1,14 @@
+namespace :after_party do
+ desc 'Deployment task: backfill_default_dossier_correction_reason'
+ task backfill_dossier_correction_reason: :environment do
+ puts "Running deploy task 'backfill_default_dossier_correction_reason'"
+
+ DossierCorrection.where(kind: 'correction').update_all(reason: 'incorrect')
+ DossierCorrection.where(kind: 'incomplete').update_all(reason: 'incomplete')
+
+ # Update task as completed. If you remove the line below, the task will
+ # run with every deploy (or every time you call after_party:run).
+ AfterParty::TaskRecord
+ .create version: AfterParty::TaskRecorder.new(__FILE__).timestamp
+ end
+end
diff --git a/spec/controllers/api/v2/graphql_controller_spec.rb b/spec/controllers/api/v2/graphql_controller_spec.rb
index 1196834e5..1ffeedf5e 100644
--- a/spec/controllers/api/v2/graphql_controller_spec.rb
+++ b/spec/controllers/api/v2/graphql_controller_spec.rb
@@ -972,6 +972,23 @@ describe API::V2::GraphqlController do
end
end
+ context 'with correction' do
+ let(:input) { super().merge(correction: :incorrect) }
+
+ it 'should create a correction' do
+ expect(gql_data).to eq(dossierEnvoyerMessage: {
+ message: {
+ body: "Bonjour"
+ },
+ errors: nil
+ })
+
+ expect(dossier).to be_pending_correction
+ expect(dossier.pending_correction).to be_dossier_incorrect
+ expect(dossier.pending_correction.commentaire.body).to eq("Bonjour")
+ end
+ end
+
context 'schema error' do
let(:input) do
{
diff --git a/spec/controllers/instructeurs/dossiers_controller_spec.rb b/spec/controllers/instructeurs/dossiers_controller_spec.rb
index 7046069af..564574188 100644
--- a/spec/controllers/instructeurs/dossiers_controller_spec.rb
+++ b/spec/controllers/instructeurs/dossiers_controller_spec.rb
@@ -503,13 +503,13 @@ describe Instructeurs::DossiersController, type: :controller do
describe '#pending_correction' do
let(:message) { 'do that' }
let(:justificatif) { nil }
- let(:kind) { nil }
+ let(:reason) { nil }
subject do
post :pending_correction, params: {
procedure_id: procedure.id, dossier_id: dossier.id,
dossier: { motivation: message, justificatif_motivation: justificatif },
- kind:
+ reason:
}, format: :turbo_stream
end
@@ -535,7 +535,7 @@ describe Instructeurs::DossiersController, type: :controller do
expect(dossier.reload).to be_en_construction
expect(dossier).to be_pending_correction
- expect(dossier.corrections.last).to be_correction
+ expect(dossier.corrections.last).to be_dossier_incorrect
end
it 'create a comment with text body' do
@@ -544,10 +544,10 @@ describe Instructeurs::DossiersController, type: :controller do
end
context 'flagged as incomplete' do
- let(:kind) { 'incomplete' }
+ let(:reason) { 'incomplete' }
- it 'create a correction of incomplete kind' do
- expect(dossier.corrections.last).to be_incomplete
+ it 'create a correction of incomplete reason' do
+ expect(dossier.corrections.last).to be_dossier_incomplete
end
end
diff --git a/spec/factories/dossier_corrections.rb b/spec/factories/dossier_corrections.rb
index acad74696..147f02a1f 100644
--- a/spec/factories/dossier_corrections.rb
+++ b/spec/factories/dossier_corrections.rb
@@ -1,8 +1,8 @@
FactoryBot.define do
factory :dossier_correction do
dossier
- commentaire
- kind { :correction }
+ commentaire { association :commentaire, dossier: dossier }
+ reason { :incorrect }
resolved_at { nil }
trait :resolved do
diff --git a/spec/graphql/dossier_spec.rb b/spec/graphql/dossier_spec.rb
index 6e8e0f723..cd84b6210 100644
--- a/spec/graphql/dossier_spec.rb
+++ b/spec/graphql/dossier_spec.rb
@@ -241,6 +241,19 @@ RSpec.describe Types::DossierType, type: :graphql do
it {
expect(data[:dossier][:messages]).not_to be_nil
+ expect(data[:dossier][:messages][0][:correction]).to be_nil
+ }
+ end
+
+ describe 'dossier with pending correction' do
+ let(:dossier) { create(:dossier, :en_construction) }
+ let!(:correction) { create(:dossier_correction, dossier:) }
+ let(:query) { DOSSIER_WITH_CORRECTION_QUERY }
+ let(:variables) { { number: dossier.id } }
+
+ it {
+ expect(data[:dossier][:messages][0][:correction]).to eq({ reason: "incorrect", dateResolution: nil })
+ expect(data[:dossier][:dateDerniereCorrectionEnAttente]).not_to be_nil
}
end
@@ -412,6 +425,21 @@ RSpec.describe Types::DossierType, type: :graphql do
}
GRAPHQL
+ DOSSIER_WITH_CORRECTION_QUERY = <<-GRAPHQL
+ query($number: Int!) {
+ dossier(number: $number) {
+ dateDerniereCorrectionEnAttente
+ messages {
+ body
+ correction {
+ reason
+ dateResolution
+ }
+ }
+ }
+ }
+ GRAPHQL
+
DOSSIER_WITH_SELECTED_CHAMP_QUERY = <<-GRAPHQL
query($number: Int!, $id: ID!) {
dossier(number: $number) {
diff --git a/spec/mailers/dossier_mailer_spec.rb b/spec/mailers/dossier_mailer_spec.rb
index b69326f82..c800b2083 100644
--- a/spec/mailers/dossier_mailer_spec.rb
+++ b/spec/mailers/dossier_mailer_spec.rb
@@ -233,21 +233,21 @@ RSpec.describe DossierMailer, type: :mailer do
let(:procedure) { create(:procedure) }
let(:dossier) { create(:dossier, :en_construction, procedure:, sva_svr_decision_on:) }
let(:sva_svr_decision_on) { nil }
- let(:kind) { :correction }
+ let(:reason) { :incorrect }
let(:commentaire) { create(:commentaire, dossier:) }
subject {
- dossier.flag_as_pending_correction!(commentaire, kind)
+ dossier.flag_as_pending_correction!(commentaire, reason)
described_class.with(commentaire:).notify_pending_correction
}
- context 'kind is correction' do
+ context 'reason is incorrect' do
it { expect(subject.subject).to eq("Vous devez corriger votre dossier nº #{dossier.id} « #{dossier.procedure.libelle} »") }
it { expect(subject.body).to include("apporter des corrections") }
it { expect(subject.body).not_to include("Silence") }
end
- context 'sva with kind is correction' do
+ context 'sva with reason is incorrect' do
let(:sva_svr_decision_on) { Date.tomorrow }
let(:procedure) { create(:procedure, :sva) }
@@ -257,9 +257,9 @@ RSpec.describe DossierMailer, type: :mailer do
it { expect(subject.body).to include("suspendu") }
end
- context 'sva with kind is incomplete' do
+ context 'sva with reason is incomplete' do
let(:sva_svr_decision_on) { Date.tomorrow }
- let(:kind) { :incomplete }
+ let(:reason) { :incomplete }
let(:procedure) { create(:procedure, :sva) }
it { expect(subject.body).to include("compléter") }
@@ -267,9 +267,9 @@ RSpec.describe DossierMailer, type: :mailer do
it { expect(subject.body).to include("réinitialisé") }
end
- context 'svr with kind is incomplete' do
+ context 'svr with reason is incomplete' do
let(:sva_svr_decision_on) { Date.tomorrow }
- let(:kind) { :incomplete }
+ let(:reason) { :incomplete }
let(:procedure) { create(:procedure, :svr) }
it { expect(subject.body).to include("compléter") }
diff --git a/spec/models/concern/dossier_correctable_concern_spec.rb b/spec/models/concern/dossier_correctable_concern_spec.rb
index a18d58fc3..9cdee295b 100644
--- a/spec/models/concern/dossier_correctable_concern_spec.rb
+++ b/spec/models/concern/dossier_correctable_concern_spec.rb
@@ -36,12 +36,12 @@ describe DossierCorrectableConcern do
context 'when dossier is en_construction' do
it 'creates a correction' do
expect { flag }.to change { dossier.corrections.pending.count }.by(1)
- expect(dossier.corrections.last).to be_correction
+ expect(dossier.corrections.last).to be_dossier_incorrect
end
it 'created a correction of incomplete kind' do
expect { dossier.flag_as_pending_correction!(commentaire, "incomplete") }.to change { dossier.corrections.pending.count }.by(1)
- expect(dossier.corrections.last).to be_incomplete
+ expect(dossier.corrections.last).to be_dossier_incomplete
end
it 'does not change dossier state' do
diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb
index fc3780920..344603134 100644
--- a/spec/models/dossier_spec.rb
+++ b/spec/models/dossier_spec.rb
@@ -1072,30 +1072,38 @@ describe Dossier, type: :model 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:) }
+ let!(:correction) { create(:dossier_correction, dossier:) } # correction has a commentaire
- before { dossier.passer_en_instruction!(instructeur: instructeur) }
+ subject(:passer_en_instruction) { dossier.passer_en_instruction!(instructeur: instructeur) }
- it { expect(dossier.state).to eq('en_instruction') }
- it { expect(dossier.followers_instructeurs).to include(instructeur) }
- it { expect(dossier.en_construction_close_to_expiration_notice_sent_at).to be_nil }
- it { expect(last_operation.operation).to eq('passer_en_instruction') }
- it { expect(last_operation.automatic_operation?).to be_falsey }
- 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 { expect(dossier.commentaires.count).to eq(1) }
+ it do
+ passer_en_instruction
+
+ expect(dossier.state).to eq('en_instruction')
+ expect(dossier.followers_instructeurs).to include(instructeur)
+ expect(dossier.en_construction_close_to_expiration_notice_sent_at).to be_nil
+ expect(last_operation.operation).to eq('passer_en_instruction')
+ expect(last_operation.automatic_operation?).to be_falsey
+ expect(operation_serialized['operation']).to eq('passer_en_instruction')
+ expect(operation_serialized['dossier_id']).to eq(dossier.id)
+ expect(operation_serialized['executed_at']).to eq(last_operation.executed_at.iso8601)
+ end
+
+ it { expect { passer_en_instruction }.to change { dossier.commentaires.count }.by(1) }
it "resolve pending correction" do
+ passer_en_instruction
+
expect(dossier.pending_correction?).to be_falsey
expect(correction.reload.resolved_at).to be_present
end
it 'creates a commentaire in the messagerie with expected wording' do
- email_template = dossier.procedure.mail_template_for(Dossier.states.fetch(:en_instruction))
- commentaire = dossier.commentaires.first
+ passer_en_instruction
+
+ email_template = dossier.procedure.mail_template_for(Dossier.states.fetch(:en_instruction))
+ commentaire = dossier.commentaires.last
- expect(dossier.commentaires.count).to eq(1)
expect(commentaire.body).to include(email_template.subject_for_dossier(dossier), email_template.body_for_dossier(dossier))
expect(commentaire.dossier).to eq(dossier)
end
diff --git a/spec/services/sva_svr_decision_date_calculator_service_spec.rb b/spec/services/sva_svr_decision_date_calculator_service_spec.rb
index 23bae7ab7..e6ff87783 100644
--- a/spec/services/sva_svr_decision_date_calculator_service_spec.rb
+++ b/spec/services/sva_svr_decision_date_calculator_service_spec.rb
@@ -59,7 +59,7 @@ describe SVASVRDecisionDateCalculatorService do
end
end
- context 'there is a pending correction kind = correct' do
+ context 'there is a pending correction reason = incorrect' do
before do
travel_to DateTime.new(2023, 5, 30, 18) do
dossier.flag_as_pending_correction!(build(:commentaire, dossier:))
@@ -73,7 +73,7 @@ describe SVASVRDecisionDateCalculatorService do
end
end
- context 'there is a pending correction kind = incomplete' do
+ context 'there is a pending correction reason = incomplete' do
before do
travel_to DateTime.new(2023, 5, 30, 18) do
dossier.flag_as_pending_correction!(build(:commentaire, dossier:), :incomplete)