2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-06-25 15:46:10 +02:00
|
|
|
require 'csv'
|
2018-11-22 00:14:16 +01:00
|
|
|
|
2023-01-24 12:25:17 +01:00
|
|
|
describe ProcedureExportService do
|
2024-02-07 17:19:50 +01:00
|
|
|
let(:instructeur) { create(:instructeur) }
|
2024-03-08 17:14:21 +01:00
|
|
|
let(:service) { ProcedureExportService.new(procedure, procedure.dossiers, instructeur, export_template) }
|
|
|
|
let(:export_template) { nil }
|
2023-01-19 09:43:19 +01:00
|
|
|
|
2023-04-13 13:10:23 +02:00
|
|
|
describe 'to_xlsx' do
|
2019-06-25 15:46:10 +02:00
|
|
|
subject do
|
2022-04-21 15:34:24 +02:00
|
|
|
service
|
2022-04-08 17:12:34 +02:00
|
|
|
.to_xlsx
|
|
|
|
.open { |f| SimpleXlsxReader.open(f.path) }
|
2019-06-25 15:46:10 +02:00
|
|
|
end
|
2018-11-22 00:14:16 +01:00
|
|
|
|
2019-06-25 15:46:10 +02:00
|
|
|
let(:dossiers_sheet) { subject.sheets.first }
|
|
|
|
let(:etablissements_sheet) { subject.sheets.second }
|
|
|
|
let(:avis_sheet) { subject.sheets.third }
|
|
|
|
let(:repetition_sheet) { subject.sheets.fourth }
|
2018-11-22 00:14:16 +01:00
|
|
|
|
2020-05-13 15:57:40 +02:00
|
|
|
describe 'sheets' do
|
2024-05-31 09:41:31 +02:00
|
|
|
let(:procedure) { create(:procedure) }
|
|
|
|
|
2020-05-13 15:57:40 +02:00
|
|
|
it 'should have a sheet for each record type' do
|
2019-06-25 15:46:10 +02:00
|
|
|
expect(subject.sheets.map(&:name)).to eq(['Dossiers', 'Etablissements', 'Avis'])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-05-13 15:57:40 +02:00
|
|
|
describe 'Dossiers sheet' do
|
2024-05-31 09:41:31 +02:00
|
|
|
context 'with all data for individual' do
|
|
|
|
let(:procedure) { create(:procedure, :published, :for_individual, :with_all_champs) }
|
|
|
|
let!(:dossier) { create(:dossier, :en_instruction, :with_populated_champs, :with_individual, procedure: procedure) }
|
2019-06-25 15:46:10 +02:00
|
|
|
|
2024-05-31 09:41:31 +02:00
|
|
|
# before do
|
|
|
|
# # change one tdc place to check if the header is ordered
|
|
|
|
# tdc_first = procedure.active_revision.revision_types_de_champ_public.first
|
|
|
|
# tdc_last = procedure.active_revision.revision_types_de_champ_public.last
|
2019-09-18 17:52:02 +02:00
|
|
|
|
2024-05-31 09:41:31 +02:00
|
|
|
# tdc_first.update(position: tdc_last.position + 1)
|
|
|
|
# procedure.reload
|
|
|
|
# end
|
2019-06-25 15:46:10 +02:00
|
|
|
|
2024-05-31 09:41:31 +02:00
|
|
|
let(:nominal_headers) do
|
|
|
|
[
|
|
|
|
"ID",
|
|
|
|
"Email",
|
|
|
|
"FranceConnect ?",
|
|
|
|
"Civilité",
|
|
|
|
"Nom",
|
|
|
|
"Prénom",
|
|
|
|
"Dépôt pour un tiers",
|
|
|
|
"Nom du mandataire",
|
|
|
|
"Prénom du mandataire",
|
|
|
|
"Archivé",
|
|
|
|
"État du dossier",
|
|
|
|
"Dernière mise à jour le",
|
|
|
|
"Dernière mise à jour du dossier le",
|
|
|
|
"Déposé le",
|
|
|
|
"Passé en instruction le",
|
|
|
|
"Traité le",
|
|
|
|
"Motivation de la décision",
|
|
|
|
"Instructeurs",
|
|
|
|
"textarea",
|
|
|
|
"date",
|
|
|
|
"datetime",
|
|
|
|
"number",
|
|
|
|
"decimal_number",
|
|
|
|
"integer_number",
|
|
|
|
"checkbox",
|
|
|
|
"civilite",
|
|
|
|
"email",
|
|
|
|
"phone",
|
|
|
|
"address",
|
|
|
|
"simple_drop_down_list",
|
|
|
|
"multiple_drop_down_list",
|
|
|
|
"linked_drop_down_list",
|
|
|
|
"communes",
|
|
|
|
"communes (Code INSEE)",
|
|
|
|
"communes (Département)",
|
|
|
|
"departements",
|
|
|
|
"departements (Code)",
|
|
|
|
"regions",
|
|
|
|
"regions (Code)",
|
|
|
|
"pays",
|
|
|
|
"pays (Code)",
|
|
|
|
"dossier_link",
|
|
|
|
"piece_justificative",
|
|
|
|
"rna",
|
|
|
|
"carte",
|
|
|
|
"titre_identite",
|
|
|
|
"iban",
|
|
|
|
"siret",
|
|
|
|
"annuaire_education",
|
|
|
|
"cnaf",
|
|
|
|
"dgfip",
|
|
|
|
"pole_emploi",
|
|
|
|
"mesri",
|
|
|
|
"text",
|
|
|
|
"epci",
|
|
|
|
"epci (Code)",
|
|
|
|
"epci (Département)",
|
|
|
|
"cojo",
|
|
|
|
"expression_reguliere",
|
|
|
|
"rnf",
|
|
|
|
"rnf (Nom)",
|
|
|
|
"rnf (Adresse)",
|
|
|
|
"rnf (Code INSEE Ville)",
|
|
|
|
"rnf (Département)",
|
|
|
|
"engagement_juridique",
|
|
|
|
"yes_no"
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should have data' do
|
|
|
|
expect(dossiers_sheet.headers).to match_array(nominal_headers)
|
|
|
|
|
|
|
|
expect(dossiers_sheet.data.size).to eq(1)
|
|
|
|
expect(etablissements_sheet.data.size).to eq(1)
|
|
|
|
|
|
|
|
# SimpleXlsxReader is transforming datetimes in utc... It is only used in test so we just hack around.
|
|
|
|
offset = dossier.depose_at.utc_offset
|
|
|
|
depose_at = Time.zone.at(dossiers_sheet.data[0][13] - offset.seconds)
|
|
|
|
en_instruction_at = Time.zone.at(dossiers_sheet.data[0][14] - offset.seconds)
|
|
|
|
expect(dossiers_sheet.data.first.size).to eq(nominal_headers.size)
|
|
|
|
expect(depose_at).to eq(dossier.depose_at.round)
|
|
|
|
expect(en_instruction_at).to eq(dossier.en_instruction_at.round)
|
|
|
|
end
|
2019-09-18 17:52:02 +02:00
|
|
|
end
|
|
|
|
|
2020-05-13 15:57:56 +02:00
|
|
|
context 'with a birthdate' do
|
2024-05-31 09:41:31 +02:00
|
|
|
let(:procedure) { create(:procedure, :published, :for_individual, ask_birthday: true) }
|
|
|
|
let!(:dossier) { create(:dossier, :en_instruction, :with_individual, procedure:) }
|
2020-05-13 15:57:56 +02:00
|
|
|
|
2024-05-31 09:41:31 +02:00
|
|
|
it 'find date de naissance' do
|
|
|
|
expect(dossiers_sheet.headers).to include('Date de naissance')
|
|
|
|
expect(dossiers_sheet.data[0][dossiers_sheet.headers.index('Date de naissance')]).to be_a(Date)
|
|
|
|
end
|
2020-05-13 15:57:56 +02:00
|
|
|
end
|
|
|
|
|
2019-09-18 17:52:02 +02:00
|
|
|
context 'with a procedure routee' do
|
2024-05-31 09:41:31 +02:00
|
|
|
let(:procedure) { create(:procedure, :published, :for_individual) }
|
|
|
|
let!(:dossier) { create(:dossier, :en_instruction, :with_individual, procedure:) }
|
|
|
|
before { create(:groupe_instructeur, label: '2', procedure:) }
|
2019-09-18 17:52:02 +02:00
|
|
|
|
2024-05-31 09:41:31 +02:00
|
|
|
it 'find groupe instructeur data' do
|
|
|
|
expect(dossiers_sheet.headers).to include('Groupe instructeur')
|
|
|
|
expect(dossiers_sheet.data[0][dossiers_sheet.headers.index('Groupe instructeur')]).to eq('défaut')
|
|
|
|
end
|
2018-11-22 00:14:16 +01:00
|
|
|
end
|
2022-12-06 15:03:31 +01:00
|
|
|
|
|
|
|
context 'with a dossier having multiple pjs' do
|
2024-05-31 09:41:31 +02:00
|
|
|
let(:procedure) { create(:procedure, :published, :for_individual, types_de_champ_public:) }
|
|
|
|
let(:types_de_champ_public) { [{ type: :piece_justificative }] }
|
|
|
|
let!(:dossier) { create(:dossier, :en_instruction, :with_populated_champs, :with_individual, procedure:) }
|
|
|
|
let!(:dossier_2) { create(:dossier, :en_instruction, :with_populated_champs, :with_individual, procedure:) }
|
2022-12-06 15:03:31 +01:00
|
|
|
before do
|
|
|
|
dossier_2.champs_public
|
|
|
|
.find { _1.is_a? Champs::PieceJustificativeChamp }
|
|
|
|
.piece_justificative_file
|
|
|
|
.attach(io: StringIO.new("toto"), filename: "toto.txt", content_type: "text/plain")
|
|
|
|
end
|
2024-05-31 09:41:31 +02:00
|
|
|
it { expect(dossiers_sheet.data.first.size).to eq(19) } # default number of header when procedure has only one champ
|
2022-12-06 15:03:31 +01:00
|
|
|
end
|
2023-11-02 16:00:28 +01:00
|
|
|
|
|
|
|
context 'with procedure chorus' do
|
2024-05-31 09:41:31 +02:00
|
|
|
before { expect_any_instance_of(Procedure).to receive(:chorusable?).and_return(true) }
|
|
|
|
let(:procedure) { create(:procedure, :published, :for_individual, :filled_chorus) }
|
|
|
|
let!(:dossier) { create(:dossier, :en_instruction, procedure: procedure) }
|
2023-11-02 16:00:28 +01:00
|
|
|
|
|
|
|
it 'includes chorus headers' do
|
2024-05-31 09:41:31 +02:00
|
|
|
expect(dossiers_sheet.headers).to include('Domaine Fonctionnel')
|
|
|
|
expect(dossiers_sheet.headers).to include('Référentiel De Programmation')
|
|
|
|
expect(dossiers_sheet.headers).to include('Centre De Coût')
|
2023-11-02 16:00:28 +01:00
|
|
|
end
|
|
|
|
end
|
2019-06-25 15:46:10 +02:00
|
|
|
end
|
|
|
|
|
2020-05-13 15:57:40 +02:00
|
|
|
describe 'Etablissement sheet' do
|
2024-05-31 09:41:31 +02:00
|
|
|
let(:procedure) { create(:procedure, :published, types_de_champ_public:) }
|
|
|
|
let(:types_de_champ_public) { [{ type: :siret, libelle: 'siret' }] }
|
2021-11-03 15:52:53 +01:00
|
|
|
let!(:dossier) { create(:dossier, :en_instruction, :with_populated_champs, :with_entreprise, procedure: procedure) }
|
2018-11-22 00:14:16 +01:00
|
|
|
|
2019-06-25 15:46:10 +02:00
|
|
|
let(:dossier_etablissement) { etablissements_sheet.data[1] }
|
|
|
|
let(:champ_etablissement) { etablissements_sheet.data[0] }
|
|
|
|
|
|
|
|
let(:nominal_headers) do
|
|
|
|
[
|
|
|
|
"ID",
|
|
|
|
"Email",
|
2024-02-19 16:59:29 +01:00
|
|
|
"FranceConnect ?",
|
2019-06-25 15:46:10 +02:00
|
|
|
"Entreprise raison sociale",
|
|
|
|
"Archivé",
|
|
|
|
"État du dossier",
|
|
|
|
"Dernière mise à jour le",
|
2024-03-18 12:54:05 +01:00
|
|
|
"Dernière mise à jour du dossier le",
|
2019-06-25 15:46:10 +02:00
|
|
|
"Déposé le",
|
|
|
|
"Passé en instruction le",
|
|
|
|
"Traité le",
|
|
|
|
"Motivation de la décision",
|
|
|
|
"Instructeurs",
|
2024-05-31 09:41:31 +02:00
|
|
|
'siret'
|
2019-06-25 15:46:10 +02:00
|
|
|
]
|
2018-11-22 00:14:16 +01:00
|
|
|
end
|
|
|
|
|
2019-06-25 15:46:10 +02:00
|
|
|
context 'as csv' do
|
|
|
|
subject do
|
2024-03-08 17:14:21 +01:00
|
|
|
ProcedureExportService.new(procedure, procedure.dossiers, instructeur, export_template)
|
2022-04-08 17:12:34 +02:00
|
|
|
.to_csv
|
|
|
|
.open { |f| CSV.read(f.path) }
|
2019-06-25 15:46:10 +02:00
|
|
|
end
|
2018-11-22 00:14:16 +01:00
|
|
|
|
2019-06-25 15:46:10 +02:00
|
|
|
let(:nominal_headers) do
|
2018-11-22 00:14:16 +01:00
|
|
|
[
|
2019-06-25 15:46:10 +02:00
|
|
|
"ID",
|
|
|
|
"Email",
|
2024-02-19 16:59:29 +01:00
|
|
|
"FranceConnect ?",
|
2019-06-25 15:46:10 +02:00
|
|
|
"Établissement SIRET",
|
|
|
|
"Établissement siège social",
|
|
|
|
"Établissement NAF",
|
|
|
|
"Établissement libellé NAF",
|
|
|
|
"Établissement Adresse",
|
|
|
|
"Établissement numero voie",
|
|
|
|
"Établissement type voie",
|
|
|
|
"Établissement nom voie",
|
|
|
|
"Établissement complément adresse",
|
|
|
|
"Établissement code postal",
|
|
|
|
"Établissement localité",
|
|
|
|
"Établissement code INSEE localité",
|
|
|
|
"Entreprise SIREN",
|
|
|
|
"Entreprise capital social",
|
|
|
|
"Entreprise numero TVA intracommunautaire",
|
|
|
|
"Entreprise forme juridique",
|
|
|
|
"Entreprise forme juridique code",
|
|
|
|
"Entreprise nom commercial",
|
|
|
|
"Entreprise raison sociale",
|
|
|
|
"Entreprise SIRET siège social",
|
|
|
|
"Entreprise code effectif entreprise",
|
|
|
|
"Entreprise date de création",
|
2022-07-18 13:21:50 +02:00
|
|
|
"Entreprise état administratif",
|
2019-06-25 15:46:10 +02:00
|
|
|
"Entreprise nom",
|
|
|
|
"Entreprise prénom",
|
|
|
|
"Association RNA",
|
|
|
|
"Association titre",
|
|
|
|
"Association objet",
|
|
|
|
"Association date de création",
|
|
|
|
"Association date de déclaration",
|
|
|
|
"Association date de publication",
|
|
|
|
"Archivé",
|
|
|
|
"État du dossier",
|
|
|
|
"Dernière mise à jour le",
|
2024-03-18 12:54:05 +01:00
|
|
|
"Dernière mise à jour du dossier le",
|
2019-06-25 15:46:10 +02:00
|
|
|
"Déposé le",
|
|
|
|
"Passé en instruction le",
|
|
|
|
"Traité le",
|
|
|
|
"Motivation de la décision",
|
|
|
|
"Instructeurs",
|
2024-05-31 09:41:31 +02:00
|
|
|
'siret'
|
2018-11-22 00:14:16 +01:00
|
|
|
]
|
2019-06-25 15:46:10 +02:00
|
|
|
end
|
2018-11-22 00:14:16 +01:00
|
|
|
|
2019-06-25 15:46:10 +02:00
|
|
|
let(:dossiers_sheet_headers) { subject.first }
|
2018-11-22 00:14:16 +01:00
|
|
|
|
2019-06-25 15:46:10 +02:00
|
|
|
it 'should have headers' do
|
2022-11-28 17:41:46 +01:00
|
|
|
expect(dossiers_sheet_headers).to match_array(nominal_headers)
|
2019-06-25 15:46:10 +02:00
|
|
|
end
|
|
|
|
end
|
2018-11-22 00:14:16 +01:00
|
|
|
|
2024-05-31 09:41:31 +02:00
|
|
|
it 'should have headers and data' do
|
2022-11-28 17:41:46 +01:00
|
|
|
expect(dossiers_sheet.headers).to match_array(nominal_headers)
|
2019-06-25 15:46:10 +02:00
|
|
|
|
|
|
|
expect(etablissements_sheet.headers).to eq([
|
|
|
|
"Dossier ID",
|
|
|
|
"Champ",
|
|
|
|
"Établissement SIRET",
|
2020-08-20 10:21:34 +02:00
|
|
|
"Etablissement enseigne",
|
2019-06-25 15:46:10 +02:00
|
|
|
"Établissement siège social",
|
|
|
|
"Établissement NAF",
|
|
|
|
"Établissement libellé NAF",
|
|
|
|
"Établissement Adresse",
|
|
|
|
"Établissement numero voie",
|
|
|
|
"Établissement type voie",
|
|
|
|
"Établissement nom voie",
|
|
|
|
"Établissement complément adresse",
|
|
|
|
"Établissement code postal",
|
|
|
|
"Établissement localité",
|
|
|
|
"Établissement code INSEE localité",
|
|
|
|
"Entreprise SIREN",
|
|
|
|
"Entreprise capital social",
|
|
|
|
"Entreprise numero TVA intracommunautaire",
|
|
|
|
"Entreprise forme juridique",
|
|
|
|
"Entreprise forme juridique code",
|
|
|
|
"Entreprise nom commercial",
|
|
|
|
"Entreprise raison sociale",
|
|
|
|
"Entreprise SIRET siège social",
|
|
|
|
"Entreprise code effectif entreprise",
|
|
|
|
"Entreprise date de création",
|
2022-07-18 13:21:50 +02:00
|
|
|
"Entreprise état administratif",
|
2019-06-25 15:46:10 +02:00
|
|
|
"Entreprise nom",
|
|
|
|
"Entreprise prénom",
|
|
|
|
"Association RNA",
|
|
|
|
"Association titre",
|
|
|
|
"Association objet",
|
|
|
|
"Association date de création",
|
|
|
|
"Association date de déclaration",
|
|
|
|
"Association date de publication"
|
|
|
|
])
|
2018-11-22 00:14:16 +01:00
|
|
|
|
2019-06-25 15:46:10 +02:00
|
|
|
expect(etablissements_sheet.data.size).to eq(2)
|
|
|
|
expect(dossier_etablissement[1]).to eq("Dossier")
|
|
|
|
expect(champ_etablissement[1]).to eq("siret")
|
|
|
|
end
|
|
|
|
end
|
2018-11-22 00:14:16 +01:00
|
|
|
|
2020-05-13 15:57:40 +02:00
|
|
|
describe 'Avis sheet' do
|
2024-05-31 09:41:31 +02:00
|
|
|
let(:procedure) { create(:procedure, :published, :for_individual) }
|
2021-11-03 15:52:53 +01:00
|
|
|
let!(:dossier) { create(:dossier, :en_instruction, :with_populated_champs, :with_individual, procedure: procedure) }
|
2019-06-25 15:46:10 +02:00
|
|
|
let!(:avis) { create(:avis, :with_answer, dossier: dossier) }
|
2019-09-18 17:52:02 +02:00
|
|
|
|
2024-05-31 09:41:31 +02:00
|
|
|
it 'should have headers and data' do
|
2019-06-25 15:46:10 +02:00
|
|
|
expect(avis_sheet.headers).to eq([
|
|
|
|
"Dossier ID",
|
2023-03-10 14:38:37 +01:00
|
|
|
"Introduction",
|
2019-06-25 15:46:10 +02:00
|
|
|
"Réponse",
|
2023-03-10 14:38:37 +01:00
|
|
|
"Question",
|
|
|
|
"Réponse oui/non",
|
2019-06-25 15:46:10 +02:00
|
|
|
"Créé le",
|
2020-01-28 12:42:30 +01:00
|
|
|
"Répondu le",
|
|
|
|
"Instructeur",
|
|
|
|
"Expert"
|
2019-06-25 15:46:10 +02:00
|
|
|
])
|
|
|
|
expect(avis_sheet.data.size).to eq(1)
|
2018-11-22 00:14:16 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-05-13 15:57:40 +02:00
|
|
|
describe 'Repetitions sheet' do
|
2024-05-31 09:41:31 +02:00
|
|
|
before do
|
|
|
|
# change one tdc place to check if the header is ordered
|
|
|
|
tdc_first = procedure.active_revision.revision_types_de_champ_public.first
|
|
|
|
tdc_last = procedure.active_revision.revision_types_de_champ_public.last
|
|
|
|
|
|
|
|
tdc_first.update(position: tdc_last.position + 1)
|
|
|
|
procedure.reload
|
|
|
|
end
|
|
|
|
|
2024-07-01 15:31:32 +02:00
|
|
|
let(:types_de_champ_public) { [{ type: :repetition, children: [{ libelle: 'Nom' }, { libelle: 'Age' }] }] }
|
|
|
|
let(:procedure) { create(:procedure, :published, :for_individual, types_de_champ_public:) }
|
2019-06-25 15:46:10 +02:00
|
|
|
let!(:dossiers) do
|
|
|
|
[
|
2021-11-03 15:52:53 +01:00
|
|
|
create(:dossier, :en_instruction, :with_populated_champs, :with_individual, procedure: procedure),
|
|
|
|
create(:dossier, :en_instruction, :with_populated_champs, :with_individual, procedure: procedure)
|
2019-06-25 15:46:10 +02:00
|
|
|
]
|
|
|
|
end
|
2022-11-10 22:21:14 +01:00
|
|
|
let(:champ_repetition) { dossiers.first.champs_public.find { |champ| champ.type_champ == 'repetition' } }
|
2019-06-25 15:46:10 +02:00
|
|
|
|
|
|
|
it 'should have sheets' do
|
2024-04-02 17:05:44 +02:00
|
|
|
expect(subject.sheets.map(&:name)).to eq(['Dossiers', 'Etablissements', 'Avis', champ_repetition.type_de_champ.libelle_for_export])
|
2019-06-25 15:46:10 +02:00
|
|
|
end
|
2018-11-22 00:14:16 +01:00
|
|
|
|
2021-11-10 20:45:32 +01:00
|
|
|
context 'with cloned procedure' do
|
|
|
|
let(:other_parent) { create(:type_de_champ_repetition, stable_id: champ_repetition.stable_id) }
|
|
|
|
|
|
|
|
before do
|
2022-05-25 09:51:40 +02:00
|
|
|
create(:type_de_champ, parent: create(:procedure_revision_type_de_champ, type_de_champ: other_parent, revision: create(:procedure).active_revision, position: 0))
|
2021-11-10 20:45:32 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should have headers' do
|
|
|
|
expect(repetition_sheet.headers).to eq([
|
|
|
|
"Dossier ID",
|
|
|
|
"Ligne",
|
|
|
|
"Nom",
|
|
|
|
"Age"
|
|
|
|
])
|
|
|
|
end
|
2018-11-22 00:14:16 +01:00
|
|
|
end
|
|
|
|
|
2019-06-25 15:46:10 +02:00
|
|
|
it 'should have data' do
|
|
|
|
expect(repetition_sheet.data.size).to eq(4)
|
2018-11-22 00:14:16 +01:00
|
|
|
end
|
|
|
|
|
2019-06-25 15:46:10 +02:00
|
|
|
context 'with invalid characters' do
|
|
|
|
before do
|
2020-01-29 11:33:28 +01:00
|
|
|
champ_repetition.type_de_champ.update(libelle: 'A / B \ C *[]?')
|
2019-06-25 15:46:10 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should have valid sheet name' do
|
|
|
|
expect(subject.sheets.map(&:name)).to eq(['Dossiers', 'Etablissements', 'Avis', "(#{champ_repetition.type_de_champ.stable_id}) A - B - C"])
|
|
|
|
end
|
|
|
|
end
|
2018-11-22 00:14:16 +01:00
|
|
|
|
2020-09-29 14:01:27 +02:00
|
|
|
context 'with long libelle composed of utf8 characteres' do
|
2020-09-24 14:24:53 +02:00
|
|
|
before do
|
2024-09-20 14:54:26 +02:00
|
|
|
procedure.active_revision.types_de_champ_public.each do |type_de_champ|
|
|
|
|
type_de_champ.update!(libelle: "#{type_de_champ.id} - ?/[] ééé ééé ééééééé ééééééé éééééééé. ééé éé éééééééé éé ééé. ééééé éééééééé ééé ééé.")
|
2020-09-24 14:24:53 +02:00
|
|
|
end
|
2024-09-20 14:54:26 +02:00
|
|
|
procedure.active_revision.children_of(champ_repetition.type_de_champ).each do |type_de_champ|
|
|
|
|
type_de_champ.update!(libelle: "#{type_de_champ.id} - Quam rem nam maiores numquam dolorem nesciunt. Cum et possimus et aut. Fugit voluptas qui qui.")
|
2020-09-24 14:24:53 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should have valid sheet name' do
|
2021-02-04 12:38:02 +01:00
|
|
|
expect { subject }.not_to raise_error
|
2020-09-24 14:24:53 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-25 15:46:10 +02:00
|
|
|
context 'with non unique labels' do
|
2024-07-01 15:31:32 +02:00
|
|
|
let(:types_de_champ_public) { [{ type: :repetition, libelle: 'Une repetition', children: [{}] }, { type: :repetition, libelle: 'Une repetition', children: [{}] }] }
|
|
|
|
let(:dossier) { create(:dossier, :en_instruction, :with_populated_champs, :with_individual, procedure:) }
|
|
|
|
let(:type_de_champ_repetition) { dossier.revision.types_de_champ_public.first }
|
|
|
|
let(:another_type_de_champ_repetition) { dossier.revision.types_de_champ_public.second }
|
2018-11-22 00:14:16 +01:00
|
|
|
|
2019-06-25 15:46:10 +02:00
|
|
|
it 'should have sheets' do
|
2024-07-01 15:31:32 +02:00
|
|
|
expect(subject.sheets.map(&:name)).to eq(['Dossiers', 'Etablissements', 'Avis', type_de_champ_repetition.libelle_for_export, another_type_de_champ_repetition.libelle_for_export])
|
2018-11-22 00:14:16 +01:00
|
|
|
end
|
|
|
|
end
|
2022-06-17 11:33:48 +02:00
|
|
|
|
|
|
|
context 'with empty repetition' do
|
|
|
|
before do
|
2022-11-10 22:21:14 +01:00
|
|
|
dossiers.flat_map { |dossier| dossier.champs_public.filter(&:repetition?) }.each do |champ|
|
2024-09-20 14:54:26 +02:00
|
|
|
Champ.where(row_id: champ.row_ids).destroy_all
|
2022-06-17 11:33:48 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not have data' do
|
|
|
|
expect(repetition_sheet).to be_nil
|
|
|
|
end
|
|
|
|
end
|
2018-11-22 00:14:16 +01:00
|
|
|
end
|
|
|
|
end
|
2022-04-21 15:34:24 +02:00
|
|
|
|
2023-04-13 13:10:23 +02:00
|
|
|
describe 'to_zip' do
|
2024-05-31 09:41:31 +02:00
|
|
|
let(:procedure) { create(:procedure, :published, :for_individual, types_de_champ_public:) }
|
|
|
|
let(:types_de_champ_public) { [{ type: :piece_justificative, libelle: 'piece_justificative' }] }
|
|
|
|
|
2022-04-21 17:02:23 +02:00
|
|
|
subject { service.to_zip }
|
|
|
|
context 'without files' do
|
|
|
|
it 'does not raises in_batches' do
|
2023-11-09 17:27:55 +01:00
|
|
|
expect { subject }.not_to raise_error
|
2022-04-21 17:02:23 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns an empty blob' do
|
|
|
|
expect(subject).to be_an_instance_of(ActiveStorage::Blob)
|
|
|
|
end
|
2022-04-21 15:34:24 +02:00
|
|
|
end
|
|
|
|
|
2024-03-08 17:14:21 +01:00
|
|
|
describe 'generate_dossiers_export' do
|
2023-03-06 14:58:26 +01:00
|
|
|
it 'include_infos_administration (so it includes avis, champs privés)' do
|
2024-03-08 17:14:21 +01:00
|
|
|
expect(ActiveStorage::DownloadableFile).to receive(:create_list_from_dossiers).with(dossiers: anything, user_profile: instructeur, export_template:).and_return([])
|
2023-03-06 14:58:26 +01:00
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
2024-03-08 17:14:21 +01:00
|
|
|
context 'with export_template' do
|
|
|
|
let!(:dossier) { create(:dossier, :accepte, :with_populated_champs, :with_individual, procedure: procedure) }
|
|
|
|
let(:dossier_exports) { PiecesJustificativesService.new(user_profile: instructeur, export_template:).generate_dossiers_export(Dossier.where(id: dossier)) }
|
2024-07-23 17:05:16 +02:00
|
|
|
let(:export_template) { create(:export_template, :enabled_pjs, groupe_instructeur: procedure.defaut_groupe_instructeur) }
|
2024-03-08 17:14:21 +01:00
|
|
|
before do
|
|
|
|
allow_any_instance_of(ActiveStorage::Attachment).to receive(:url).and_return("https://opengraph.githubassets.com/d0e7862b24d8026a3c03516d865b28151eb3859029c6c6c2e86605891fbdcd7a/socketry/async-io")
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a blob with custom filenames' do
|
|
|
|
VCR.use_cassette('archive/new_file_to_get_200') do
|
|
|
|
subject
|
|
|
|
File.write('tmp.zip', subject.download, mode: 'wb')
|
|
|
|
File.open('tmp.zip') do |fd|
|
|
|
|
files = ZipTricks::FileReader.read_zip_structure(io: fd)
|
|
|
|
base_fn = "export"
|
|
|
|
structure = [
|
|
|
|
"#{base_fn}/",
|
|
|
|
"#{base_fn}/dossier-#{dossier.id}/",
|
2024-07-23 17:05:16 +02:00
|
|
|
"#{base_fn}/dossier-#{dossier.id}/piece_justificative-#{dossier.id}-01.txt",
|
|
|
|
"#{base_fn}/dossier-#{dossier.id}/export-#{dossier.id}.pdf"
|
2024-03-08 17:14:21 +01:00
|
|
|
]
|
|
|
|
expect(files.map(&:filename)).to match_array(structure)
|
|
|
|
end
|
|
|
|
FileUtils.remove_entry_secure('tmp.zip')
|
|
|
|
end
|
|
|
|
end
|
2022-04-21 17:02:23 +02:00
|
|
|
end
|
|
|
|
|
2024-03-08 17:14:21 +01:00
|
|
|
context 'with files (and http calls)' do
|
|
|
|
let!(:dossier) { create(:dossier, :accepte, :with_populated_champs, :with_individual, procedure: procedure) }
|
|
|
|
let(:dossier_exports) { PiecesJustificativesService.new(user_profile: instructeur, export_template: nil).generate_dossiers_export(Dossier.where(id: dossier)) }
|
|
|
|
before do
|
|
|
|
allow_any_instance_of(ActiveStorage::Attachment).to receive(:url).and_return("https://opengraph.githubassets.com/d0e7862b24d8026a3c03516d865b28151eb3859029c6c6c2e86605891fbdcd7a/socketry/async-io")
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a blob with valid files' do
|
|
|
|
VCR.use_cassette('archive/new_file_to_get_200') do
|
|
|
|
subject
|
|
|
|
|
|
|
|
File.write('tmp.zip', subject.download, mode: 'wb')
|
|
|
|
File.open('tmp.zip') do |fd|
|
|
|
|
files = ZipTricks::FileReader.read_zip_structure(io: fd)
|
|
|
|
base_fn = 'export'
|
|
|
|
structure = [
|
|
|
|
"#{base_fn}/",
|
|
|
|
"#{base_fn}/dossier-#{dossier.id}/",
|
|
|
|
"#{base_fn}/dossier-#{dossier.id}/pieces_justificatives/",
|
|
|
|
"#{base_fn}/dossier-#{dossier.id}/#{ActiveStorage::DownloadableFile.timestamped_filename(ActiveStorage::Attachment.where(record_type: "Champ").first)}",
|
|
|
|
"#{base_fn}/dossier-#{dossier.id}/#{ActiveStorage::DownloadableFile.timestamped_filename(dossier_exports.first.first)}"
|
|
|
|
]
|
|
|
|
expect(files.size).to eq(structure.size)
|
|
|
|
expect(files.map(&:filename)).to match_array(structure)
|
|
|
|
end
|
|
|
|
FileUtils.remove_entry_secure('tmp.zip')
|
2022-04-21 17:02:23 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2022-04-21 15:34:24 +02:00
|
|
|
end
|
|
|
|
end
|
2022-11-16 11:50:19 +01:00
|
|
|
|
|
|
|
describe 'to_geo_json' do
|
2024-05-31 09:41:31 +02:00
|
|
|
let(:procedure) { create(:procedure, :published, :for_individual, types_de_champ_public:) }
|
|
|
|
let(:types_de_champ_public) { [{ type: :carte }] }
|
|
|
|
|
2022-11-16 11:50:19 +01:00
|
|
|
subject do
|
|
|
|
service
|
|
|
|
.to_geo_json
|
|
|
|
.open { |f| JSON.parse(f.read) }
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:dossier) { create(:dossier, :en_instruction, :with_populated_champs, :with_individual, procedure: procedure) }
|
|
|
|
let(:champ_carte) { dossier.champs_public.find(&:carte?) }
|
|
|
|
let(:properties) { subject['features'].first['properties'] }
|
|
|
|
|
|
|
|
before do
|
|
|
|
create(:geo_area, :polygon, champ: champ_carte)
|
|
|
|
end
|
|
|
|
|
2023-04-13 13:10:23 +02:00
|
|
|
it 'should have features' do
|
2024-07-01 15:31:32 +02:00
|
|
|
expect(subject['features'].size).to eq(3)
|
2022-11-16 11:50:19 +01:00
|
|
|
expect(properties['dossier_id']).to eq(dossier.id)
|
|
|
|
expect(properties['champ_id']).to eq(champ_carte.stable_id)
|
|
|
|
expect(properties['champ_label']).to eq(champ_carte.libelle)
|
|
|
|
end
|
|
|
|
end
|
2018-11-22 00:14:16 +01:00
|
|
|
end
|