refactor(spec): stop using procedure type de champs traits as :with_datetime, :with_xxx in favor of :types_de_champ_public which keeps position in check

This commit is contained in:
Martin 2024-01-23 09:52:20 +01:00
parent 15e0ed8480
commit 2952987ad8
35 changed files with 167 additions and 293 deletions

View file

@ -264,12 +264,11 @@ class ProcedureRevision < ApplicationRecord
end
def next_position_for(siblings:, after_coordinate: nil)
if siblings.to_a.empty? # first element of the list, starts at 0
# either we are at the beginning of the list or after another item
if after_coordinate.nil? # first element of the list, starts at 0
0
elsif after_coordinate # middle of the list, between two items
else # after another item
after_coordinate.position + 1
else # last element of the list, end with last position + 1
siblings.to_a.last.position + 1
end
end

View file

@ -1,7 +1,7 @@
describe TypesDeChampEditor::ChampComponent, type: :component do
describe 'render by type' do
context 'explication' do
let(:procedure) { create(:procedure, :with_explication) }
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :explication }]) }
let(:tdc) { procedure.active_revision.types_de_champ_public.first }
let(:coordinate) { procedure.draft_revision.coordinate_for(tdc) }
let(:component) { described_class.new(coordinate: coordinate, upper_coordinates: []) }

View file

@ -185,7 +185,7 @@ describe Administrateurs::AttestationTemplatesController, type: :controller do
end
context 'when procedure is published' do
let(:procedure) { create(:procedure, :with_type_de_champ, types_de_champ_count: 3, administrateur: admin, attestation_template: attestation_template) }
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :text }, { type: :text }, { type: :text }], administrateur: admin, attestation_template: attestation_template) }
let(:dossier) {}
let(:attestation_template) { build(:attestation_template, title: 'a') }
let(:attestation_params) do
@ -208,11 +208,12 @@ describe Administrateurs::AttestationTemplatesController, type: :controller do
procedure.publish!
procedure.reload
procedure.draft_revision.remove_type_de_champ(removed_and_published_type_de_champ.stable_id)
procedure.draft_revision.add_type_de_champ(libelle: 'new type de champ', type_champ: 'text')
procedure.draft_revision.add_type_de_champ(libelle: 'new type de champ', type_champ: 'text', after_stable_id: procedure.draft_revision.types_de_champ_public.last.stable_id)
procedure.publish_revision!
procedure.reload
procedure.draft_revision.remove_type_de_champ(removed_type_de_champ.stable_id)
procedure.draft_revision.add_type_de_champ(libelle: 'draft type de champ', type_champ: 'text')
procedure.draft_revision.reload
procedure.draft_revision.add_type_de_champ(libelle: 'draft type de champ', type_champ: 'text', after_stable_id: procedure.draft_revision.types_de_champ_public.last.stable_id)
dossier

View file

@ -1,11 +1,14 @@
describe Administrateurs::TypesDeChampController, type: :controller do
let(:procedure) do
create(:procedure).tap do |p|
p.draft_revision.add_type_de_champ(type_champ: :integer_number, libelle: 'l1')
p.draft_revision.add_type_de_champ(type_champ: :integer_number, libelle: 'l2')
p.draft_revision.add_type_de_champ(type_champ: :drop_down_list, libelle: 'l3')
p.draft_revision.add_type_de_champ(type_champ: :yes_no, libelle: 'bon dossier', private: true)
end
create(:procedure,
types_de_champ_public: [
{ type: :integer_number, libelle: 'l1' },
{ type: :integer_number, libelle: 'l2' },
{ type: :drop_down_list, libelle: 'l3' }
],
types_de_champ_private: [
{ type: :yes_no, libelle: 'bon dossier', private: true }
])
end
def first_coordinate = procedure.draft_revision.revision_types_de_champ_public.first

View file

@ -269,7 +269,7 @@ describe API::V1::DossiersController do
end
describe 'departement' do
let(:procedure) { create(:procedure, :with_departement, administrateur: admin) }
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :departements }], administrateur: admin) }
let(:dossier) { create(:dossier, :en_construction, :with_populated_champs, procedure: procedure) }
subject { super() }
@ -281,7 +281,7 @@ describe API::V1::DossiersController do
end
describe 'repetition' do
let(:procedure) { create(:procedure, :with_repetition, administrateur: admin) }
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :repetition, children: [{ type: :text }, { type: :integer_number }] }], administrateur: admin) }
let(:dossier) { create(:dossier, :en_construction, :with_populated_champs, procedure: procedure) }
subject { super().first[:rows] }

View file

@ -1,6 +1,6 @@
describe Champs::PieceJustificativeController, type: :controller do
let(:user) { create(:user) }
let(:procedure) { create(:procedure, :published, :with_piece_justificative) }
let(:procedure) { create(:procedure, :published, types_de_champ_public: [{ type: :piece_justificative }]) }
let(:dossier) { create(:dossier, user: user, procedure: procedure) }
let(:champ) { dossier.champs_public.first }

View file

@ -1,6 +1,6 @@
describe Champs::RNAController, type: :controller do
let(:user) { create(:user) }
let(:procedure) { create(:procedure, :published, :with_rna) }
let(:procedure) { create(:procedure, :published, types_de_champ_public: [{ type: :rna }]) }
describe '#show' do
let(:dossier) { create(:dossier, user: user, procedure: procedure) }

View file

