From 358c7975dbc609088d2d70c5085a786a2a873b76 Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Wed, 12 Jul 2023 12:56:16 +0200 Subject: [PATCH] feat(graphql): can flag pending correction with "dossier envoyer message" Co-authored-by: Paul Chavard --- .../mutations/dossier_envoyer_message.rb | 7 ++++++- app/graphql/schema.graphql | 5 +++++ .../api/v2/graphql_controller_spec.rb | 17 +++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/app/graphql/mutations/dossier_envoyer_message.rb b/app/graphql/mutations/dossier_envoyer_message.rb index b941afa1731..5f5c5f8c06c 100644 --- a/app/graphql/mutations/dossier_envoyer_message.rb +++ b/app/graphql/mutations/dossier_envoyer_message.rb @@ -6,14 +6,19 @@ class DossierEnvoyerMessage < Mutations::BaseMutation 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 d0b12a2fb69..773df9474a8 100644 --- a/app/graphql/schema.graphql +++ b/app/graphql/schema.graphql @@ -1590,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! } diff --git a/spec/controllers/api/v2/graphql_controller_spec.rb b/spec/controllers/api/v2/graphql_controller_spec.rb index 1196834e542..1ffeedf5eab 100644 --- a/spec/controllers/api/v2/graphql_controller_spec.rb +++ b/spec/controllers/api/v2/graphql_controller_spec.rb @@ -972,6 +972,23 @@ def format_type_champ(type_champ) 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 {