2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-06-14 13:05:19 +02:00
|
|
|
describe DemarchesPubliquesExportService do
|
2023-02-28 16:25:53 +01:00
|
|
|
let(:procedure) { create(:procedure, :published, :with_service, :with_type_de_champ, estimated_dossiers_count: 4) }
|
2022-11-24 13:16:37 +01:00
|
|
|
let!(:dossier) { create(:dossier, :en_construction, procedure: procedure) }
|
2022-07-13 10:41:22 +02:00
|
|
|
let(:gzip_filename) { "demarches.json.gz" }
|
|
|
|
|
|
|
|
after { FileUtils.rm(gzip_filename) }
|
2022-06-14 13:05:19 +02:00
|
|
|
|
|
|
|
describe 'call' do
|
|
|
|
it 'generate json for all closed procedures' do
|
|
|
|
expected_result = {
|
|
|
|
number: procedure.id,
|
|
|
|
title: procedure.libelle,
|
|
|
|
description: "Demande de subvention à l'intention des associations",
|
|
|
|
service: {
|
|
|
|
nom: procedure.service.nom,
|
|
|
|
organisme: "organisme",
|
|
|
|
typeOrganisme: "association"
|
|
|
|
},
|
2022-11-24 13:16:37 +01:00
|
|
|
cadreJuridiqueUrl: "un cadre juridique important",
|
2023-02-15 18:30:02 +01:00
|
|
|
demarcheUrl: Rails.application.routes.url_helpers.commencer_url(path: procedure.path),
|
2022-11-24 13:16:37 +01:00
|
|
|
dpoUrl: nil,
|
|
|
|
noticeUrl: nil,
|
|
|
|
siteWebUrl: "https://mon-site.gouv",
|
|
|
|
logo: nil,
|
|
|
|
notice: nil,
|
2022-06-14 13:05:19 +02:00
|
|
|
deliberation: nil,
|
|
|
|
datePublication: procedure.published_at.iso8601,
|
2022-11-24 13:16:37 +01:00
|
|
|
zones: ["Ministère de l'Education Populaire"],
|
|
|
|
tags: [],
|
2022-06-17 19:14:04 +02:00
|
|
|
dossiersCount: 1,
|
2022-06-14 13:05:19 +02:00
|
|
|
revision: {
|
|
|
|
champDescriptors: [
|
|
|
|
{
|
2022-11-16 12:46:33 +01:00
|
|
|
description: procedure.active_revision.types_de_champ_public.first.description,
|
|
|
|
label: procedure.active_revision.types_de_champ_public.first.libelle,
|
2024-06-25 17:17:51 +02:00
|
|
|
required: true,
|
2022-11-24 13:16:37 +01:00
|
|
|
__typename: "TextChampDescriptor"
|
2022-06-14 13:05:19 +02:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
2022-07-13 10:41:22 +02:00
|
|
|
DemarchesPubliquesExportService.new(gzip_filename).call
|
2022-06-14 13:05:19 +02:00
|
|
|
|
2022-07-13 10:41:22 +02:00
|
|
|
expect(JSON.parse(deflat_gzip(gzip_filename))[0]
|
2022-06-14 13:05:19 +02:00
|
|
|
.deep_symbolize_keys)
|
|
|
|
.to eq(expected_result)
|
|
|
|
end
|
2022-07-13 10:41:22 +02:00
|
|
|
|
2022-06-14 13:05:19 +02:00
|
|
|
it 'raises exception when procedure with bad data' do
|
|
|
|
procedure.libelle = nil
|
|
|
|
procedure.save(validate: false)
|
|
|
|
|
2022-07-13 10:41:22 +02:00
|
|
|
expect { DemarchesPubliquesExportService.new(gzip_filename).call }.to raise_error(DemarchesPubliquesExportService::Error)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def deflat_gzip(gzip_filename)
|
|
|
|
Zlib::GzipReader.open(gzip_filename) do |gz|
|
|
|
|
return gz.read
|
2022-06-14 13:05:19 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|