@ -1,6 +1,6 @@
describe Champs::SiretController, type: :controller do
let(:user) { create(:user) }
let(:procedure) { create(:procedure, :published, :with_siret) }
let(:procedure) { create(:procedure, :published, types_de_champ_public: [{ type: :siret }]) }
describe '#show' do
let(:dossier) { create(:dossier, user: user, procedure: procedure) }

View file

@ -915,7 +915,7 @@ describe Instructeurs::DossiersController, type: :controller do
it { expect(response).to render_template 'dossiers/show' }
context 'empty champs commune' do
let(:procedure) { create(:procedure, :published, :with_commune, instructeurs:) }
let(:procedure) { create(:procedure, :published, types_de_champ_public: [{ type: :communes }], instructeurs:) }
let(:dossier) { create(:dossier, :accepte, procedure:) }
it { expect(response).to render_template 'dossiers/show' }

View file

@ -40,7 +40,7 @@ describe Manager::ProceduresController, type: :controller do
describe '#show' do
render_views
let(:procedure) { create(:procedure, :published, :with_repetition) }
let(:procedure) { create(:procedure, :published, types_de_champ_public: [{ type: :repetition, children: [{ type: :text, libelle: 'sub type de champ' }] }]) }
before do
get :show, params: { id: procedure.id }

View file

@ -1,12 +1,9 @@
describe RechercheController, type: :controller do
let(:procedure) {
create(:procedure,
:published,
create(:procedure, :published,
:for_individual,
:with_type_de_champ,
:with_type_de_champ_private,
types_de_champ_count: 2,
types_de_champ_private_count: 2)
types_de_champ_public: [{ type: :text }, { type: :text }],
types_de_champ_private: [{ type: :text }, { type: :text }])
}
let(:dossier) { create(:dossier, :en_construction, :with_individual, procedure: procedure) }
let(:instructeur) { create(:instructeur) }

View file

@ -90,10 +90,7 @@ FactoryBot.define do
published
for_individual { true }
after(:build) do |procedure, _evaluator|
build(:type_de_champ, libelle: 'Texte obligatoire', mandatory: true, procedure: procedure)
end
types_de_champ_public { [{ type: :text, libelle: 'Texte obligatoire', mandatory: true }] }
end
trait :with_bulk_message do
@ -144,164 +141,11 @@ FactoryBot.define do
end
trait :with_type_de_champ do
transient do
types_de_champ_count { 1 }
end
after(:build) do |procedure, evaluator|
evaluator.types_de_champ_count.times do |position|
build(:type_de_champ, procedure: procedure, position: position)
end
end
types_de_champ_public { [{ type: :text }] }
end
trait :with_type_de_champ_private do
transient do
types_de_champ_private_count { 1 }
end
after(:build) do |procedure, evaluator|
evaluator.types_de_champ_private_count.times do |position|
build(:type_de_champ, :private, procedure: procedure, position: position)
end
end
end
trait :with_type_de_champ_mandatory do
after(:build) do |procedure, _evaluator|
build(:type_de_champ, mandatory: true, procedure: procedure)
end
end
trait :with_datetime do
after(:build) do |procedure, _evaluator|
build(:type_de_champ_datetime, mandatory: true, procedure: procedure)
end
end
trait :with_dossier_link do
after(:build) do |procedure, _evaluator|
build(:type_de_champ_dossier_link, procedure: procedure)
end
end
trait :with_siret do
after(:build) do |procedure, _evaluator|
build(:type_de_champ_siret, procedure: procedure)
end
end
trait :with_yes_no do
after(:build) do |procedure, _evaluator|
build(:type_de_champ_yes_no, procedure: procedure)
end
end
trait :with_commune do
after(:build) do |procedure, _evaluator|
build(:type_de_champ_communes, procedure: procedure)
end
end
trait :with_departement do
after(:build) do |procedure, _evaluator|
build(:type_de_champ_departements, procedure: procedure)
end
end
trait :with_region do
after(:build) do |procedure, _evaluator|
build(:type_de_champ_regions, procedure: procedure)
end
end
trait :with_piece_justificative do
after(:build) do |procedure, _evaluator|
build(:type_de_champ_piece_justificative, procedure: procedure)
end
end
trait :with_titre_identite do
after(:build) do |procedure, _evaluator|
build(:type_de_champ_titre_identite, procedure: procedure)
end
end
trait :with_repetition do
after(:build) do |procedure, _evaluator|
build(:type_de_champ_repetition, :with_types_de_champ, procedure: procedure)
end
end
trait :with_private_repetition do
after(:build) do |procedure, _evaluator|
build(:type_de_champ_repetition, :private, procedure: procedure)
end
end
trait :with_number do
after(:build) do |procedure, _evaluator|
build(:type_de_champ_number, procedure: procedure)
end
end
trait :with_phone do
after(:build) do |procedure, _evaluator|
build(:type_de_champ_phone, procedure: procedure)
end
end
trait :with_drop_down_list do
after(:build) do |procedure, _evaluator|
build(:type_de_champ_drop_down_list, :with_other, procedure: procedure)
end
end
trait :with_address do
after(:build) do |procedure, _evaluator|
build(:type_de_champ_address, procedure: procedure)
end
end
trait :with_cnaf do
after(:build) do |procedure, _evaluator|
build(:type_de_champ_cnaf, procedure: procedure)
end
end
trait :with_rna do
after(:build) do |procedure, _evaluator|
build(:type_de_champ_rna, procedure: procedure)
end
end
trait :with_dgfip do
after(:build) do |procedure, _evaluator|
build(:type_de_champ_dgfip, procedure: procedure)
end
end
trait :with_pole_emploi do
after(:build) do |procedure, _evaluator|
build(:type_de_champ_pole_emploi, procedure: procedure)
end
end
trait :with_mesri do
after(:build) do |procedure, _evaluator|
build(:type_de_champ_mesri, procedure: procedure)
end
end
trait :with_explication do
after(:build) do |procedure, _evaluator|
build(:type_de_champ_explication, procedure: procedure)
end
end
trait :with_carte do
after(:build) do |procedure, _evaluator|
build(:type_de_champ_carte, procedure: procedure)
end
types_de_champ_private { [{ type: :text }] }
end
trait :draft do
@ -398,6 +242,7 @@ FactoryBot.define do
end
end
# TODO: rewrite with types_de_champ_private
trait :with_all_annotations do
after(:build) do |procedure, _evaluator|
TypeDeChamp.type_champs.map.with_index do |(libelle, type_champ), index|

