[GraphQL] Add archiver mutation
This commit is contained in:
parent
a911a71db9
commit
061a743759
4 changed files with 105 additions and 0 deletions
25
app/graphql/mutations/dossier_archiver.rb
Normal file
25
app/graphql/mutations/dossier_archiver.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
module Mutations
|
||||
class DossierArchiver < Mutations::BaseMutation
|
||||
description "Archiver le dossier."
|
||||
|
||||
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
|
||||
|
||||
field :dossier, Types::DossierType, null: true
|
||||
field :errors, [Types::ValidationErrorType], null: true
|
||||
|
||||
def resolve(dossier:, instructeur:)
|
||||
if dossier.termine?
|
||||
dossier.archiver!(instructeur)
|
||||
|
||||
{ dossier: dossier }
|
||||
else
|
||||
{ errors: ["Un dossier ne peut être archivé qu’une fois le traitement terminé"] }
|
||||
end
|
||||
end
|
||||
|
||||
def authorized?(dossier:, instructeur:)
|
||||
instructeur.is_a?(Instructeur) && instructeur.dossiers.exists?(id: dossier.id)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -457,6 +457,38 @@ type DossierAccepterPayload {
|
|||
errors: [ValidationError!]
|
||||
}
|
||||
|
||||
"""
|
||||
Autogenerated input type of DossierArchiver
|
||||
"""
|
||||
input DossierArchiverInput {
|
||||
"""
|
||||
A unique identifier for the client performing the mutation.
|
||||
"""
|
||||
clientMutationId: String
|
||||
|
||||
"""
|
||||
Dossier ID
|
||||
"""
|
||||
dossierId: ID!
|
||||
|
||||
"""
|
||||
Instructeur qui prend la décision sur le dossier.
|
||||
"""
|
||||
instructeurId: ID!
|
||||
}
|
||||
|
||||
"""
|
||||
Autogenerated return type of DossierArchiver
|
||||
"""
|
||||
type DossierArchiverPayload {
|
||||
"""
|
||||
A unique identifier for the client performing the mutation.
|
||||
"""
|
||||
clientMutationId: String
|
||||
dossier: Dossier
|
||||
errors: [ValidationError!]
|
||||
}
|
||||
|
||||
"""
|
||||
Autogenerated input type of DossierChangerGroupeInstructeur
|
||||
"""
|
||||
|
@ -925,6 +957,11 @@ type Mutation {
|
|||
"""
|
||||
dossierAccepter(input: DossierAccepterInput!): DossierAccepterPayload
|
||||
|
||||
"""
|
||||
Archiver le dossier.
|
||||
"""
|
||||
dossierArchiver(input: DossierArchiverInput!): DossierArchiverPayload
|
||||
|
||||
"""
|
||||
Changer le grope instructeur du dossier.
|
||||
"""
|
||||
|
|
|
@ -7,6 +7,7 @@ module Types
|
|||
field :dossier_classer_sans_suite, mutation: Mutations::DossierClasserSansSuite
|
||||
field :dossier_refuser, mutation: Mutations::DossierRefuser
|
||||
field :dossier_accepter, mutation: Mutations::DossierAccepter
|
||||
field :dossier_archiver, mutation: Mutations::DossierArchiver
|
||||
field :dossier_changer_groupe_instructeur, mutation: Mutations::DossierChangerGroupeInstructeur
|
||||
end
|
||||
end
|
||||
|
|
|
@ -885,6 +885,48 @@ describe API::V2::GraphqlController do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'dossierArchiver' do
|
||||
let(:query) do
|
||||
"mutation {
|
||||
dossierArchiver(input: {
|
||||
dossierId: \"#{dossier.to_typed_id}\",
|
||||
instructeurId: \"#{instructeur.to_typed_id}\"
|
||||
}) {
|
||||
dossier {
|
||||
archived
|
||||
}
|
||||
errors {
|
||||
message
|
||||
}
|
||||
}
|
||||
}"
|
||||
end
|
||||
|
||||
it "validation error" do
|
||||
expect(gql_errors).to eq(nil)
|
||||
|
||||
expect(gql_data).to eq(dossierArchiver: {
|
||||
dossier: nil,
|
||||
errors: [{ message: "Un dossier ne peut être archivé qu’une fois le traitement terminé" }]
|
||||
})
|
||||
end
|
||||
|
||||
context "should archive dossier" do
|
||||
let(:dossier) { create(:dossier, :sans_suite, :with_individual, procedure: procedure) }
|
||||
|
||||
it "change made" do
|
||||
expect(gql_errors).to eq(nil)
|
||||
|
||||
expect(gql_data).to eq(dossierArchiver: {
|
||||
dossier: {
|
||||
archived: true
|
||||
},
|
||||
errors: nil
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue