[#10837] Add an explicit message when SIRET is not valid on service

This commit is contained in:
Mathieu Magnin 2024-09-20 15:21:22 +02:00
parent 28b8c8bf84
commit e9b5c4a615
No known key found for this signature in database
GPG key ID: 8DCAFC82D7BA654E
4 changed files with 14 additions and 4 deletions

View file

@ -674,7 +674,7 @@ class Procedure < ApplicationRecord
result << :service
end
if service_test?
if service_siret_test?
result << :service
end
@ -710,7 +710,7 @@ class Procedure < ApplicationRecord
end
end
def service_test?
def service_siret_test?
service&.siret == Service::SIRET_TEST
end

View file

@ -22,6 +22,7 @@ class Service < ApplicationRecord
validates :nom, uniqueness: { scope: :administrateur, message: 'existe déjà' }
validates :organisme, presence: { message: 'doit être renseigné' }, allow_nil: false
validates :siret, siret_format: true
validates :siret, comparison: { other_than: SIRET_TEST, message: "n'est pas valide" }, on: :update
validates :type_organisme, presence: { message: 'doit être renseigné' }, allow_nil: false
validates :email, presence: { message: 'doit être renseigné' }, allow_nil: false
validates :telephone, phone: { possible: true, allow_blank: true }

View file

@ -46,8 +46,8 @@
%li= link_to("des instructeurs", admin_procedure_groupe_instructeur_path(@procedure, @procedure.defaut_groupe_instructeur))
- if @procedure.service.nil?
%li= link_to("un service", admin_services_path(procedure_id: @procedure))
- if @procedure.service_test?
%li= link_to("un service valide", admin_services_path(procedure_id: @procedure))
- if @procedure.service_siret_test?
%li= link_to("un service avec un SIRET valide", admin_services_path(procedure_id: @procedure))
= link_to t('.back_to_procedure'), admin_procedure_path(id: @procedure), class: 'fr-btn fr-btn--secondary fr-btn--icon-left fr-icon-arrow-go-back-line fr-mt-2w'
- else

View file

@ -89,6 +89,15 @@ describe Service, type: :model do
end
end
describe 'validation on update' do
subject { create(:service) }
it 'should not allow to have a test siret' do
subject.siret = Service::SIRET_TEST
expect(subject).not_to be_valid
end
end
describe "etablissement adresse & geo coordinates" do
subject { create(:service, etablissement_lat: latitude, etablissement_lng: longitude, etablissement_infos: etablissement_infos) }