View file

@ -218,6 +218,7 @@ FactoryBot.define do
revision.save
end
# TODO: drop
trait :with_types_de_champ do
after(:build) do |type_de_champ_repetition, evaluator|
revision = evaluator.procedure.active_revision

View file

@ -34,7 +34,7 @@ RSpec.describe ProcedureHelper, type: :helper do
subject { estimated_fill_duration_minutes(procedure.reload) }
context 'with champs' do
let(:procedure) { create(:procedure, :with_yes_no, :with_piece_justificative) }
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :yes_no }, { type: :piece_justificative }]) }
it 'rounds up the duration to the minute' do
expect(subject).to eq(2)

View file

@ -1,6 +1,6 @@
describe DataFixer::DossierChampsMissing do
describe '#fix' do
let(:procedure) { create(:procedure, :with_datetime, :with_dossier_link) }
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :datetime }, { type: :dossier_link }]) }
let(:dossier) { create(:dossier, procedure:) }
context 'when dossier does not have a fork' do
@ -34,7 +34,7 @@ describe DataFixer::DossierChampsMissing do
end
context 'when dossier have missing champ on repetition' do
let(:procedure) { create(:procedure, :with_repetition) }
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :repetition, children: [{ type: :text }, { type: :decimal_number }] }]) }
let(:dossier) { create(:dossier, :with_populated_champs, procedure:) }
let(:champ_repetition) { dossier.champs_public.first }
let(:initial_champ_count) { dossier.champs.count }

View file

@ -573,11 +573,7 @@ describe DossierRebaseConcern do
context 'with a procedure with 2 tdc' do
let!(:procedure) do
create(:procedure).tap do |p|
p.draft_revision.add_type_de_champ(type_champ: :text, libelle: 'l1')
p.draft_revision.add_type_de_champ(type_champ: :text, libelle: 'l2')
p.publish!
end
create(:procedure, :published, types_de_champ_public: [{ type: :text, libelle: 'l1' }, { type: :text, libelle: 'l2' }])
end
let!(:dossier) { create(:dossier, procedure: procedure) }
@ -656,25 +652,34 @@ describe DossierRebaseConcern do
context 'with a procedure with a repetition' do
let!(:procedure) do
create(:procedure).tap do |p|
repetition = p.draft_revision.add_type_de_champ(type_champ: :repetition, libelle: 'p1', mandatory: true)
p.draft_revision.add_type_de_champ(type_champ: :text, libelle: 'c1', parent_stable_id: repetition.stable_id)
p.draft_revision.add_type_de_champ(type_champ: :text, libelle: 'c2', parent_stable_id: repetition.stable_id)
p.publish!
end
create(:procedure, :published, types_de_champ_public: [
{
type: :repetition,
libelle: 'p1',
mandatory: true,
children: [
{ type: :text, libelle: 'c1' },
{ type: :text, libelle: 'c2' }
]
}
])
end
let!(:dossier) { create(:dossier, procedure: procedure) }
let(:repetition_stable_id) { procedure.draft_revision.types_de_champ.find(&:repetition?) }
let(:repetition) { procedure.draft_revision.types_de_champ.find(&:repetition?) }
def child_libelles = dossier.champs_public.first.champs.map(&:libelle)
context 'when a child tdc is added in the middle' do
before do
added_tdc = procedure.draft_revision.add_type_de_champ(type_champ: :text, libelle: 'c3', parent_stable_id: repetition_stable_id)
last_child = procedure.draft_revision.children_of(repetition).last
added_tdc = procedure.draft_revision.add_type_de_champ(type_champ: :text, libelle: 'c3', parent_stable_id: repetition.stable_id, after_stable_id: last_child)
procedure.draft_revision.move_type_de_champ(added_tdc.stable_id, 1)
# procedure.publish_revision!
end
it { expect { subject }.to change { child_libelles }.from(['c1', 'c2']).to(['c1', 'c3', 'c2']) }
it 'does somehting' do
expect { subject }.to change { child_libelles }.from(['c1', 'c2']).to(['c1', 'c3', 'c2'])
end
end
context 'when the first child tdc is removed' do

View file

@ -1979,7 +1979,7 @@ describe Dossier, type: :model do
end
context "when procedure brouillon" do
let(:procedure) { create(:procedure, :with_type_de_champ, :with_explication) }
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :text }, { type: :explication }]) }
it "should not contain non-exportable types de champ" do
expect(dossier_champs_for_export.map { |(libelle)| libelle }).to eq([text_type_de_champ.libelle])

View file

@ -262,7 +262,6 @@ describe Instructeur, type: :model do
let(:seen_at_instructeur2) { now - 1.hour }
before do
gi_p1.instructeurs << instructeur
instructeur_2.followed_dossiers << dossier
Timecop.freeze(now)
end

