From 16c72e7478e610e1fcc76f459213e6b0e598595d Mon Sep 17 00:00:00 2001 From: Xavier J Date: Fri, 26 Feb 2016 12:17:41 +0100 Subject: [PATCH] Complete API Dossier --- app/serializers/cerfa_serializer.rb | 6 + app/serializers/champ_serializer.rb | 5 + app/serializers/dossier_serializer.rb | 6 +- .../piece_justificative_serializer.rb | 5 + app/serializers/type_de_champ_serializer.rb | 2 +- .../api/v1/dossiers_controller_spec.rb | 124 +++++++++++++----- spec/factories/type_de_champ.rb | 2 +- 7 files changed, 115 insertions(+), 35 deletions(-) create mode 100644 app/serializers/cerfa_serializer.rb create mode 100644 app/serializers/champ_serializer.rb create mode 100644 app/serializers/piece_justificative_serializer.rb diff --git a/app/serializers/cerfa_serializer.rb b/app/serializers/cerfa_serializer.rb new file mode 100644 index 000000000..54fccc911 --- /dev/null +++ b/app/serializers/cerfa_serializer.rb @@ -0,0 +1,6 @@ +class CerfaSerializer < ActiveModel::Serializer + + attributes :content_url => :url + + has_one :type_de_champ +end \ No newline at end of file diff --git a/app/serializers/champ_serializer.rb b/app/serializers/champ_serializer.rb new file mode 100644 index 000000000..5a0ba0bf3 --- /dev/null +++ b/app/serializers/champ_serializer.rb @@ -0,0 +1,5 @@ +class ChampSerializer < ActiveModel::Serializer + attributes :value + + has_one :type_de_champ +end \ No newline at end of file diff --git a/app/serializers/dossier_serializer.rb b/app/serializers/dossier_serializer.rb index dd68a55b0..b3f56395b 100644 --- a/app/serializers/dossier_serializer.rb +++ b/app/serializers/dossier_serializer.rb @@ -4,8 +4,12 @@ class DossierSerializer < ActiveModel::Serializer :description, :created_at, :updated_at, - :archived + :archived, + :mandataire_social has_one :entreprise has_one :etablissement + has_one :cerfa + has_many :champs + has_many :pieces_justificatives end \ No newline at end of file diff --git a/app/serializers/piece_justificative_serializer.rb b/app/serializers/piece_justificative_serializer.rb new file mode 100644 index 000000000..0fe9d0e10 --- /dev/null +++ b/app/serializers/piece_justificative_serializer.rb @@ -0,0 +1,5 @@ +class PieceJustificativeSerializer < ActiveModel::Serializer + attributes :content_url => :url + + has_one :type_de_piece_justificative +end \ No newline at end of file diff --git a/app/serializers/type_de_champ_serializer.rb b/app/serializers/type_de_champ_serializer.rb index 32f10627c..bbe2cb7dc 100644 --- a/app/serializers/type_de_champ_serializer.rb +++ b/app/serializers/type_de_champ_serializer.rb @@ -1,7 +1,7 @@ class TypeDeChampSerializer < ActiveModel::Serializer attributes :id, :libelle, - :type_champ, + {:type_champ => :type}, :order_place, :description end \ No newline at end of file diff --git a/spec/controllers/api/v1/dossiers_controller_spec.rb b/spec/controllers/api/v1/dossiers_controller_spec.rb index 82fdbc300..d463fcaea 100644 --- a/spec/controllers/api/v1/dossiers_controller_spec.rb +++ b/spec/controllers/api/v1/dossiers_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' describe API::V1::DossiersController do let(:admin) { create(:administrateur) } - let(:procedure) { create(:procedure, administrateur: admin) } + let(:procedure) { create(:procedure, :with_two_type_de_piece_justificative, :with_type_de_champ, administrateur: admin) } let(:wrong_procedure) { create(:procedure) } it { expect(described_class).to be < APIController } @@ -114,7 +114,7 @@ describe API::V1::DossiersController do let!(:dossier) { Timecop.freeze(date_creation) { create(:dossier, :with_entreprise, procedure: procedure) } } let(:dossier_id) { dossier.id } let(:body) { JSON.parse(response.body, symbolize_names: true) } - let(:field_list) { [:id, :nom_projet, :created_at, :updated_at, :description, :archived, :entreprise, :etablissement] } + let(:field_list) { [:id, :nom_projet, :created_at, :updated_at, :description, :archived, :mandataire_social, :entreprise, :etablissement] } subject { body[:dossier] } it { expect(response.code).to eq('200') } @@ -124,28 +124,30 @@ describe API::V1::DossiersController do it { expect(subject[:updated_at]).to eq('2008-09-01T08:05:00.000Z') } it { expect(subject[:description]).to eq(dossier.description) } it { expect(subject[:archived]).to eq(dossier.archived) } + it { expect(subject[:mandataire_social]).to eq(dossier.mandataire_social) } + it { expect(subject.keys).to match_array(field_list) } describe 'entreprise' do let(:field_list) { [ - :siren, - :capital_social, - :numero_tva_intracommunautaire, - :forme_juridique, - :forme_juridique_code, - :nom_commercial, - :raison_sociale, - :siret_siege_social, - :code_effectif_entreprise, - :date_creation, - :nom, - :prenom] } - subject { super()[:entreprise]} + :siren, + :capital_social, + :numero_tva_intracommunautaire, + :forme_juridique, + :forme_juridique_code, + :nom_commercial, + :raison_sociale, + :siret_siege_social, + :code_effectif_entreprise, + :date_creation, + :nom, + :prenom] } + subject { super()[:entreprise] } - it { expect(subject[:siren]).to eq('440117620')} - it { expect(subject[:capital_social]).to eq(537_100_000)} - it { expect(subject[:numero_tva_intracommunautaire]).to eq('FR27440117620')} - it { expect(subject[:forme_juridique]).to eq('SA à conseil d\'administration (s.a.i.)')} + it { expect(subject[:siren]).to eq('440117620') } + it { expect(subject[:capital_social]).to eq(537_100_000) } + it { expect(subject[:numero_tva_intracommunautaire]).to eq('FR27440117620') } + it { expect(subject[:forme_juridique]).to eq('SA à conseil d\'administration (s.a.i.)') } it { expect(subject[:forme_juridique_code]).to eq('5599') } it { expect(subject[:nom_commercial]).to eq('GRTGAZ') } it { expect(subject[:raison_sociale]).to eq('GRTGAZ') } @@ -155,22 +157,80 @@ describe API::V1::DossiersController do it { expect(subject.keys).to match_array(field_list) } end + describe 'pieces_justificatives' do + let(:field_list) { [ + :url] } + subject { super()[:pieces_justificatives] } + + it { expect(subject.length).to eq 2 } + + describe 'first piece justificative' do + subject { super().first } + + it { expect(subject.keys.include?(:url)).to be_truthy } + it { expect(subject.keys.include?(:type_de_piece_justificative)).to be_truthy } + + describe 'type de piece justificative' do + let(:field_list) { [ + :id, + :libelle, + :description] } + subject { super()[:type_de_piece_justificative] } + + it { expect(subject.keys.include?(:id)).to be_truthy } + it { expect(subject[:libelle]).to eq('RIB') } + it { expect(subject[:description]).to eq('Releve identité bancaire') } + end + end + end + + describe 'champs' do + let(:field_list) { [ + :url] } + subject { super()[:champs] } + + it { expect(subject.length).to eq 1 } + + describe 'first champs' do + subject { super().first } + + it { expect(subject.keys.include?(:value)).to be_truthy } + it { expect(subject.keys.include?(:type_de_champ)).to be_truthy } + + describe 'type de champ' do + let(:field_list) { [ + :id, + :libelle, + :description, + :order_place, + :type] } + subject { super()[:type_de_champ] } + + it { expect(subject.keys.include?(:id)).to be_truthy } + it { expect(subject[:libelle]).to eq('Description') } + it { expect(subject[:description]).to eq('description de votre projet') } + it { expect(subject.keys.include?(:order_place)).to be_truthy } + it { expect(subject[:type]).to eq('textarea') } + end + end + end + describe 'etablissement' do let(:field_list) { [ - :siret, - :siege_social, - :naf, - :libelle_naf, - :adresse, - :numero_voie, - :type_voie, - :nom_voie, - :complement_adresse, - :code_postal, - :localite, - :code_insee_localite + :siret, + :siege_social, + :naf, + :libelle_naf, + :adresse, + :numero_voie, + :type_voie, + :nom_voie, + :complement_adresse, + :code_postal, + :localite, + :code_insee_localite ] } - subject { super()[:etablissement]} + subject { super()[:etablissement] } it { expect(subject[:siret]).to eq('44011762001530') } it { expect(subject[:siege_social]).to eq(true) } diff --git a/spec/factories/type_de_champ.rb b/spec/factories/type_de_champ.rb index 2eee3b273..45b0f69e2 100644 --- a/spec/factories/type_de_champ.rb +++ b/spec/factories/type_de_champ.rb @@ -1,6 +1,6 @@ FactoryGirl.define do factory :type_de_champ do - libelle 'Libellé' + libelle 'Description' description 'description de votre projet' type_champ 'textarea' order_place 1