2017-12-14 15:51:45 +01:00
describe DossierSerializer do
describe '#attributes' do
subject { DossierSerializer . new ( dossier ) . serializable_hash }
context 'when the dossier is en_construction' do
let ( :dossier ) { create ( :dossier , :en_construction ) }
2021-12-06 15:49:17 +01:00
it { is_expected . to include ( initiated_at : dossier . depose_at ) }
2017-12-14 15:51:45 +01:00
it { is_expected . to include ( state : 'initiated' ) }
end
2017-12-14 15:53:02 +01:00
context 'when the dossier is en instruction' do
let ( :dossier ) { create ( :dossier , :en_instruction ) }
it { is_expected . to include ( received_at : dossier . en_instruction_at ) }
2017-12-04 20:23:57 +01:00
end
2018-11-13 18:48:04 +01:00
context 'champs' do
subject { super ( ) [ :champs ] }
2018-11-27 15:55:14 +01:00
let ( :dossier ) { create ( :dossier , :en_construction , procedure : create ( :procedure , :published , :with_type_de_champ ) ) }
2018-11-13 18:48:04 +01:00
before do
2022-11-10 22:21:14 +01:00
dossier . champs_public << build ( :champ_carte , dossier : dossier )
dossier . champs_public << build ( :champ_siret , dossier : dossier )
dossier . champs_public << build ( :champ_integer_number , dossier : dossier )
dossier . champs_public << build ( :champ_decimal_number , dossier : dossier )
dossier . champs_public << build ( :champ_linked_drop_down_list , dossier : dossier )
2018-11-13 18:48:04 +01:00
end
it {
2018-11-27 15:55:14 +01:00
expect ( subject . size ) . to eq ( 6 )
2018-11-13 18:48:04 +01:00
expect ( subject [ 0 ] [ :type_de_champ ] [ :type_champ ] ) . to eq ( TypeDeChamp . type_champs . fetch ( :text ) )
expect ( subject [ 1 ] [ :type_de_champ ] [ :type_champ ] ) . to eq ( TypeDeChamp . type_champs . fetch ( :carte ) )
expect ( subject [ 2 ] [ :type_de_champ ] [ :type_champ ] ) . to eq ( TypeDeChamp . type_champs . fetch ( :siret ) )
expect ( subject [ 1 ] [ :geo_areas ] . size ) . to eq ( 0 )
expect ( subject [ 2 ] [ :etablissement ] ) . to be_present
expect ( subject [ 2 ] [ :entreprise ] ) . to be_present
expect ( subject [ 3 ] [ :value ] ) . to eq ( 42 )
expect ( subject [ 4 ] [ :value ] ) . to eq ( 42 . 1 )
2019-07-09 15:57:48 +02:00
expect ( subject [ 5 ] [ :value ] ) . to eq ( { primary : 'categorie 1' , secondary : 'choix 1' } )
2018-11-13 18:48:04 +01:00
}
end
2017-12-14 15:51:45 +01:00
end
2019-01-10 18:46:19 +01:00
2019-07-25 16:49:06 +02:00
context 'when a type de champ PJ was cloned from a legacy PJ' do
let ( :original_pj_id ) { 3 }
let ( :cloned_type_de_champ ) do
2022-08-04 11:39:07 +02:00
{
type : :piece_justificative ,
2019-01-10 18:46:19 +01:00
libelle : " Vidéo de votre demande de subvention " ,
2019-07-25 16:49:06 +02:00
description : " Pour optimiser vos chances, soignez la chorégraphie et privilégiez le chant polyphonique. \r \n Récupérer le formulaire vierge pour mon dossier : https://www.dance-academy.gouv.fr " ,
2022-08-04 11:39:07 +02:00
old_pj : { stable_id : original_pj_id }
}
2019-01-10 18:46:19 +01:00
end
2022-08-04 11:39:07 +02:00
let ( :procedure ) { create ( :procedure , :published , types_de_champ_public : [ cloned_type_de_champ ] ) }
2019-01-10 18:46:19 +01:00
let ( :dossier ) { create ( :dossier , procedure : procedure ) }
2022-11-10 22:21:14 +01:00
let ( :champ_pj ) { dossier . champs_public . last }
2019-01-10 18:46:19 +01:00
before do
champ_pj . piece_justificative_file . attach ( io : StringIO . new ( " toto " ) , filename : " toto.txt " , content_type : " text/plain " )
end
subject { DossierSerializer . new ( dossier ) . serializable_hash }
it " exposes the PJ in the legacy format " do
is_expected . to include (
2019-01-10 18:49:21 +01:00
types_de_piece_justificative : [
{
2019-07-25 16:49:06 +02:00
" id " = > original_pj_id ,
2022-08-04 11:39:07 +02:00
" libelle " = > cloned_type_de_champ [ :libelle ] ,
2019-07-25 16:49:06 +02:00
" description " = > 'Pour optimiser vos chances, soignez la chorégraphie et privilégiez le chant polyphonique.' ,
" lien_demarche " = > 'https://www.dance-academy.gouv.fr' ,
2022-05-25 09:51:40 +02:00
" order_place " = > 0
2019-01-10 18:49:21 +01:00
}
] ,
2019-01-10 18:46:19 +01:00
pieces_justificatives : [
{
2019-12-19 18:29:01 +01:00
" content_url " = > subject [ :pieces_justificatives ] [ 0 ] [ " content_url " ] ,
2019-01-10 18:46:19 +01:00
" created_at " = > champ_pj . created_at . in_time_zone ( 'UTC' ) . iso8601 ( 3 ) ,
2019-07-25 16:49:06 +02:00
" type_de_piece_justificative_id " = > original_pj_id ,
2019-01-10 18:46:19 +01:00
" user " = > a_hash_including ( " id " = > dossier . user . id )
}
]
)
2019-12-19 18:29:01 +01:00
expect ( subject [ :pieces_justificatives ] [ 0 ] [ " content_url " ] ) . to match ( '/rails/active_storage/disk/' )
2019-01-10 18:46:19 +01:00
end
2019-01-10 18:50:12 +01:00
it " does not expose the PJ as a champ " do
2019-07-25 16:49:06 +02:00
expect ( subject [ :champs ] ) . to be_empty
2019-01-10 18:50:12 +01:00
end
2019-01-10 18:46:19 +01:00
end
2017-12-14 15:51:45 +01:00
end