View file

@ -132,20 +132,36 @@ RSpec.describe PrefillDescription, type: :model do
end
describe '#prefill_query' do
let(:procedure) { create(:procedure) }
let(:type_de_champ_text) { create(:type_de_champ_text, procedure: procedure) }
let(:type_de_champ_epci) { TypesDeChamp::PrefillTypeDeChamp.build(create(:type_de_champ_epci, procedure: procedure), procedure.active_revision) }
let(:type_de_champ_repetition) { build(:type_de_champ_repetition, :with_types_de_champ, :with_region_types_de_champ, procedure: procedure) }
let(:procedure) do
create(:procedure, types_de_champ_public: [
{ type: :text },
{ type: :epci },
{
type: :repetition, children: [
{ type: :text },
{ type: :integer_number },
{ type: :regions }
]
}
])
end
let(:type_de_champ_text) { procedure.active_revision.types_de_champ_public.find { |type_de_champ| type_de_champ.type_champ == TypeDeChamp.type_champs.fetch(:text) } }
let(:type_de_champ_epci) { procedure.active_revision.types_de_champ_public.find { |type_de_champ| type_de_champ.type_champ == TypeDeChamp.type_champs.fetch(:epci) } }
let(:type_de_champ_repetition) { procedure.active_revision.types_de_champ_public.find { |type_de_champ| type_de_champ.type_champ == TypeDeChamp.type_champs.fetch(:repetition) } }
let(:prefill_type_de_champ_epci) { TypesDeChamp::PrefillTypeDeChamp.build(type_de_champ_epci, procedure.active_revision) }
let(:prefillable_subchamps) { TypesDeChamp::PrefillRepetitionTypeDeChamp.new(type_de_champ_repetition, procedure.active_revision).send(:prefillable_subchamps) }
let(:text_repetition) { prefillable_subchamps.first }
let(:integer_repetition) { prefillable_subchamps.second }
let(:region_repetition) { prefillable_subchamps.third }
let(:prefill_description) { described_class.new(procedure) }
let(:expected_query) do
<<~TEXT
curl --request POST '#{api_public_v1_dossiers_url(procedure)}' \\
--header 'Content-Type: application/json' \\
--data '{"identite_prenom":"#{I18n.t("views.prefill_descriptions.edit.examples.prenom")}","champ_#{type_de_champ_text.to_typed_id_for_query}":"Texte court","champ_#{type_de_champ_epci.to_typed_id_for_query}":["01","200042935"],"champ_#{type_de_champ_repetition.to_typed_id_for_query}":[{"champ_#{text_repetition.to_typed_id_for_query}":"Texte court","champ_#{integer_repetition.to_typed_id_for_query}":"42","champ_#{region_repetition.to_typed_id_for_query}":"53"},{"champ_#{text_repetition.to_typed_id_for_query}":"Texte court","champ_#{integer_repetition.to_typed_id_for_query}":"42","champ_#{region_repetition.to_typed_id_for_query}":"53"}]}'
--data '{"identite_prenom":"#{I18n.t("views.prefill_descriptions.edit.examples.prenom")}","champ_#{type_de_champ_text.to_typed_id_for_query}":"Texte court","champ_#{prefill_type_de_champ_epci.to_typed_id_for_query}":["01","200042935"],"champ_#{type_de_champ_repetition.to_typed_id_for_query}":[{"champ_#{text_repetition.to_typed_id_for_query}":"Texte court","champ_#{integer_repetition.to_typed_id_for_query}":"42","champ_#{region_repetition.to_typed_id_for_query}":"53"},{"champ_#{text_repetition.to_typed_id_for_query}":"Texte court","champ_#{integer_repetition.to_typed_id_for_query}":"42","champ_#{region_repetition.to_typed_id_for_query}":"53"}]}'
TEXT
end

View file

@ -3,30 +3,25 @@ describe ProcedurePresentation do
subject { procedure.types_de_champ_for_procedure_presentation.not_repetition.pluck(:libelle) }
context 'for a draft procedure' do
let(:procedure) { create(:procedure) }
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :number, libelle: 'libelle 1' }]) }
context 'when there are one tdc on a draft revision' do
let!(:tdc) { { type_champ: :number, libelle: 'libelle 1' } }
before { procedure.draft_revision.add_type_de_champ(tdc) }
it { is_expected.to match(['libelle 1']) }
end
end
context 'for a published procedure' do
let(:procedure) { create(:procedure, :published) }
let(:tdc) { { type_champ: :number, libelle: 'libelle 1' } }
let(:procedure) { create(:procedure, :published, types_de_champ_public: []) }
let!(:tdc) { procedure.draft_revision.add_type_de_champ({ type_champ: :number, libelle: 'libelle 1' }) }
before do
procedure.draft_revision.add_type_de_champ(tdc)
procedure.publish_revision!
end
it { is_expected.to match(['libelle 1']) }
context 'when there is another published revision with an added tdc' do
let(:added_tdc) { { type_champ: :number, libelle: 'libelle 2' } }
let(:added_tdc) { { type_champ: :number, libelle: 'libelle 2', after_stable_id: tdc.stable_id } }
before do
procedure.draft_revision.add_type_de_champ(added_tdc)

View file

