#3698 Validation du champ SIRET (il doit comporter exactement 14 chiffres)

Fix #3692
This commit is contained in:
Frederic Merizen 2019-03-28 18:13:21 +01:00 committed by GitHub
commit 2b2b8e0ad5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 1 deletions

View file

@ -2,4 +2,8 @@ class Champs::SiretChamp < Champ
def search_terms
etablissement.present? ? etablissement.search_terms : [value]
end
def mandatory_and_blank?
mandatory? && Siret.new(siret: value).invalid?
end
end

View file

@ -2,7 +2,9 @@
placeholder: champ.libelle,
class: 'small-margin',
data: { remote: true, debounce: true, url: champs_siret_path(form.index), params: { champ_id: champ&.id }.to_query, spinner: true },
required: champ.mandatory?
required: champ.mandatory?,
pattern: "[0-9]{14}",
title: "Le numéro de SIRET doit comporter exactement 14 chiffres"
.spinner.right-spinner.hidden
%div{ class: "siret-info-#{form.index}" }
- if champ.etablissement.present?

View file

@ -858,6 +858,33 @@ describe Dossier do
end
end
context "with mandatory SIRET champ" do
let(:type_de_champ) { create(:type_de_champ_siret, mandatory: true) }
let(:champ_siret) { create(:champ_siret, type_de_champ: type_de_champ) }
before do
dossier.champs << champ_siret
end
it 'should not have errors' do
errors = dossier.check_mandatory_champs
expect(errors).to be_empty
end
context "and invalid SIRET" do
before do
champ_siret.update(value: "1234")
dossier.reload
end
it 'should have errors' do
errors = dossier.check_mandatory_champs
expect(errors).not_to be_empty
expect(errors.first).to eq("Le champ #{champ_siret.libelle} doit être rempli.")
end
end
end
context "with champ repetition" do
let(:procedure) { create(:procedure) }
let(:type_de_champ_repetition) { create(:type_de_champ_repetition, mandatory: true) }