2024-04-29 00:17:15 +02:00
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2018-01-23 17:15:42 +01:00
|
|
|
|
FactoryBot.define do
|
2015-08-13 15:55:19 +02:00
|
|
|
|
factory :dossier do
|
2018-09-04 16:46:48 +02:00
|
|
|
|
autorisation_donnees { true }
|
|
|
|
|
state { Dossier.states.fetch(:brouillon) }
|
2021-11-19 13:48:52 +01:00
|
|
|
|
|
|
|
|
|
user { association :user }
|
2022-11-04 10:10:57 +01:00
|
|
|
|
groupe_instructeur { procedure.routing_enabled? ? nil : procedure.defaut_groupe_instructeur }
|
2021-11-19 16:42:54 +01:00
|
|
|
|
revision { procedure.active_revision }
|
|
|
|
|
individual { association(:individual, :empty, dossier: instance, strategy: :build) if procedure.for_individual? }
|
2016-02-04 14:08:35 +01:00
|
|
|
|
|
2019-08-26 15:27:43 +02:00
|
|
|
|
transient do
|
2021-11-19 13:48:52 +01:00
|
|
|
|
for_individual? { false }
|
|
|
|
|
# For now a dossier must use a `create`d procedure, even if the dossier is only built (and not created).
|
|
|
|
|
# This is because saving the dossier fails when the procedure has not been saved beforehand
|
|
|
|
|
# (due to some internal ActiveRecord error).
|
|
|
|
|
# TODO: find a way to find the issue and just `build` the procedure.
|
|
|
|
|
procedure { create(:procedure, :published, :with_type_de_champ, :with_type_de_champ_private, for_individual: for_individual?) }
|
2019-08-26 15:27:43 +02:00
|
|
|
|
end
|
|
|
|
|
|
2015-08-13 15:55:19 +02:00
|
|
|
|
trait :with_entreprise do
|
2022-09-21 15:05:11 +02:00
|
|
|
|
transient do
|
|
|
|
|
as_degraded_mode { false }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
after(:build) do |dossier, evaluator|
|
2020-01-07 17:50:49 +01:00
|
|
|
|
if dossier.procedure.for_individual?
|
|
|
|
|
raise 'Inconsistent factory: attempting to create a dossier :with_entreprise on a procedure that is `for_individual?`'
|
|
|
|
|
end
|
2022-09-21 15:05:11 +02:00
|
|
|
|
|
|
|
|
|
etablissement = if evaluator.as_degraded_mode
|
|
|
|
|
Etablissement.new(siret: build(:etablissement).siret)
|
|
|
|
|
else
|
|
|
|
|
create(:etablissement, :with_exercices, :with_effectif_mensuel)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
dossier.update(etablissement:)
|
2015-08-13 15:55:19 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
2015-09-21 17:59:03 +02:00
|
|
|
|
|
2018-06-19 16:23:43 +02:00
|
|
|
|
trait :with_service do
|
2019-04-11 12:23:40 +02:00
|
|
|
|
after(:create) do |dossier, _evaluator|
|
2018-06-19 16:23:43 +02:00
|
|
|
|
dossier.procedure.service = create(:service)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2023-11-23 10:35:31 +01:00
|
|
|
|
trait :for_tiers_with_notification do
|
|
|
|
|
for_tiers { true }
|
|
|
|
|
mandataire_first_name { 'John' }
|
|
|
|
|
mandataire_last_name { 'Doe' }
|
|
|
|
|
|
|
|
|
|
transient do
|
|
|
|
|
for_individual? { true }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
after(:build) do |dossier, _evaluator|
|
|
|
|
|
if !dossier.procedure.for_individual?
|
|
|
|
|
raise 'Inconsistent factory: attempting to create a dossier :with_individual on a procedure that is not `for_individual?`'
|
|
|
|
|
end
|
|
|
|
|
dossier.individual = build(:individual, :with_notification, dossier: dossier)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
trait :for_tiers_without_notification do
|
|
|
|
|
for_tiers { true }
|
|
|
|
|
mandataire_first_name { 'John' }
|
|
|
|
|
mandataire_last_name { 'Doe' }
|
|
|
|
|
|
|
|
|
|
transient do
|
|
|
|
|
for_individual? { true }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
after(:build) do |dossier, _evaluator|
|
|
|
|
|
if !dossier.procedure.for_individual?
|
|
|
|
|
raise 'Inconsistent factory: attempting to create a dossier :with_individual on a procedure that is not `for_individual?`'
|
|
|
|
|
end
|
|
|
|
|
dossier.individual = build(:individual, :without_notification, dossier: dossier)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2020-01-07 17:47:22 +01:00
|
|
|
|
trait :with_individual do
|
2021-11-19 13:48:52 +01:00
|
|
|
|
transient do
|
|
|
|
|
for_individual? { true }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
after(:build) do |dossier, _evaluator|
|
2020-01-07 17:45:39 +01:00
|
|
|
|
if !dossier.procedure.for_individual?
|
|
|
|
|
raise 'Inconsistent factory: attempting to create a dossier :with_individual on a procedure that is not `for_individual?`'
|
|
|
|
|
end
|
2020-07-20 16:53:25 +02:00
|
|
|
|
dossier.individual = build(:individual, dossier: dossier)
|
2017-01-03 12:53:27 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2022-12-14 18:15:57 +01:00
|
|
|
|
trait :with_declarative_accepte do
|
|
|
|
|
after(:build) do |dossier, _evaluator|
|
|
|
|
|
dossier.procedure.declarative_with_state = 'accepte'
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
trait :with_declarative_en_instruction do
|
|
|
|
|
after(:build) do |dossier, _evaluator|
|
|
|
|
|
dossier.procedure.declarative_with_state = 'en_instruction'
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2017-04-12 11:18:28 +02:00
|
|
|
|
trait :archived do
|
2018-09-04 16:46:48 +02:00
|
|
|
|
archived { true }
|
2017-04-12 11:18:28 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
trait :not_archived do
|
2018-09-04 16:46:48 +02:00
|
|
|
|
archived { false }
|
2017-04-12 11:18:28 +02:00
|
|
|
|
end
|
|
|
|
|
|
2024-06-12 16:32:42 +02:00
|
|
|
|
trait :hidden_by_expired do
|
2024-07-15 18:02:54 +02:00
|
|
|
|
hidden_by_expired_at { 1.day.ago }
|
2024-06-04 17:52:01 +02:00
|
|
|
|
hidden_by_reason { DeletedDossier.reasons.fetch(:expired) }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
trait :hidden_by_user do
|
|
|
|
|
hidden_by_user_at { 1.day.ago }
|
|
|
|
|
hidden_by_reason { DeletedDossier.reasons.fetch(:user_request) }
|
|
|
|
|
end
|
|
|
|
|
|
2024-05-29 11:03:33 +02:00
|
|
|
|
trait :hidden_by_administration do
|
|
|
|
|
hidden_by_administration_at { 1.day.ago }
|
|
|
|
|
hidden_by_reason { DeletedDossier.reasons.fetch(:instructeur_request) }
|
|
|
|
|
end
|
|
|
|
|
|
2018-09-05 16:17:26 +02:00
|
|
|
|
trait :with_commentaires do
|
2021-11-19 17:25:32 +01:00
|
|
|
|
commentaires { [build(:commentaire), build(:commentaire)] }
|
2022-11-07 18:09:06 +01:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
trait :with_invites do
|
|
|
|
|
invites { [build(:invite)] }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
trait :with_avis do
|
|
|
|
|
avis { [build(:avis)] }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
trait :with_dossier_operation_logs do
|
|
|
|
|
dossier_operation_logs { [build(:dossier_operation_log)] }
|
2018-09-05 16:17:26 +02:00
|
|
|
|
end
|
|
|
|
|
|
2017-07-17 11:22:12 +02:00
|
|
|
|
trait :followed do
|
|
|
|
|
after(:create) do |dossier, _evaluator|
|
2019-08-06 11:02:54 +02:00
|
|
|
|
g = create(:instructeur)
|
2017-07-17 11:22:12 +02:00
|
|
|
|
g.followed_dossiers << dossier
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2020-12-16 14:35:55 +01:00
|
|
|
|
trait :brouillon do
|
|
|
|
|
end
|
|
|
|
|
|
2017-12-14 15:51:45 +01:00
|
|
|
|
trait :en_construction do
|
2017-10-05 10:50:44 +02:00
|
|
|
|
after(:create) do |dossier, _evaluator|
|
2018-08-28 14:10:55 +02:00
|
|
|
|
dossier.state = Dossier.states.fetch(:en_construction)
|
2021-03-09 11:21:30 +01:00
|
|
|
|
dossier.groupe_instructeur ||= dossier.procedure&.defaut_groupe_instructeur
|
2023-11-14 15:54:34 +01:00
|
|
|
|
|
|
|
|
|
processed_at = DossierWithReferenceDate.assign(dossier)
|
|
|
|
|
dossier.traitements.passer_en_construction(processed_at:)
|
|
|
|
|
|
2017-10-05 10:50:44 +02:00
|
|
|
|
dossier.save!
|
|
|
|
|
end
|
2017-01-30 15:17:45 +01:00
|
|
|
|
end
|
2017-10-05 15:22:56 +02:00
|
|
|
|
|
2017-12-14 15:53:02 +01:00
|
|
|
|
trait :en_instruction do
|
2017-10-05 15:22:56 +02:00
|
|
|
|
after(:create) do |dossier, _evaluator|
|
2018-08-28 14:10:55 +02:00
|
|
|
|
dossier.state = Dossier.states.fetch(:en_instruction)
|
2021-03-09 11:21:30 +01:00
|
|
|
|
dossier.groupe_instructeur ||= dossier.procedure&.defaut_groupe_instructeur
|
2023-11-14 15:54:34 +01:00
|
|
|
|
|
|
|
|
|
processed_at = DossierWithReferenceDate.assign(dossier)
|
|
|
|
|
dossier.traitements.passer_en_instruction(processed_at:)
|
|
|
|
|
|
2017-10-05 15:22:56 +02:00
|
|
|
|
dossier.save!
|
|
|
|
|
end
|
|
|
|
|
end
|
2018-08-10 16:17:19 +02:00
|
|
|
|
|
|
|
|
|
trait :accepte do
|
2020-07-02 11:02:50 +02:00
|
|
|
|
transient do
|
|
|
|
|
motivation { nil }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
after(:create) do |dossier, evaluator|
|
2018-08-28 14:10:55 +02:00
|
|
|
|
dossier.state = Dossier.states.fetch(:accepte)
|
2021-03-09 11:21:30 +01:00
|
|
|
|
dossier.groupe_instructeur ||= dossier.procedure&.defaut_groupe_instructeur
|
2023-11-14 15:54:34 +01:00
|
|
|
|
|
|
|
|
|
processed_at = DossierWithReferenceDate.assign(dossier)
|
|
|
|
|
dossier.traitements.accepter(motivation: evaluator.motivation, processed_at:)
|
|
|
|
|
|
2018-08-10 16:17:19 +02:00
|
|
|
|
dossier.save!
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
trait :refuse do
|
2023-11-14 15:54:34 +01:00
|
|
|
|
transient do
|
|
|
|
|
motivation { nil }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
after(:create) do |dossier, evaluator|
|
2018-08-28 14:10:55 +02:00
|
|
|
|
dossier.state = Dossier.states.fetch(:refuse)
|
2021-03-09 11:21:30 +01:00
|
|
|
|
dossier.groupe_instructeur ||= dossier.procedure&.defaut_groupe_instructeur
|
2023-11-14 15:54:34 +01:00
|
|
|
|
|
|
|
|
|
processed_at = DossierWithReferenceDate.assign(dossier)
|
|
|
|
|
dossier.traitements.refuser(motivation: evaluator.motivation, processed_at:)
|
|
|
|
|
|
2018-08-10 16:17:19 +02:00
|
|
|
|
dossier.save!
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
trait :sans_suite do
|
2023-11-14 15:54:34 +01:00
|
|
|
|
transient do
|
|
|
|
|
motivation { nil }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
after(:create) do |dossier, evaluator|
|
2018-08-28 14:10:55 +02:00
|
|
|
|
dossier.state = Dossier.states.fetch(:sans_suite)
|
2021-03-09 11:21:30 +01:00
|
|
|
|
dossier.groupe_instructeur ||= dossier.procedure&.defaut_groupe_instructeur
|
2023-11-14 15:54:34 +01:00
|
|
|
|
|
|
|
|
|
processed_at = DossierWithReferenceDate.assign(dossier)
|
|
|
|
|
dossier.traitements.classer_sans_suite(motivation: evaluator.motivation, processed_at:)
|
|
|
|
|
|
2018-08-10 16:17:19 +02:00
|
|
|
|
dossier.save!
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
trait :with_motivation do
|
|
|
|
|
after(:create) do |dossier, _evaluator|
|
2020-07-02 11:02:50 +02:00
|
|
|
|
motivation = case dossier.state
|
2018-08-28 14:10:55 +02:00
|
|
|
|
when Dossier.states.fetch(:refuse)
|
2018-08-10 16:17:19 +02:00
|
|
|
|
'L’entreprise concernée n’est pas agréée.'
|
2018-08-28 14:10:55 +02:00
|
|
|
|
when Dossier.states.fetch(:sans_suite)
|
2018-08-10 16:17:19 +02:00
|
|
|
|
'Le département n’est pas éligible. Veuillez remplir un nouveau dossier auprès de la DDT du 93.'
|
|
|
|
|
else
|
|
|
|
|
'Vous avez validé les conditions.'
|
|
|
|
|
end
|
2020-07-02 11:02:50 +02:00
|
|
|
|
dossier.traitements.last.update!(motivation: motivation)
|
2018-08-10 16:17:19 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
2018-09-17 14:45:40 +02:00
|
|
|
|
|
|
|
|
|
trait :with_attestation do
|
2020-07-20 16:30:29 +02:00
|
|
|
|
after(:build) do |dossier, _evaluator|
|
2022-11-09 12:09:24 +01:00
|
|
|
|
dossier.procedure.attestation_template ||= build(:attestation_template)
|
|
|
|
|
dossier.association(:attestation_template).target = dossier.procedure.attestation_template
|
2018-09-17 14:45:40 +02:00
|
|
|
|
dossier.attestation = dossier.build_attestation
|
|
|
|
|
end
|
|
|
|
|
end
|
2018-11-22 00:14:16 +01:00
|
|
|
|
|
2019-10-15 12:42:51 +02:00
|
|
|
|
trait :with_justificatif do
|
|
|
|
|
after(:create) do |dossier, _evaluator|
|
|
|
|
|
dossier.justificatif_motivation.attach(
|
|
|
|
|
io: StringIO.new('Hello World'),
|
2021-09-02 12:26:57 +02:00
|
|
|
|
filename: 'hello.txt',
|
|
|
|
|
# we don't want to run virus scanner on this file
|
|
|
|
|
metadata: { virus_scan_result: ActiveStorage::VirusScanner::SAFE }
|
2019-10-15 12:42:51 +02:00
|
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2021-11-03 15:52:53 +01:00
|
|
|
|
trait :with_populated_champs do
|
2018-11-22 00:14:16 +01:00
|
|
|
|
after(:create) do |dossier, _evaluator|
|
2023-04-11 17:00:25 +02:00
|
|
|
|
dossier.champs_to_destroy.where(private: false).destroy_all
|
|
|
|
|
dossier.types_de_champ.each do |type_de_champ|
|
2024-07-01 15:31:32 +02:00
|
|
|
|
value = if type_de_champ.simple_drop_down_list?
|
|
|
|
|
type_de_champ.drop_down_list_enabled_non_empty_options.first
|
2023-11-28 17:33:43 +01:00
|
|
|
|
elsif type_de_champ.multiple_drop_down_list?
|
2024-07-01 15:31:32 +02:00
|
|
|
|
type_de_champ.drop_down_list_enabled_non_empty_options.first(2).to_json
|
2023-11-28 17:33:43 +01:00
|
|
|
|
end
|
2024-07-01 15:31:32 +02:00
|
|
|
|
attrs = { stable_id: type_de_champ.stable_id, dossier:, value: }.compact
|
|
|
|
|
create(:"champ_do_not_use_#{type_de_champ.type_champ}", **attrs)
|
2018-11-22 00:14:16 +01:00
|
|
|
|
end
|
2023-04-11 17:00:25 +02:00
|
|
|
|
dossier.reload
|
2018-11-22 00:14:16 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2021-11-03 15:52:53 +01:00
|
|
|
|
trait :with_populated_annotations do
|
2018-11-22 00:14:16 +01:00
|
|
|
|
after(:create) do |dossier, _evaluator|
|
2023-04-11 17:00:25 +02:00
|
|
|
|
dossier.champs_to_destroy.where(private: true).destroy_all
|
|
|
|
|
dossier.types_de_champ_private.each do |type_de_champ|
|
2024-07-01 15:31:32 +02:00
|
|
|
|
value = if type_de_champ.simple_drop_down_list?
|
|
|
|
|
type_de_champ.drop_down_list_enabled_non_empty_options.first
|
2023-11-28 17:33:43 +01:00
|
|
|
|
elsif type_de_champ.multiple_drop_down_list?
|
2024-07-01 15:31:32 +02:00
|
|
|
|
type_de_champ.drop_down_list_enabled_non_empty_options.first(2).to_json
|
2023-11-28 17:33:43 +01:00
|
|
|
|
end
|
2024-07-01 15:31:32 +02:00
|
|
|
|
attrs = { stable_id: type_de_champ.stable_id, dossier:, private: true, value: }.compact
|
|
|
|
|
create(:"champ_do_not_use_#{type_de_champ.type_champ}", **attrs)
|
2018-11-22 00:14:16 +01:00
|
|
|
|
end
|
2023-04-11 17:00:25 +02:00
|
|
|
|
dossier.reload
|
2018-11-22 00:14:16 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
2023-01-03 14:46:10 +01:00
|
|
|
|
|
|
|
|
|
trait :prefilled do
|
|
|
|
|
prefilled { true }
|
|
|
|
|
end
|
2015-08-13 15:55:19 +02:00
|
|
|
|
end
|
2015-08-20 17:30:17 +02:00
|
|
|
|
end
|