feat(graphql): can flag pending correction with "dossier envoyer message"

Co-authored-by: Paul Chavard <github@paul.chavard.net>
This commit is contained in:
Colin Darie 2023-07-12 12:56:16 +02:00 committed by Paul Chavard
parent 873218222c
commit caf41a82e6
3 changed files with 28 additions and 1 deletions

View file

@ -6,14 +6,19 @@ module Mutations
argument :instructeur_id, ID, required: true, loads: Types::ProfileType argument :instructeur_id, ID, required: true, loads: Types::ProfileType
argument :body, String, required: true argument :body, String, required: true
argument :attachment, ID, required: false argument :attachment, ID, required: false
argument :correction, Types::CorrectionType::CorrectionReason, 'Préciser quil sagit dune demande de correction. Le dossier repasssera en construction.', required: false
field :message, Types::MessageType, null: true field :message, Types::MessageType, null: true
field :errors, [Types::ValidationErrorType], 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) message = CommentaireService.create(instructeur, dossier, body: body, piece_jointe: attachment)
if message.errors.empty? if message.errors.empty?
if correction
dossier.flag_as_pending_correction!(message, correction)
end
{ message: } { message: }
else else
{ errors: message.errors.full_messages } { errors: message.errors.full_messages }

View file

@ -1590,6 +1590,11 @@ input DossierEnvoyerMessageInput {
A unique identifier for the client performing the mutation. A unique identifier for the client performing the mutation.
""" """
clientMutationId: String clientMutationId: String
"""
Préciser quil sagit dune demande de correction. Le dossier repasssera en construction.
"""
correction: CorrectionReason
dossierId: ID! dossierId: ID!
instructeurId: ID! instructeurId: ID!
} }

View file

@ -972,6 +972,23 @@ describe API::V2::GraphqlController do
end end
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 context 'schema error' do
let(:input) do let(:input) do
{ {