Skip to content

Commit

Permalink
chore(patron): build real demarche and dossier for page patron
Browse files Browse the repository at this point in the history
  • Loading branch information
tchak committed Apr 23, 2024
1 parent 6c70a3d commit ea42dec
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 60 deletions.
100 changes: 40 additions & 60 deletions app/controllers/root_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class RootController < ApplicationController
before_action :authenticate_administrateur!, only: :patron
include ApplicationHelper

def index
Expand All @@ -25,72 +26,51 @@ def administration
def patron
description = "Allez voir le super site : #{Current.application_base_url}"

all_champs = TypeDeChamp.type_champs
.map.with_index { |(name, _), i| TypeDeChamp.new(type_champ: name, private: false, libelle: name.humanize, description:, mandatory: true, stable_id: i) }
.map.with_index { |type_de_champ, i| type_de_champ.champ.build(id: i) }
procedure = Procedure.create_with(for_individual: true,

Check warning on line 29 in app/controllers/root_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/root_controller.rb#L29

Added line #L29 was not covered by tests
administrateurs: [current_administrateur],
duree_conservation_dossiers_dans_ds: 1,
max_duree_conservation_dossiers_dans_ds: Expired::DEFAULT_DOSSIER_RENTENTION_IN_MONTH,
cadre_juridique: 'http://www.legifrance.gouv.fr',
description:).find_or_initialize_by(libelle: 'Démarche de demo pour la page patron')

all_champs
.filter { |champ| champ.type_champ == TypeDeChamp.type_champs.fetch(:header_section) }
.each { |champ| champ.type_de_champ.libelle = 'Un super titre de section' }
if procedure.new_record?
Procedure.transaction do
procedure.draft_revision = procedure.revisions.build
procedure.save!
after_stable_id = nil
TypeDeChamp.type_champs.values.sort.each do |type_champ|
type_de_champ = procedure.draft_revision

Check warning on line 42 in app/controllers/root_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/root_controller.rb#L38-L42

Added lines #L38 - L42 were not covered by tests
.add_type_de_champ(type_champ:, libelle: type_champ.humanize, description:, mandatory: true, private: false, after_stable_id:)
after_stable_id = type_de_champ.stable_id

Check warning on line 44 in app/controllers/root_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/root_controller.rb#L44

Added line #L44 was not covered by tests

all_champs
.filter { |champ| champ.type_de_champ.drop_down_list? }
.each do |champ|
if champ.type_de_champ.linked_drop_down_list?
champ.type_de_champ.drop_down_list_value =
"-- section 1 --
option A
option B
-- section 2 --
option C"
else
champ.type_de_champ.drop_down_list_value =
"option A
option B
-- avant l'option C --
option C"
champ.value = '["option B", "option C"]'
champ.type_de_champ.drop_down_other = "1"
if type_de_champ.repetition?

Check warning on line 46 in app/controllers/root_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/root_controller.rb#L46

Added line #L46 was not covered by tests
repetition_after_stable_id = nil
['text', 'integer_number', 'checkbox'].each do |type_champ|
repetition_type_de_champ = procedure.draft_revision

Check warning on line 49 in app/controllers/root_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/root_controller.rb#L48-L49

Added lines #L48 - L49 were not covered by tests
.add_type_de_champ(type_champ:, libelle: type_champ.humanize, description:, mandatory: true, private: false, parent_stable_id: type_de_champ.stable_id, after_stable_id: repetition_after_stable_id)
repetition_after_stable_id = repetition_type_de_champ.stable_id

Check warning on line 51 in app/controllers/root_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/root_controller.rb#L51

Added line #L51 was not covered by tests
end
elsif type_de_champ.linked_drop_down_list?
type_de_champ.drop_down_list_value =
"-- section 1 --
option A
option B
-- section 2 --
option C"
type_de_champ.save

Check warning on line 60 in app/controllers/root_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/root_controller.rb#L60

Added line #L60 was not covered by tests
elsif type_de_champ.drop_down_list?
type_de_champ.drop_down_list_value =
"option A
option B
-- avant l'option C --
option C"
type_de_champ.save

Check warning on line 67 in app/controllers/root_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/root_controller.rb#L67

Added line #L67 was not covered by tests
end
end
end

all_champs
.filter { |champ| champ.type_champ == TypeDeChamp.type_champs.fetch(:repetition) }
.each do |champ_repetition|
libelles = ['Prénom', 'Nom'];
champ_repetition.champs << libelles.map.with_index do |libelle, i|
text_tdc = TypeDeChamp.new(type_champ: :text, private: false, libelle: libelle, description: description, mandatory: true)
text_tdc.champ.build(id: all_champs.length + i)
end
end

type_champ_values = {
TypeDeChamp.type_champs.fetch(:date) => '2016-07-26',
TypeDeChamp.type_champs.fetch(:datetime) => '26/07/2016 07:35',
TypeDeChamp.type_champs.fetch(:textarea) => 'Une description de mon projet'
}

type_champ_values.each do |(type_champ, value)|
all_champs
.filter { |champ| champ.type_champ == type_champ }
.each { |champ| champ.value = value }
end

@dossier = Dossier.new(champs: all_champs)
@dossier.association(:procedure).target = Procedure.new
all_champs.each do |champ|
champ.association(:dossier).target = @dossier
champ.champs.each do |champ|
champ.association(:dossier).target = @dossier
end
end

draft_revision = @dossier.procedure.build_draft_revision(types_de_champ: all_champs.map(&:type_de_champ))
@dossier.association(:revision).target = draft_revision
@dossier.champs_public.map(&:type_de_champ).map do |tdc|
tdc.association(:revision_type_de_champ).target = tdc.build_revision_type_de_champ(revision: draft_revision)
tdc.association(:revision).target = draft_revision
end
@dossier = procedure.draft_revision.dossier_for_preview(current_user)

Check warning on line 73 in app/controllers/root_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/root_controller.rb#L73

Added line #L73 was not covered by tests
end

def suivi
Expand Down
3 changes: 3 additions & 0 deletions spec/system/patron_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
describe 'Accessing the /patron page:' do
let(:administrateur) { create(:administrateur) }
before { sign_in administrateur.user }

scenario 'I can display a page with all form fields and UI elements' do
visit patron_path
expect(page).to have_text('Icônes')
Expand Down

0 comments on commit ea42dec

Please sign in to comment.