Merge pull request #8339 from mfo/US/fix-departement-champs

Us/fix departement champs
This commit is contained in:
mfo 2022-12-27 16:01:35 +01:00 committed by GitHub
commit 31735e16d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 49 additions and 4 deletions

View file

@ -262,6 +262,7 @@ class Champ < ApplicationRecord
def normalize def normalize
return if value.nil? return if value.nil?
return if value.present? && !value.include?("\u0000")
self.value = value.delete("\u0000") self.value = value.delete("\u0000")
end end

View file

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

View file

@ -120,6 +120,10 @@ describe API::V1::DossiersController do
end end
describe 'GET show' do 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 } } let(:retour) { get :show, params: { token: token, procedure_id: procedure_id, id: dossier_id } }
subject { retour } subject { retour }
@ -254,6 +258,18 @@ describe API::V1::DossiersController do
end end
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 describe 'repetition' do
let(:procedure) { create(:procedure, :with_repetition, administrateur: admin) } let(:procedure) { create(:procedure, :with_repetition, administrateur: admin) }
let(:dossier) { create(:dossier, :en_construction, :with_populated_champs, procedure: procedure) } let(:dossier) { create(:dossier, :en_construction, :with_populated_champs, procedure: procedure) }

View file

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

View file

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

View file

@ -199,6 +199,12 @@ FactoryBot.define do
end end
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 trait :with_piece_justificative do
after(:build) do |procedure, _evaluator| after(:build) do |procedure, _evaluator|
build(:type_de_champ_piece_justificative, procedure: procedure) build(:type_de_champ_piece_justificative, procedure: procedure)

View file

@ -9,7 +9,10 @@ describe '20220705164551_remove_unused_champs' do
rake_task.invoke rake_task.invoke
end 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 } after { rake_task.reenable }
describe 'remove_unused_champs' do describe 'remove_unused_champs' do

View file

@ -9,7 +9,7 @@ describe Champs::DepartementChamp, type: :model do
let(:champ) { described_class.new } let(:champ) { described_class.new }
describe 'value', vcr: { cassette_name: 'api_geo_departements' } do describe 'value', vcr: { cassette_name: 'api_geo_departements' } do
it 'with code' do it 'with code having 2 chars' do
champ.value = '01' champ.value = '01'
expect(champ.external_id).to eq('01') expect(champ.external_id).to eq('01')
expect(champ.code).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') expect(champ.to_s).to eq('01 Ain')
end 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 it 'with nil' do
champ.write_attribute(:value, 'Ain') champ.write_attribute(:value, 'Ain')
champ.write_attribute(:external_id, '01') champ.write_attribute(:external_id, '01')

View file

@ -1669,6 +1669,7 @@ describe Dossier do
end end
describe "#destroy" do 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(:procedure) { create(:procedure, :with_all_champs, :with_all_annotations) }
let(:transfer) { create(:dossier_transfer) } let(:transfer) { create(:dossier_transfer) }
let(:dossier) { create(:dossier, :with_populated_champs, :with_populated_annotations, transfer: transfer, procedure: procedure) } 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 describe ProcedureExportService do
let(:procedure) { create(:procedure, :published, :for_individual, :with_all_champs) } let(:procedure) { create(:procedure, :published, :for_individual, :with_all_champs) }
let(:service) { ProcedureExportService.new(procedure, procedure.dossiers) } 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 describe 'to_xlsx' do
subject do subject do