diff --git a/app/models/champs/departement_champ.rb b/app/models/champs/departement_champ.rb index f197a58c4..ef86957ca 100644 --- a/app/models/champs/departement_champ.rb +++ b/app/models/champs/departement_champ.rb @@ -33,6 +33,10 @@ class Champs::DepartementChamp < Champs::TextChamp formatted_value end + def for_api + formatted_value + end + def selected code end diff --git a/spec/controllers/api/v1/dossiers_controller_spec.rb b/spec/controllers/api/v1/dossiers_controller_spec.rb index 81f0f02b7..af705addd 100644 --- a/spec/controllers/api/v1/dossiers_controller_spec.rb +++ b/spec/controllers/api/v1/dossiers_controller_spec.rb @@ -120,6 +120,10 @@ describe API::V1::DossiersController do end describe 'GET show' do + before do + allow(APIGeoService).to receive(:departement_name).with('01').and_return('Ain') + end + let(:retour) { get :show, params: { token: token, procedure_id: procedure_id, id: dossier_id } } subject { retour } @@ -254,6 +258,18 @@ describe API::V1::DossiersController do end end + describe 'departement' do + let(:procedure) { create(:procedure, :with_departement, administrateur: admin) } + let(:dossier) { create(:dossier, :en_construction, :with_populated_champs, procedure: procedure) } + + subject { super() } + + it 'should have rows' do + expect(subject.size).to eq(1) + expect(subject.first[:value]).to eq("01 – Ain") + end + end + describe 'repetition' do let(:procedure) { create(:procedure, :with_repetition, administrateur: admin) } let(:dossier) { create(:dossier, :en_construction, :with_populated_champs, procedure: procedure) } diff --git a/spec/factories/procedure.rb b/spec/factories/procedure.rb index cd947cf18..2af349302 100644 --- a/spec/factories/procedure.rb +++ b/spec/factories/procedure.rb @@ -199,6 +199,12 @@ FactoryBot.define do end end + trait :with_departement do + after(:build) do |procedure, _evaluator| + build(:type_de_champ_departements, procedure: procedure) + end + end + trait :with_piece_justificative do after(:build) do |procedure, _evaluator| build(:type_de_champ_piece_justificative, procedure: procedure)