From e63b777bd902fbddaf98c72e4fe239f105b08937 Mon Sep 17 00:00:00 2001 From: mfo Date: Wed, 24 Jul 2024 17:48:00 +0200 Subject: [PATCH] feat(api.dossier.modifier_annotation): stop validation only with graphql schema, also validate with our validations methods --- app/graphql/mutations/dossier_modifier_annotation.rb | 2 +- spec/controllers/api/v2/graphql_controller_spec.rb | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/graphql/mutations/dossier_modifier_annotation.rb b/app/graphql/mutations/dossier_modifier_annotation.rb index aca7fb396..3d3c140ba 100644 --- a/app/graphql/mutations/dossier_modifier_annotation.rb +++ b/app/graphql/mutations/dossier_modifier_annotation.rb @@ -20,7 +20,7 @@ module Mutations annotation.value = value end - if annotation.save + if annotation.validate(:champs_private_value) && annotation.save { annotation: } else { errors: annotation.errors.full_messages } diff --git a/spec/controllers/api/v2/graphql_controller_spec.rb b/spec/controllers/api/v2/graphql_controller_spec.rb index 4382eb52c..ec5275d8e 100644 --- a/spec/controllers/api/v2/graphql_controller_spec.rb +++ b/spec/controllers/api/v2/graphql_controller_spec.rb @@ -1476,6 +1476,17 @@ describe API::V2::GraphqlController do }) end end + context "failure" do + let(:value) { drop_down_list_options.first.reverse } + it 'should be a success' do + expect(gql_errors).to eq(nil) + + expect(gql_data).to eq(dossierModifierAnnotationDropDownList: { + annotation: nil, + errors: [{ message: "doit ĂȘtre dans les options proposĂ©es" }] + }) + end + end end describe 'integer_number' do