diff --git a/app/graphql/api/v2/stored_query.rb b/app/graphql/api/v2/stored_query.rb index 1c48a5bd1..b246cc22b 100644 --- a/app/graphql/api/v2/stored_query.rb +++ b/app/graphql/api/v2/stored_query.rb @@ -894,6 +894,20 @@ class API::V2::StoredQuery } } + mutation dossierModifierAnnotationDropDownList( + $input: DossierModifierAnnotationDropDownListInput! + ) { + dossierModifierAnnotationDropDownList(input: $input) { + annotation { + id + value: stringValue + } + errors { + message + } + } + } + mutation dossierModifierAnnotationIntegerNumber( $input: DossierModifierAnnotationIntegerNumberInput! ) { diff --git a/app/graphql/mutations/dossier_modifier_annotation.rb b/app/graphql/mutations/dossier_modifier_annotation.rb index de467fa00..aca7fb396 100644 --- a/app/graphql/mutations/dossier_modifier_annotation.rb +++ b/app/graphql/mutations/dossier_modifier_annotation.rb @@ -65,6 +65,8 @@ module Mutations TypeDeChamp.type_champs.fetch(:datetime) when :integer_number TypeDeChamp.type_champs.fetch(:integer_number) + when :drop_down_list + TypeDeChamp.type_champs.fetch(:drop_down_list) end end end diff --git a/app/graphql/mutations/dossier_modifier_annotation_drop_down_list.rb b/app/graphql/mutations/dossier_modifier_annotation_drop_down_list.rb new file mode 100644 index 000000000..5136242c7 --- /dev/null +++ b/app/graphql/mutations/dossier_modifier_annotation_drop_down_list.rb @@ -0,0 +1,17 @@ +module Mutations + class DossierModifierAnnotationDropDownList < Mutations::DossierModifierAnnotation + description "Modifier l’annotation d'un champs de type dropdown list." + + argument :value, GraphQL::Types::String, required: true + + def resolve(dossier:, annotation_id:, instructeur:, value:) + resolve_with_type(dossier:, annotation_id:, instructeur:, value:) + end + + private + + def input_type + :drop_down_list + end + end +end diff --git a/app/graphql/schema.graphql b/app/graphql/schema.graphql index c422408fe..1ae80f784 100644 --- a/app/graphql/schema.graphql +++ b/app/graphql/schema.graphql @@ -1937,6 +1937,45 @@ type DossierModifierAnnotationDatetimePayload { errors: [ValidationError!] } +""" +Autogenerated input type of DossierModifierAnnotationDropDownList +""" +input DossierModifierAnnotationDropDownListInput { + """ + Annotation ID + """ + annotationId: ID! + + """ + A unique identifier for the client performing the mutation. + """ + clientMutationId: String + + """ + Dossier ID + """ + dossierId: ID! + + """ + Instructeur qui demande la modification. + """ + instructeurId: ID! + value: String! +} + +""" +Autogenerated return type of DossierModifierAnnotationDropDownList. +""" +type DossierModifierAnnotationDropDownListPayload { + annotation: Champ + + """ + A unique identifier for the client performing the mutation. + """ + clientMutationId: String + errors: [ValidationError!] +} + """ Autogenerated input type of DossierModifierAnnotationIntegerNumber """ @@ -3278,6 +3317,16 @@ type Mutation { input: DossierModifierAnnotationDatetimeInput! ): DossierModifierAnnotationDatetimePayload + """ + Modifier l’annotation d'un champs de type dropdown list. + """ + dossierModifierAnnotationDropDownList( + """ + Parameters for DossierModifierAnnotationDropDownList + """ + input: DossierModifierAnnotationDropDownListInput! + ): DossierModifierAnnotationDropDownListPayload + """ Modifier l’annotation au format nombre entier. """ diff --git a/app/graphql/types/mutation_type.rb b/app/graphql/types/mutation_type.rb index b9ad5a92c..286cbeac3 100644 --- a/app/graphql/types/mutation_type.rb +++ b/app/graphql/types/mutation_type.rb @@ -19,6 +19,7 @@ module Types field :dossier_modifier_annotation_datetime, mutation: Mutations::DossierModifierAnnotationDatetime field :dossier_modifier_annotation_integer_number, mutation: Mutations::DossierModifierAnnotationIntegerNumber field :dossier_modifier_annotation_ajouter_ligne, mutation: Mutations::DossierModifierAnnotationAjouterLigne + field :dossier_modifier_annotation_drop_down_list, mutation: Mutations::DossierModifierAnnotationDropDownList field :groupe_instructeur_modifier, mutation: Mutations::GroupeInstructeurModifier field :groupe_instructeur_creer, mutation: Mutations::GroupeInstructeurCreer diff --git a/spec/controllers/api/v2/graphql_controller_spec.rb b/spec/controllers/api/v2/graphql_controller_spec.rb index f54c63190..4382eb52c 100644 --- a/spec/controllers/api/v2/graphql_controller_spec.rb +++ b/spec/controllers/api/v2/graphql_controller_spec.rb @@ -1230,9 +1230,13 @@ describe API::V2::GraphqlController do end describe 'dossierModifierAnnotation' do - let(:procedure) { create(:procedure, :published, :for_individual, :with_service, :with_all_annotations, administrateurs: [admin]) } + let(:procedure) do + create(:procedure, :published, :for_individual, :with_service, administrateurs: [admin], types_de_champ_private:) + end describe 'text' do + let(:types_de_champ_private) { [{ type: :text }] } + let(:query) do "mutation { dossierModifierAnnotationText(input: { @@ -1266,6 +1270,8 @@ describe API::V2::GraphqlController do end describe 'checkbox' do + let(:types_de_champ_private) { [{ type: :checkbox }] } + let(:value) { 'true' } let(:query) do @@ -1316,6 +1322,7 @@ describe API::V2::GraphqlController do end describe 'yes_no' do + let(:types_de_champ_private) { [{ type: :yes_no }] } let(:value) { 'true' } let(:query) do @@ -1366,6 +1373,8 @@ describe API::V2::GraphqlController do end describe 'date' do + let(:types_de_champ_private) { [{ type: :date }] } + let(:query) do "mutation { dossierModifierAnnotationDate(input: { @@ -1399,6 +1408,8 @@ describe API::V2::GraphqlController do end describe 'datetime' do + let(:types_de_champ_private) { [{ type: :datetime }] } + let(:query) do "mutation { dossierModifierAnnotationDatetime(input: { @@ -1431,7 +1442,44 @@ describe API::V2::GraphqlController do end end + describe 'drop_down_list' do + let(:drop_down_list_options) { ['bijour'] } + let(:types_de_champ_private) { [{ type: :drop_down_list, options: drop_down_list_options }] } + let(:query) do + "mutation { + dossierModifierAnnotationDropDownList(input: { + dossierId: \"#{dossier.to_typed_id}\", + annotationId: \"#{dossier.champs_private.find { |c| c.type_champ == 'drop_down_list' }.to_typed_id}\", + instructeurId: \"#{instructeur.to_typed_id}\", + value: \"#{value}\" + }) { + annotation { + stringValue + } + errors { + message + } + } + }" + end + + context "success" do + let(:value) { drop_down_list_options.first } + it 'should be a success' do + expect(gql_errors).to eq(nil) + + expect(gql_data).to eq(dossierModifierAnnotationDropDownList: { + annotation: { + stringValue: dossier.reload.champs_private.find { |c| c.type_champ == 'drop_down_list' }.to_s + }, + errors: nil + }) + end + end + end + describe 'integer_number' do + let(:types_de_champ_private) { [{ type: :integer_number }] } let(:query) do "mutation { dossierModifierAnnotationIntegerNumber(input: {