From 63519f04c8c2f3c3672af649f80736de52ee7600 Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Thu, 10 Jan 2019 18:49:21 +0100 Subject: [PATCH] [#2180] Expose migrated types PJ as legacy type PJ in dossier API --- app/serializers/dossier_serializer.rb | 5 +++++ spec/serializers/dossier_serializer_spec.rb | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/app/serializers/dossier_serializer.rb b/app/serializers/dossier_serializer.rb index dbc3f90e9..3737fd608 100644 --- a/app/serializers/dossier_serializer.rb +++ b/app/serializers/dossier_serializer.rb @@ -52,6 +52,11 @@ class DossierSerializer < ActiveModel::Serializer PiecesJustificativesService.serialize_champs_as_pjs(object) end + def types_de_piece_justificative + ActiveModelSerializers::SerializableResource.new(object.types_de_piece_justificative).serializable_hash + + PiecesJustificativesService.serialize_types_de_champ_as_type_pj(object) + end + def email object.user&.email end diff --git a/spec/serializers/dossier_serializer_spec.rb b/spec/serializers/dossier_serializer_spec.rb index 730ea1e56..ac9b7bc97 100644 --- a/spec/serializers/dossier_serializer_spec.rb +++ b/spec/serializers/dossier_serializer_spec.rb @@ -65,6 +65,7 @@ describe DossierSerializer do end let(:type_pj) { original_procedure.types_de_piece_justificative.first } + let(:migrated_type_champ) { procedure.types_de_champ.find_by(libelle: type_pj.libelle) } let(:dossier) { create(:dossier, procedure: procedure) } let(:champ_pj) { dossier.champs.last } @@ -76,6 +77,15 @@ describe DossierSerializer do it "exposes the PJ in the legacy format" do is_expected.to include( + types_de_piece_justificative: [ + { + "id" => type_pj.id, + "libelle" => type_pj.libelle, + "description" => type_pj.description, + "lien_demarche" => type_pj.lien_demarche, + "order_place" => type_pj.order_place + } + ], pieces_justificatives: [ { "content_url" => champ_pj.for_api,