@ -53,7 +53,11 @@ describe ProcedurePresentation do
describe "#fields" do
context 'when the procedure can have a SIRET number' do
let(:procedure) { create(:procedure, :with_type_de_champ, :with_type_de_champ_private, types_de_champ_count: 4, types_de_champ_private_count: 4) }
let(:procedure) do
create(:procedure,
types_de_champ_public: Array.new(4) { { type: :text } },
types_de_champ_private: Array.new(4) { { type: :text } })
end
let(:tdc_1) { procedure.active_revision.types_de_champ_public[0] }
let(:tdc_2) { procedure.active_revision.types_de_champ_public[1] }
let(:tdc_private_1) { procedure.active_revision.types_de_champ_private[0] }
@ -866,7 +870,7 @@ describe ProcedurePresentation do
end
context 'when type_de_champ yes_no' do
let(:procedure) { create(:procedure, :with_yes_no) }
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :yes_no }]) }
it 'should transform value' do
expect(subject).to eq("oui")
@ -894,7 +898,7 @@ describe ProcedurePresentation do
let(:filters) { { "suivis" => [] } }
context 'when type_de_champ yes_no' do
let(:procedure) { create(:procedure, :with_yes_no) }
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :yes_no }]) }
it 'should downcase and transform value' do
procedure_presentation.add_filter("suivis", "type_de_champ/#{first_type_de_champ_id}", "Oui")

View file

