correctif(ChampDepartement): gere les departement a 3 codes

This commit is contained in:
Martin 2022-12-27 12:10:50 +01:00
parent 48c80e9387
commit 186d4e6539
7 changed files with 22 additions and 4 deletions

View file

@ -55,7 +55,7 @@ class Champs::DepartementChamp < Champs::TextChamp
end
def value=(code)
if code&.size == 2
if [2, 3].include?(code&.size)
self.external_id = code
super(APIGeoService.departement_name(code))
elsif code.blank?

View file

@ -37,6 +37,7 @@ describe API::V2::GraphqlController do
end
before do
allow(APIGeoService).to receive(:departement_name).with('01').and_return('Ain')
instructeur.assign_to_procedure(procedure)
end

View file

@ -117,7 +117,7 @@ FactoryBot.define do
factory :champ_departements, class: 'Champs::DepartementChamp' do
type_de_champ { association :type_de_champ_departements, procedure: dossier.procedure }
value { '971 - Guadeloupe' }
value { '01' }
end
factory :champ_communes, class: 'Champs::CommuneChamp' do

View file

@ -9,7 +9,10 @@ describe '20220705164551_remove_unused_champs' do
rake_task.invoke
end
before { champ_repetition.champs.first.update(type_de_champ: create(:type_de_champ)) }
before do
allow(APIGeoService).to receive(:departement_name).with('01').and_return('Ain')
champ_repetition.champs.first.update(type_de_champ: create(:type_de_champ))
end
after { rake_task.reenable }
describe 'remove_unused_champs' do

View file

@ -9,7 +9,7 @@ describe Champs::DepartementChamp, type: :model do
let(:champ) { described_class.new }
describe 'value', vcr: { cassette_name: 'api_geo_departements' } do
it 'with code' do
it 'with code having 2 chars' do
champ.value = '01'
expect(champ.external_id).to eq('01')
expect(champ.code).to eq('01')
@ -19,6 +19,16 @@ describe Champs::DepartementChamp, type: :model do
expect(champ.to_s).to eq('01 Ain')
end
it 'with code having 3 chars' do
champ.value = '971'
expect(champ.external_id).to eq('971')
expect(champ.code).to eq('971')
expect(champ.name).to eq('Guadeloupe')
expect(champ.value).to eq('Guadeloupe')
expect(champ.selected).to eq('971')
expect(champ.to_s).to eq('971 Guadeloupe')
end
it 'with nil' do
champ.write_attribute(:value, 'Ain')
champ.write_attribute(:external_id, '01')

View file

@ -1669,6 +1669,7 @@ describe Dossier do
end
describe "#destroy" do
before { allow(APIGeoService).to receive(:departement_name).with('01').and_return('Ain') }
let(:procedure) { create(:procedure, :with_all_champs, :with_all_annotations) }
let(:transfer) { create(:dossier_transfer) }
let(:dossier) { create(:dossier, :with_populated_champs, :with_populated_annotations, transfer: transfer, procedure: procedure) }

View file

@ -3,6 +3,9 @@ require 'csv'
describe ProcedureExportService do
let(:procedure) { create(:procedure, :published, :for_individual, :with_all_champs) }
let(:service) { ProcedureExportService.new(procedure, procedure.dossiers) }
before do
allow(APIGeoService).to receive(:departement_name).with('01').and_return('Ain')
end
describe 'to_xlsx' do
subject do