Skip to content

Commit

Permalink
feat(graphql): can flag pending correction with "dossier envoyer mess…
Browse files Browse the repository at this point in the history
…age"

Co-authored-by: Paul Chavard <github@paul.chavard.net>
  • Loading branch information
colinux and tchak committed Jul 13, 2023
1 parent 1c9b34f commit 358c797
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app/graphql/mutations/dossier_envoyer_message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
5 changes: 5 additions & 0 deletions app/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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!
}
Expand Down
17 changes: 17 additions & 0 deletions spec/controllers/api/v2/graphql_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit 358c797

Please sign in to comment.