@ -11,20 +11,27 @@ describe ProcedureRevision do
describe '#add_type_de_champ' do
# tdc: public: text, repetition ; private: text ; +1 text child of repetition
let(:procedure) do
create(:procedure).tap do |p|
p.draft_revision.add_type_de_champ(type_champ: :text, libelle: 'l1')
parent = p.draft_revision.add_type_de_champ(type_champ: :repetition, libelle: 'l2')
p.draft_revision.add_type_de_champ(type_champ: :text, libelle: 'l2', parent_stable_id: parent.stable_id)
p.draft_revision.add_type_de_champ(type_champ: :text, libelle: 'l1 private', private: true)
create(:procedure,
types_de_champ_public: [
{ type: :text, libelle: 'l1' },
{
type: :repetition, libelle: 'l2', children: [
{ type: :text, libelle: 'l2' }
]
}
],
types_de_champ_private: [
{ type: :text, libelle: 'l1 private' }
])
end
end
let(:text_params) { { type_champ: :text, libelle: 'text' } }
let(:tdc_params) { text_params }
let(:last_coordinate) { draft.revision_types_de_champ.last }
subject { draft.add_type_de_champ(tdc_params) }
context 'with a text tdc' do
let(:text_params) { { type_champ: :text, libelle: 'text', after_stable_id: procedure.draft_revision.types_de_champ_public.last.stable_id } }
it 'public' do
expect { subject }.to change { draft.types_de_champ_public.size }.from(2).to(3)
expect(draft.types_de_champ_public.last).to eq(subject)
@ -36,6 +43,7 @@ describe ProcedureRevision do
end
context 'with a private tdc' do
let(:text_params) { { type_champ: :text, libelle: 'text', after_stable_id: procedure.draft_revision.types_de_champ_private.last.id } }
let(:tdc_params) { text_params.merge(private: true) }
it 'private' do
@ -47,6 +55,7 @@ describe ProcedureRevision do
end
context 'with a repetition child' do
let(:text_params) { { type_champ: :text, libelle: 'text', after_stable_id: procedure.draft_revision.children_of(type_de_champ_repetition).last.stable_id } }
let(:tdc_params) { text_params.merge(parent_stable_id: type_de_champ_repetition.stable_id) }
it do
@ -62,12 +71,14 @@ describe ProcedureRevision do
end
context 'when a libelle is missing' do
let(:text_params) { { type_champ: :text, libelle: 'text', after_stable_id: procedure.draft_revision.types_de_champ_private.last.id } }
let(:tdc_params) { text_params.except(:libelle) }
it { expect(subject.errors.full_messages).to eq(["Le champ « Libelle » doit être rempli"]) }
end
context 'when a parent is incorrect' do
let(:text_params) { { type_champ: :text, libelle: 'text', after_stable_id: procedure.draft_revision.types_de_champ_private.last.id } }
let(:tdc_params) { text_params.merge(parent_id: 123456789) }
it { expect(subject.errors.full_messages).not_to be_empty }
@ -75,6 +86,7 @@ describe ProcedureRevision do
context 'after_stable_id' do
context 'with a valid after_stable_id' do
let(:text_params) { { type_champ: :text, libelle: 'text', after_stable_id: procedure.draft_revision.types_de_champ_private.last.id } }
let(:tdc_params) { text_params.merge(after_stable_id: draft.revision_types_de_champ_public.first.stable_id, libelle: 'in the middle') }
it do
@ -86,18 +98,19 @@ describe ProcedureRevision do
end
context 'with blank valid after_stable_id' do
let(:text_params) { { type_champ: :text, libelle: 'text', after_stable_id: procedure.draft_revision.types_de_champ_private.last.id } }
let(:tdc_params) { text_params.merge(after_stable_id: '', libelle: 'in the middle') }
it do
subject
expect(draft.revision_types_de_champ_public.reload.map(&:libelle)).to eq(['l1', 'l2', 'in the middle'])
expect(draft.revision_types_de_champ_public.reload.map(&:libelle)).to eq(['in the middle', 'l1', 'l2'])
end
end
end
end
describe '#move_type_de_champ' do
let(:procedure) { create(:procedure, :with_type_de_champ, types_de_champ_count: 4) }
let(:procedure) { create(:procedure, types_de_champ_public: Array.new(4) { { type: :text } }) }
let(:last_type_de_champ) { draft.types_de_champ_public.last }
context 'with 4 types de champ publiques' do
@ -122,13 +135,14 @@ describe ProcedureRevision do
end
context 'with a champ repetition repetition' do
let(:procedure) { create(:procedure, :with_repetition) }
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :repetition, children: [{ type: :text }, { type: :integer_number }] }]) }
let!(:second_child) do
draft.add_type_de_champ({
type_champ: TypeDeChamp.type_champs.fetch(:text),
libelle: "second child",
parent_stable_id: type_de_champ_repetition.stable_id
parent_stable_id: type_de_champ_repetition.stable_id,
after_stable_id: draft.reload.children_of(type_de_champ_repetition).last.stable_id
})
end
@ -136,7 +150,8 @@ describe ProcedureRevision do
draft.add_type_de_champ({
type_champ: TypeDeChamp.type_champs.fetch(:text),
libelle: "last child",
parent_stable_id: type_de_champ_repetition.stable_id
parent_stable_id: type_de_champ_repetition.stable_id,
after_stable_id: draft.reload.children_of(type_de_champ_repetition).last.stable_id
})
end
@ -177,7 +192,7 @@ describe ProcedureRevision do
context 'with multiple tdc' do
context 'in public tdc' do
let(:procedure) { create(:procedure, :with_type_de_champ, types_de_champ_count: 3) }
let(:procedure) { create(:procedure, types_de_champ_public: Array.new(3) { { type: :text } }) }
it 'reorders' do
expect(draft.revision_types_de_champ_public.pluck(:position)).to eq([0, 1, 2])
@ -193,7 +208,7 @@ describe ProcedureRevision do
end
context 'in repetition tdc' do
let(:procedure) { create(:procedure, :with_repetition) }
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :repetition, children: [{ type: :text }, { type: :integer_number }] }]) }
let!(:second_child) do
draft.add_type_de_champ({
type_champ: TypeDeChamp.type_champs.fetch(:text),
@ -224,7 +239,7 @@ describe ProcedureRevision do
end
context 'for a type_de_champ_repetition' do
let(:procedure) { create(:procedure, :with_repetition) }
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :repetition, children: [{ type: :text }, { type: :integer_number }] }]) }
let!(:child) { child = draft.children_of(type_de_champ_repetition).first }
it 'can remove its children' do
@ -295,7 +310,7 @@ describe ProcedureRevision do
end
context 'with repetition_type_de_champ' do
let(:procedure) { create(:procedure, :with_repetition) }
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :repetition, children: [{ type: :text }, { type: :integer_number }] }]) }
it 'should have the same tdcs with different links' do
expect(new_draft.types_de_champ.count).to eq(3)
@ -312,7 +327,7 @@ describe ProcedureRevision do
end
describe '#update_type_de_champ' do
let(:procedure) { create(:procedure, :with_repetition) }
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :repetition, children: [{ type: :text }, { type: :integer_number }] }]) }
let(:last_coordinate) { draft.revision_types_de_champ.last }
let(:last_type_de_champ) { last_coordinate.type_de_champ }
@ -343,10 +358,10 @@ describe ProcedureRevision do
context 'with a procedure with 2 tdcs' do
let(:procedure) do
create(:procedure).tap do |p|
p.draft_revision.add_type_de_champ(type_champ: :integer_number, libelle: 'l1')
p.draft_revision.add_type_de_champ(type_champ: :text, libelle: 'l2')
end
create(:procedure, types_de_champ_public: [
{ type: :integer_number, libelle: 'l1' },
{ type: :text, libelle: 'l2' }
])
end
context 'when a condition is added' do
@ -487,7 +502,7 @@ describe ProcedureRevision do
end
context 'when collapsible_explanation_enabled and collapsible_explanation_text are changed' do
let(:procedure) { create(:procedure, :with_explication) }
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :explication }]) }
before do
updated_tdc = new_draft.find_and_ensure_exclusive_use(first_tdc.stable_id)
@ -520,7 +535,7 @@ describe ProcedureRevision do
end
context 'when a type de champ is moved' do
let(:procedure) { create(:procedure, :with_type_de_champ, types_de_champ_count: 3) }
let(:procedure) { create(:procedure, types_de_champ_public: Array.new(3) { { type: :text } }) }
let(:new_draft_second_tdc) { new_draft.types_de_champ_public.second }
let(:new_draft_third_tdc) { new_draft.types_de_champ_public.third }
@ -572,7 +587,7 @@ describe ProcedureRevision do
end
context 'when a child type de champ is transformed into a drop_down_list' do
let(:procedure) { create(:procedure, :with_repetition) }
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :repetition, children: [{ type: :text, libelle: 'sub type de champ' }, { type: :integer_number }] }]) }
before do
child = new_draft.children_of(new_draft.types_de_champ_public.last).first
@ -604,7 +619,7 @@ describe ProcedureRevision do
end
context 'when a child type de champ is transformed into a map' do
let(:procedure) { create(:procedure, :with_repetition) }
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :repetition, children: [{ type: :text, libelle: 'sub type de champ' }, { type: :integer_number }] }]) }
before do
child = new_draft.children_of(new_draft.types_de_champ_public.last).first
@ -644,7 +659,7 @@ describe ProcedureRevision do
end
context 'with a repetition tdc' do
let(:procedure) { create(:procedure, :with_repetition) }
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :repetition, children: [{ type: :text }, { type: :integer_number }] }]) }
let!(:parent) { draft.types_de_champ.find(&:repetition?) }
let!(:first_child) { draft.types_de_champ.reject(&:repetition?).first }
let!(:second_child) { draft.types_de_champ.reject(&:repetition?).second }
@ -988,9 +1003,12 @@ describe ProcedureRevision do
def second_champ = procedure.draft_revision.types_de_champ_public.second
let(:procedure) do
create(:procedure).tap do |p|
tdc = p.draft_revision.add_type_de_champ(type_champ: :integer_number, libelle: 'l1')
p.draft_revision.add_type_de_champ(type_champ: :integer_number, libelle: 'l2', condition: ds_eq(champ_value(tdc.stable_id), constant(true)))
create(:procedure, types_de_champ_public: [{ type: :integer_number, libelle: 'l1' }]).tap do |p|
tdc = p.draft_revision.revision_types_de_champ_public.last
p.draft_revision.add_type_de_champ(type_champ: :integer_number,
libelle: 'l2',
condition: ds_eq(champ_value(tdc.stable_id), constant(true)),
after_stable_id: tdc.stable_id)
end
end
@ -1017,14 +1035,14 @@ describe ProcedureRevision do
describe '#routable_types_de_champ' do
let(:procedure) do
create(:procedure).tap do |p|
p.draft_revision.add_type_de_champ(type_champ: :text, libelle: 'l1')
p.draft_revision.add_type_de_champ(type_champ: :drop_down_list, libelle: 'l2')
p.draft_revision.add_type_de_champ(type_champ: :departements, libelle: 'l3')
p.draft_revision.add_type_de_champ(type_champ: :regions, libelle: 'l4')
p.draft_revision.add_type_de_champ(type_champ: :communes, libelle: 'l5')
p.draft_revision.add_type_de_champ(type_champ: :epci, libelle: 'l6')
end
create(:procedure, types_de_champ_public: [
{ type: :text, libelle: 'l1' },
{ type: :drop_down_list, libelle: 'l2' },
{ type: :departements, libelle: 'l3' },
{ type: :regions, libelle: 'l4' },
{ type: :communes, libelle: 'l5' },
{ type: :epci, libelle: 'l6' }
])
end
it { expect(draft.routable_types_de_champ.pluck(:libelle)).to eq(['l2', 'l3', 'l4', 'l5', 'l6']) }

