From 9c8020b05ca8a8ada64a65a0ea00133574ff17ca Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Wed, 3 May 2023 15:08:21 +0200 Subject: [PATCH] feat(admin): add initiation procedure for a new admin --- .../concerns/initiation_procedure_concern.rb | 43 +++++++++++++++++++ app/models/procedure.rb | 1 + app/models/super_admin.rb | 1 + .../initiation_procedure_concern_spec.rb | 13 ++++++ 4 files changed, 58 insertions(+) create mode 100644 app/models/concerns/initiation_procedure_concern.rb create mode 100644 spec/models/concern/initiation_procedure_concern_spec.rb diff --git a/app/models/concerns/initiation_procedure_concern.rb b/app/models/concerns/initiation_procedure_concern.rb new file mode 100644 index 000000000..bfb693928 --- /dev/null +++ b/app/models/concerns/initiation_procedure_concern.rb @@ -0,0 +1,43 @@ +module InitiationProcedureConcern + extend ActiveSupport::Concern + + class_methods do + def create_initiation_procedure(administrateur) + p = Procedure.new( + libelle: 'Une première procédure', + description: "Une première procédure afin de découvrir les possibilités de #{APPLICATION_NAME}", + organisation: 'Dinum', + cadre_juridique: "inexistant car c'est un test", + duree_conservation_dossiers_dans_ds: 1, + for_individual: true, + administrateurs: [administrateur] + ) + + p.draft_revision = p.revisions.build + + p.save! + + p.draft_revision.add_type_de_champ({ type_champ: :text, libelle: 'nouveau champ' }) + p.defaut_groupe_instructeur.instructeurs << administrateur.instructeur + + service = Service.create( + nom: 'Un très bon service', + organisme: "d'un excellent organisme", + type_organisme: Service.type_organismes.fetch(:autre), + email: 'contactez@moi.fr', + telephone: '1234', + horaires: 'de 9 h à 18 h', + adresse: 'adresse', + siret: '35600082800018', + etablissement_infos: { adresse: "75 rue du Louvre\n75002\nPARIS\nFRANCE" }, + etablissement_lat: 48.87, + etablissement_lng: 2.34, + administrateur: + ) + + p.update(service:) + + p + end + end +end diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 019c0cd09..678773fe3 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -62,6 +62,7 @@ class Procedure < ApplicationRecord include ProcedureStatsConcern include EncryptableConcern + include InitiationProcedureConcern include Discard::Model self.discard_column = :hidden_at diff --git a/app/models/super_admin.rb b/app/models/super_admin.rb index 9fe9b4590..f1ff0f6ad 100644 --- a/app/models/super_admin.rb +++ b/app/models/super_admin.rb @@ -58,6 +58,7 @@ class SuperAdmin < ApplicationRecord if user.valid? user.invite_administrateur!(id) + Procedure.create_initiation_procedure(user.administrateur) end user diff --git a/spec/models/concern/initiation_procedure_concern_spec.rb b/spec/models/concern/initiation_procedure_concern_spec.rb new file mode 100644 index 000000000..f3303b90f --- /dev/null +++ b/spec/models/concern/initiation_procedure_concern_spec.rb @@ -0,0 +1,13 @@ +describe InitiationProcedureConcern do + describe '.create_initiation_procedure' do + let(:administrateur) { create(:administrateur) } + subject { Procedure.create_initiation_procedure(administrateur) } + + it "returns a new procedure" do + expect(subject).to be_valid + expect(subject.defaut_groupe_instructeur.instructeurs.count).to eq(1) + expect(subject.draft_revision.types_de_champ_public).not_to be_empty + expect(subject.service).not_to be_nil + end + end +end