From 8c6feb1e1f732ed3028134c282b6b208089a8c5a Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Fri, 20 May 2022 19:01:54 +0200 Subject: [PATCH] feat(graphql): expose repasser_en_construction and repasser_en_instruction --- .../dossier_repasser_en_construction.rb | 27 ++++++ .../dossier_repasser_en_instruction.rb | 27 ++++++ app/graphql/schema.graphql | 94 +++++++++++++++++++ app/graphql/types/mutation_type.rb | 2 + .../api/v2/graphql_controller_spec.rb | 86 +++++++++++++++++ 5 files changed, 236 insertions(+) create mode 100644 app/graphql/mutations/dossier_repasser_en_construction.rb create mode 100644 app/graphql/mutations/dossier_repasser_en_instruction.rb diff --git a/app/graphql/mutations/dossier_repasser_en_construction.rb b/app/graphql/mutations/dossier_repasser_en_construction.rb new file mode 100644 index 000000000..194e44393 --- /dev/null +++ b/app/graphql/mutations/dossier_repasser_en_construction.rb @@ -0,0 +1,27 @@ +module Mutations + class DossierRepasserEnConstruction < Mutations::BaseMutation + include DossierHelper + + description "Re-passer le dossier en construction." + + argument :dossier_id, ID, "Dossier ID", required: true, loads: Types::DossierType + argument :instructeur_id, ID, "Instructeur qui prend la décision sur le dossier.", required: true, loads: Types::ProfileType + argument :disable_notification, Boolean, "Désactiver l’envoi de l’email de notification après l’opération", required: false, default_value: false + + field :dossier, Types::DossierType, null: true + field :errors, [Types::ValidationErrorType], null: true + + def resolve(dossier:, instructeur:, disable_notification:) + dossier.repasser_en_construction!(instructeur) + + { dossier: dossier } + end + + def authorized?(dossier:, instructeur:, **args) + if !dossier.en_instruction? + return false, { errors: ["Le dossier est déjà #{dossier_display_state(dossier, lower: true)}"] } + end + dossier_authorized_for?(dossier, instructeur) + end + end +end diff --git a/app/graphql/mutations/dossier_repasser_en_instruction.rb b/app/graphql/mutations/dossier_repasser_en_instruction.rb new file mode 100644 index 000000000..d71dde304 --- /dev/null +++ b/app/graphql/mutations/dossier_repasser_en_instruction.rb @@ -0,0 +1,27 @@ +module Mutations + class DossierRepasserEnInstruction < Mutations::BaseMutation + include DossierHelper + + description "Re-passer le dossier en instruction." + + argument :dossier_id, ID, "Dossier ID", required: true, loads: Types::DossierType + argument :instructeur_id, ID, "Instructeur qui prend la décision sur le dossier.", required: true, loads: Types::ProfileType + argument :disable_notification, Boolean, "Désactiver l’envoi de l’email de notification après l’opération", required: false, default_value: false + + field :dossier, Types::DossierType, null: true + field :errors, [Types::ValidationErrorType], null: true + + def resolve(dossier:, instructeur:, disable_notification:) + dossier.repasser_en_instruction!(instructeur: instructeur, disable_notification: disable_notification) + + { dossier: dossier } + end + + def authorized?(dossier:, instructeur:, **args) + if !dossier.termine? + return false, { errors: ["Le dossier est déjà #{dossier_display_state(dossier, lower: true)}"] } + end + dossier_authorized_for?(dossier, instructeur) + end + end +end diff --git a/app/graphql/schema.graphql b/app/graphql/schema.graphql index 89054c900..1439ec17b 100644 --- a/app/graphql/schema.graphql +++ b/app/graphql/schema.graphql @@ -1291,6 +1291,80 @@ type DossierRefuserPayload { errors: [ValidationError!] } +""" +Autogenerated input type of DossierRepasserEnConstruction +""" +input DossierRepasserEnConstructionInput { + """ + A unique identifier for the client performing the mutation. + """ + clientMutationId: String + + """ + Désactiver l’envoi de l’email de notification après l’opération + """ + disableNotification: Boolean = false + + """ + Dossier ID + """ + dossierId: ID! + + """ + Instructeur qui prend la décision sur le dossier. + """ + instructeurId: ID! +} + +""" +Autogenerated return type of DossierRepasserEnConstruction +""" +type DossierRepasserEnConstructionPayload { + """ + A unique identifier for the client performing the mutation. + """ + clientMutationId: String + dossier: Dossier + errors: [ValidationError!] +} + +""" +Autogenerated input type of DossierRepasserEnInstruction +""" +input DossierRepasserEnInstructionInput { + """ + A unique identifier for the client performing the mutation. + """ + clientMutationId: String + + """ + Désactiver l’envoi de l’email de notification après l’opération + """ + disableNotification: Boolean = false + + """ + Dossier ID + """ + dossierId: ID! + + """ + Instructeur qui prend la décision sur le dossier. + """ + instructeurId: ID! +} + +""" +Autogenerated return type of DossierRepasserEnInstruction +""" +type DossierRepasserEnInstructionPayload { + """ + A unique identifier for the client performing the mutation. + """ + clientMutationId: String + dossier: Dossier + errors: [ValidationError!] +} + enum DossierState { """ Accepté @@ -1654,6 +1728,26 @@ type Mutation { """ input: DossierRefuserInput! ): DossierRefuserPayload + + """ + Re-passer le dossier en construction. + """ + dossierRepasserEnConstruction( + """ + Parameters for DossierRepasserEnConstruction + """ + input: DossierRepasserEnConstructionInput! + ): DossierRepasserEnConstructionPayload + + """ + Re-passer le dossier en instruction. + """ + dossierRepasserEnInstruction( + """ + Parameters for DossierRepasserEnInstruction + """ + input: DossierRepasserEnInstructionInput! + ): DossierRepasserEnInstructionPayload } enum Order { diff --git a/app/graphql/types/mutation_type.rb b/app/graphql/types/mutation_type.rb index 9633fa891..3f6e2eaca 100644 --- a/app/graphql/types/mutation_type.rb +++ b/app/graphql/types/mutation_type.rb @@ -7,6 +7,8 @@ module Types field :dossier_classer_sans_suite, mutation: Mutations::DossierClasserSansSuite field :dossier_refuser, mutation: Mutations::DossierRefuser field :dossier_accepter, mutation: Mutations::DossierAccepter + field :dossier_repasser_en_instruction, mutation: Mutations::DossierRepasserEnInstruction + field :dossier_repasser_en_construction, mutation: Mutations::DossierRepasserEnConstruction field :dossier_archiver, mutation: Mutations::DossierArchiver field :dossier_changer_groupe_instructeur, mutation: Mutations::DossierChangerGroupeInstructeur diff --git a/spec/controllers/api/v2/graphql_controller_spec.rb b/spec/controllers/api/v2/graphql_controller_spec.rb index 79b8d0444..51589359b 100644 --- a/spec/controllers/api/v2/graphql_controller_spec.rb +++ b/spec/controllers/api/v2/graphql_controller_spec.rb @@ -1000,6 +1000,92 @@ describe API::V2::GraphqlController do end end + describe 'dossierRepasserEnInstruction' do + let(:dossiers) { [dossier2, dossier1, dossier] } + let(:dossier) { create(:dossier, :refuse, :with_individual, procedure: procedure) } + let(:instructeur_id) { instructeur.to_typed_id } + let(:disable_notification) { false } + let(:query) do + "mutation { + dossierRepasserEnInstruction(input: { + dossierId: \"#{dossier.to_typed_id}\", + instructeurId: \"#{instructeur_id}\", + disableNotification: #{disable_notification} + }) { + dossier { + id + state + motivation + } + errors { + message + } + } + }" + end + + context 'success' do + it "should repasser en instruction dossier" do + expect(gql_errors).to eq(nil) + + expect(gql_data).to eq(dossierRepasserEnInstruction: { + dossier: { + id: dossier.to_typed_id, + state: "en_instruction", + motivation: nil + }, + errors: nil + }) + + perform_enqueued_jobs + expect(ActionMailer::Base.deliveries.size).to eq(4) + end + end + end + + describe 'dossierRepasserEnConstruction' do + let(:dossiers) { [dossier2, dossier1, dossier] } + let(:dossier) { create(:dossier, :en_instruction, :with_individual, procedure: procedure) } + let(:instructeur_id) { instructeur.to_typed_id } + let(:disable_notification) { false } + let(:query) do + "mutation { + dossierRepasserEnConstruction(input: { + dossierId: \"#{dossier.to_typed_id}\", + instructeurId: \"#{instructeur_id}\", + disableNotification: #{disable_notification} + }) { + dossier { + id + state + motivation + } + errors { + message + } + } + }" + end + + context 'success' do + it "should passer en instruction dossier" do + expect(gql_errors).to eq(nil) + + expect(gql_data).to eq(dossierRepasserEnConstruction: { + dossier: { + id: dossier.to_typed_id, + state: "en_construction", + motivation: nil + }, + errors: nil + }) + + perform_enqueued_jobs + expect(ActionMailer::Base.deliveries.size).to eq(3) + end + end + end + describe 'dossierClasserSansSuite' do let(:dossier) { create(:dossier, :en_instruction, :with_individual, procedure: procedure) } let(:query) do