View file

@ -325,7 +325,7 @@ describe Procedure do
let(:drop_down) { build(:type_de_champ_drop_down_list, :without_selectable_values, libelle: 'Civilité') }
let(:invalid_drop_down_error_message) { 'Le champ « Civilité » doit comporter au moins un choix sélectionnable' }
let(:procedure) { create(:procedure, :with_repetition) }
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :repetition, children: [{ type: :text }, { type: :integer_number }] }]) }
let(:draft) { procedure.draft_revision }
before do

View file

@ -103,7 +103,7 @@ RSpec.describe TypesDeChamp::PrefillTypeDeChamp, type: :model do
end
describe 'too many possible values or not' do
let!(:procedure) { create(:procedure, :with_drop_down_list) }
let!(:procedure) { create(:procedure, types_de_champ_public: [{ type: :drop_down_list }]) }
let(:type_de_champ) { procedure.draft_types_de_champ_public.first }
let(:link_to_all_possible_values) {
link_to(

View file

@ -199,7 +199,7 @@ describe DossierProjectionService do
context 'for type_de_champ table and value to.s' do
let(:table) { 'type_de_champ' }
let(:procedure) { create(:procedure, :with_yes_no) }
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :yes_no }]) }
let(:dossier) { create(:dossier, procedure: procedure) }
let(:column) { dossier.procedure.active_revision.types_de_champ_public.first.stable_id.to_s }
@ -210,7 +210,7 @@ describe DossierProjectionService do
context 'for type_de_champ table and value to.s which needs data field' do
let(:table) { 'type_de_champ' }
let(:procedure) { create(:procedure, :with_address) }
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :address }]) }
let(:dossier) { create(:dossier, procedure: procedure) }
let(:column) { dossier.procedure.active_revision.types_de_champ_public.first.stable_id.to_s }

View file

@ -11,7 +11,7 @@ describe PiecesJustificativesService do
end
context 'with a pj champ' do
let(:procedure) { create(:procedure, :with_piece_justificative) }
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :piece_justificative }]) }
let(:dossier) { create(:dossier, procedure: procedure) }
let(:witness) { create(:dossier, procedure: procedure) }
@ -37,7 +37,7 @@ describe PiecesJustificativesService do
end
context 'with a pj not safe on a champ' do
let(:procedure) { create(:procedure, :with_piece_justificative) }
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :piece_justificative }]) }
let(:dossier) { create(:dossier, procedure: procedure) }
let(:pj_champ) { -> (d) { d.champs_public.find { |c| c.type == 'Champs::PieceJustificativeChamp' } } }
@ -113,7 +113,7 @@ describe PiecesJustificativesService do
end
context 'with a identite champ pj' do
let(:procedure) { create(:procedure, :with_titre_identite) }
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :titre_identite }]) }
let(:dossier) { create(:dossier, procedure: procedure) }
let(:witness) { create(:dossier, procedure: procedure) }

View file

@ -133,7 +133,7 @@ describe 'wcag rules for usager', js: true do
end
context "logged in, depot d'un dossier entreprise" do
let(:procedure) { create(:procedure, :with_type_de_champ, :with_all_champs, :with_service, :published) }
let(:procedure) { create(:procedure, :with_all_champs, :with_service, :published) }
before do
login_as litteraire_user, scope: :user

View file

