review: detailled error message
This commit is contained in:
parent
2ad4e4c01f
commit
30eef3e128
6 changed files with 43 additions and 10 deletions
|
@ -5,7 +5,8 @@ module SiretChampEtablissementFetchableConcern
|
|||
|
||||
def fetch_etablissement!(siret, user)
|
||||
return clear_etablissement!(:empty) if siret.empty?
|
||||
return clear_etablissement!(:invalid) unless Siret.new(siret: siret).valid? # i18n-tasks-use t('errors.messages.invalid_siret')
|
||||
return clear_etablissement!(:invalid_length) if invalid_because?(siret, :length) # i18n-tasks-use t('errors.messages.invalid_siret_length')
|
||||
return clear_etablissement!(:invalid_checksum) if invalid_because?(siret, :checksum) # i18n-tasks-use t('errors.messages.invalid_siret_checksum')
|
||||
return clear_etablissement!(:not_found) unless (etablissement = APIEntrepriseService.create_etablissement(self, siret, user&.id)) # i18n-tasks-use t('errors.messages.siret_not_found')
|
||||
|
||||
update!(value: siret, etablissement: etablissement)
|
||||
|
@ -35,4 +36,11 @@ module SiretChampEtablissementFetchableConcern
|
|||
|
||||
false
|
||||
end
|
||||
|
||||
def invalid_because?(siret, criteria)
|
||||
validatable_siret = Siret.new(siret: siret)
|
||||
return false if validatable_siret.valid?
|
||||
|
||||
validatable_siret.errors.details[:siret].any? && validatable_siret.errors.details[:siret].first[:error] == criteria
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
- case siret
|
||||
- when :invalid
|
||||
Le numéro de SIRET doit comporter exactement 14 chiffres.
|
||||
- when :invalid_length
|
||||
= t('errors.messages.invalid_siret_length')
|
||||
|
||||
- when :invalid_checksum
|
||||
= t('errors.messages.invalid_siret_checksum')
|
||||
|
||||
- when :not_found
|
||||
Nous n’avons pas trouvé d’établissement correspondant à ce numéro de SIRET.
|
||||
|
|
|
@ -155,7 +155,7 @@ en:
|
|||
date: "2023-02-01"
|
||||
datetime: "2023-02-01T10:30"
|
||||
checkbox: "true"
|
||||
siret: 828212345600023
|
||||
siret: 13002526500013
|
||||
prefill_link_title: Prefill link (GET)
|
||||
prefill_link_info: Use the button to copy the link, then remplace the values with your data.
|
||||
prefill_link_too_long: Warning, the prefill link is too long and may not work on all browsers.
|
||||
|
@ -511,7 +511,8 @@ en:
|
|||
dossier_not_found: "The file does not exist or you do not have access to it."
|
||||
# # dossier_map_not_activated: "The file does not have access to the map."
|
||||
targeted_user_link_expired: "This invitation link or the file is no longer available."
|
||||
invalid_siret: "The SIRET is incorrect"
|
||||
invalid_siret_length: "The SIRET number must contain exactly 14 numbers."
|
||||
invalid_siret_checksum: "The SIRET number is invalid."
|
||||
procedure_not_found: "The procedure does not exist"
|
||||
siret_unknown: 'Sorry, we did not find any establishment registered under this SIRET number.'
|
||||
siret_network_error: 'Désolé, la récupération des informations SIRET est temporairement indisponible. Veuillez réessayer dans quelques instants.'
|
||||
|
|
|
@ -147,7 +147,7 @@ fr:
|
|||
date: "2023-02-01"
|
||||
datetime: "2023-02-01T10:30"
|
||||
checkbox: "true"
|
||||
siret: 82812345600023
|
||||
siret: 13002526500013
|
||||
prefill_link_title: Lien de préremplissage (GET)
|
||||
prefill_link_info: Copiez le lien grâce au bouton ci-dessous et remplacez les valeurs par les données dont vous disposez.
|
||||
prefill_link_too_long: Attention, ce lien de préremplissage est trop long et risque de ne pas fonctionner sur certains navigateurs.
|
||||
|
@ -507,7 +507,8 @@ fr:
|
|||
dossier_not_found: "Le dossier n’existe pas ou vous n’y avez pas accès."
|
||||
# dossier_map_not_activated: "Le dossier n’a pas accès à la cartographie."
|
||||
targeted_user_link_expired: "Ce lien d’invitation n’est plus valable ou le dossier n’est plus accessible."
|
||||
invalid_siret: "Le siret est incorrect"
|
||||
invalid_siret_length: "Le numéro de SIRET doit comporter exactement 14 chiffres."
|
||||
invalid_siret_checksum: "Le format du numéro de SIRET est invalide."
|
||||
procedure_not_found: "La démarche n’existe pas"
|
||||
siret_unknown: 'Désolé, nous n’avons pas trouvé d’établissement enregistré correspondant à ce numéro SIRET.'
|
||||
siret_network_error: 'Désolé, la récupération des informations SIRET est temporairement indisponible. Veuillez réessayer dans quelques instants.'
|
||||
|
|
|
@ -48,7 +48,7 @@ describe Champs::SiretController, type: :controller do
|
|||
end
|
||||
end
|
||||
|
||||
context 'when the SIRET is invalid' do
|
||||
context "when the SIRET is invalid because of it's length" do
|
||||
let(:siret) { '1234' }
|
||||
|
||||
subject! { get :show, params: params, format: :turbo_stream }
|
||||
|
@ -62,6 +62,20 @@ describe Champs::SiretController, type: :controller do
|
|||
end
|
||||
end
|
||||
|
||||
context "when the SIRET is invalid because of it's checksum" do
|
||||
let(:siret) { '82812345600023' }
|
||||
|
||||
subject! { get :show, params: params, format: :turbo_stream }
|
||||
|
||||
it 'clears the etablissement on the model' do
|
||||
expect(champ.reload.etablissement).to be_nil
|
||||
end
|
||||
|
||||
it 'displays a “SIRET is invalid” error message' do
|
||||
expect(response.body).to include('Le format du numéro de SIRET est invalide.')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the API is unavailable due to network error' do
|
||||
let(:siret) { '82161143100015' }
|
||||
let(:api_etablissement_status) { 503 }
|
||||
|
|
|
@ -34,10 +34,16 @@ RSpec.describe SiretChampEtablissementFetchableConcern do
|
|||
it_behaves_like 'an error occured', :empty
|
||||
end
|
||||
|
||||
context 'when the SIRET is invalid' do
|
||||
context "when the SIRET is invalid because of it's length" do
|
||||
let(:siret) { '1234' }
|
||||
|
||||
it_behaves_like 'an error occured', :invalid
|
||||
it_behaves_like 'an error occured', :invalid_length
|
||||
end
|
||||
|
||||
context "when the SIRET is invalid because of it's checksum" do
|
||||
let(:siret) { '82812345600023' }
|
||||
|
||||
it_behaves_like 'an error occured', :invalid_checksum
|
||||
end
|
||||
|
||||
context 'when the API is unavailable due to network error' do
|
||||
|
|
Loading…
Reference in a new issue