2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-30 11:18:43 +02:00
|
|
|
describe Individual do
|
2016-12-20 17:01:16 +01:00
|
|
|
it { is_expected.to have_db_column(:gender) }
|
2016-08-30 11:18:43 +02:00
|
|
|
it { is_expected.to have_db_column(:nom) }
|
|
|
|
it { is_expected.to have_db_column(:prenom) }
|
2020-07-20 16:53:25 +02:00
|
|
|
it { is_expected.to belong_to(:dossier).required }
|
2018-02-26 12:01:28 +01:00
|
|
|
|
2018-03-20 16:00:30 +01:00
|
|
|
describe "#save" do
|
2018-02-26 12:01:28 +01:00
|
|
|
let(:individual) { build(:individual) }
|
|
|
|
|
2024-04-25 17:44:28 +02:00
|
|
|
subject do
|
|
|
|
individual.save
|
|
|
|
individual
|
|
|
|
end
|
2018-02-26 12:01:28 +01:00
|
|
|
|
|
|
|
context "with birthdate" do
|
|
|
|
before do
|
|
|
|
individual.birthdate = birthdate_from_user
|
|
|
|
end
|
|
|
|
|
|
|
|
context "and the format is dd/mm/yyy " do
|
|
|
|
let(:birthdate_from_user) { "12/11/1980" }
|
|
|
|
|
2024-04-25 17:44:28 +02:00
|
|
|
it { expect(subject.birthdate).to eq(Date.new(1980, 11, 12)) }
|
2018-02-26 12:01:28 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context "and the format is ISO" do
|
|
|
|
let(:birthdate_from_user) { "1980-11-12" }
|
|
|
|
|
2024-04-25 17:44:28 +02:00
|
|
|
it { expect(subject.birthdate).to eq(Date.new(1980, 11, 12)) }
|
2018-02-26 12:01:28 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context "and the format is WTF" do
|
|
|
|
let(:birthdate_from_user) { "1980 1 12" }
|
|
|
|
|
2024-04-25 17:44:28 +02:00
|
|
|
it { expect(subject.birthdate).to be_nil }
|
2018-02-26 12:01:28 +01:00
|
|
|
end
|
|
|
|
end
|
2023-11-27 15:52:55 +01:00
|
|
|
|
2024-04-25 17:57:55 +02:00
|
|
|
it "schedule index search terms" do
|
|
|
|
subject.dossier.debounce_index_search_terms_flag.remove
|
|
|
|
assert_enqueued_jobs(1, only: DossierIndexSearchTermsJob) do
|
|
|
|
individual.update(nom: "new name")
|
2023-11-27 15:52:55 +01:00
|
|
|
end
|
|
|
|
end
|
2018-02-26 12:01:28 +01:00
|
|
|
end
|
2024-04-25 17:44:28 +02:00
|
|
|
|
2024-07-29 17:21:49 +02:00
|
|
|
describe 'validate_mandant_email' do
|
|
|
|
let(:user) { create(:user, email: 'mandataire@example.com') }
|
|
|
|
let(:dossier) { create(:dossier, :for_tiers_with_notification, user: user) }
|
|
|
|
let(:individual) { dossier.individual }
|
2024-04-25 17:44:28 +02:00
|
|
|
|
2024-07-29 17:21:49 +02:00
|
|
|
context 'when validating email' do
|
|
|
|
it 'is valid when email is different from the mandataire' do
|
|
|
|
individual.email = 'different@example.com'
|
|
|
|
expect(individual).to be_valid
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is invalid when email is the same as the mandataire' do
|
|
|
|
individual.email = 'mandataire@example.com'
|
|
|
|
expect(individual).not_to be_valid
|
|
|
|
expect(individual.errors[:email]).to include(
|
|
|
|
I18n.t('activerecord.errors.models.individual.attributes.email.must_be_different_from_mandataire')
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is valid when email is not required (notification_method is not email)' do
|
|
|
|
dossier_without_notification = create(:dossier, :for_tiers_without_notification, user: user)
|
|
|
|
individual_without_notification = dossier_without_notification.individual
|
|
|
|
|
|
|
|
expect(individual_without_notification).to be_valid
|
|
|
|
expect(individual_without_notification.email).to be_nil
|
|
|
|
expect(individual_without_notification.notification_method).to eq('no_notification')
|
|
|
|
end
|
2024-04-25 17:44:28 +02:00
|
|
|
end
|
|
|
|
end
|
2016-08-30 11:18:43 +02:00
|
|
|
end
|