@ -3,13 +3,11 @@ describe 'As an administrateur I can edit types de champ condition', js: true do
let(:administrateur) { procedure.administrateurs.first }
let(:procedure) do
create(:procedure).tap do |p|
p.draft_revision.add_type_de_champ(type_champ: :integer_number, libelle: 'age')
# private
p.draft_revision.add_type_de_champ(type_champ: :boolean, libelle: 'bon dossier', private: true)
p.draft_revision.add_type_de_champ(type_champ: :text, libelle: 'nom du parent')
end
create(:procedure,
types_de_champ_public: [
{ type: :integer_number, libelle: 'age' },
{ type: :text, libelle: 'nom du parent' }
])
end
let(:first_tdc) { procedure.draft_revision.types_de_champ.first }

View file

@ -5,7 +5,7 @@ describe 'Inviting an expert:' do
context 'as an invited Expert' do
let(:expert) { create(:expert) }
let(:instructeur) { create(:instructeur) }
let(:procedure) { create(:procedure, :published, :with_piece_justificative, instructeurs: [instructeur]) }
let(:procedure) { create(:procedure, :published, types_de_champ_public: [{ type: :piece_justificative }], instructeurs: [instructeur]) }
let(:experts_procedure) { create(:experts_procedure, expert: expert, procedure: procedure) }
let(:dossier) { create(:dossier, :en_construction, :with_dossier_link, procedure: procedure) }
let(:champ) { dossier.champs_public.first }

View file

@ -198,7 +198,7 @@ describe 'Instructing a dossier:', js: true do
end
context 'A instructeur can ask for an Archive' do
let(:procedure) { create(:procedure, :published, :with_piece_justificative, instructeurs: [instructeur]) }
let(:procedure) { create(:procedure, :published, types_de_champ_public: [{ type: :piece_justificative }], instructeurs: [instructeur]) }
let(:dossier) { create(:dossier, :accepte, procedure: procedure) }
before do
log_in(instructeur.email, password)
@ -212,7 +212,7 @@ describe 'Instructing a dossier:', js: true do
end
end
context 'with dossiers having attached files', js: true do
let(:procedure) { create(:procedure, :published, :with_piece_justificative, instructeurs: [instructeur]) }
let(:procedure) { create(:procedure, :published, types_de_champ_public: [{ type: :piece_justificative }], instructeurs: [instructeur]) }
let(:dossier) { create(:dossier, :en_construction, procedure: procedure) }
let(:champ) { dossier.champs_public.first }
let(:path) { 'spec/fixtures/files/piece_justificative_0.pdf' }

View file

@ -1,6 +1,6 @@
describe "procedure filters" do
let(:instructeur) { create(:instructeur) }
let(:procedure) { create(:procedure, :published, :with_type_de_champ, :with_departement, :with_region, :with_drop_down_list, instructeurs: [instructeur]) }
let(:procedure) { create(:procedure, :published, types_de_champ_public: [{ type: :text }, { type: :departements }, { type: :regions }, { type: :drop_down_list }], instructeurs: [instructeur]) }
let!(:type_de_champ) { procedure.active_revision.types_de_champ_public.first }
let!(:new_unfollow_dossier) { create(:dossier, procedure: procedure, state: Dossier.states.fetch(:en_instruction)) }
let!(:champ) { Champ.find_by(type_de_champ_id: type_de_champ.id, dossier_id: new_unfollow_dossier.id) }

View file

@ -2,17 +2,10 @@ describe 'The routing with rules', js: true do
let(:password) { 'a very complicated password' }
let(:procedure) do
create(:procedure, :with_service, :for_individual, :with_zone).tap do |p|
p.draft_revision.add_type_de_champ(
type_champ: :text,
libelle: 'un premier champ text'
)
p.draft_revision.add_type_de_champ(
type_champ: :drop_down_list,
libelle: 'Spécialité',
options: { "drop_down_other" => "0", "drop_down_options" => ["", "littéraire", "scientifique", "artistique"] }
)
end
create(:procedure, :with_service, :for_individual, :with_zone, types_de_champ_public: [
{ type: :text, libelle: 'un premier champ text' },
{ type: :drop_down_list, libelle: 'Spécialité', options: ["", "littéraire", "scientifique", "artistique"] }
])
end
let(:administrateur) { create(:administrateur, procedures: [procedure]) }
let(:scientifique_user) { create(:user, password: password) }

View file

@ -1,6 +1,6 @@
describe "Dossier en_construction" do
let(:user) { create(:user) }
let(:procedure) { create(:simple_procedure, :with_piece_justificative, :with_titre_identite) }
let(:procedure) { create(:procedure, :for_individual, types_de_champ_public: [{ type: :piece_justificative }, { type: :titre_identite }]) }
let(:dossier) { create(:dossier, :en_construction, :with_individual, :with_populated_champs, user:, procedure:) }
let(:tdc) {

View file

@ -1,5 +1,5 @@
describe 'dossiers/dossier_vide', type: :view do
let(:procedure) { create(:procedure, :with_all_champs, :with_drop_down_list) }
let(:procedure) { create(:procedure, :with_all_champs) }
let(:dossier) { create(:dossier, procedure: procedure) }
before do

View file

@ -60,7 +60,7 @@ describe 'shared/_procedure_description', type: :view do
end
context 'when the procedure has pieces jointes' do
let(:procedure) { create(:procedure, :draft, :with_titre_identite, :with_piece_justificative, :with_siret) }
let(:procedure) { create(:procedure, :draft, types_de_champ_public: [{ type: :titre_identite }, { type: :piece_justificative }, { type: :siret }]) }
it 'shows the pieces jointes list for draft procedure' do
subject
expect(rendered).to have_text('Quelles sont les pièces justificatives à fournir')