diff --git a/spec/controllers/users/dossiers_controller_spec.rb b/spec/controllers/users/dossiers_controller_spec.rb index d26cd5167..196507157 100644 --- a/spec/controllers/users/dossiers_controller_spec.rb +++ b/spec/controllers/users/dossiers_controller_spec.rb @@ -200,6 +200,33 @@ describe Users::DossiersController, type: :controller do expect(flash[:alert]).to include("Le champ « Civilité » doit être rempli", "Le champ « Nom » doit être rempli", "Le champ « Prénom » doit être rempli") end end + + context 'when a dossier is in broullon, for_tiers and we want to update the individual' do + let(:dossier) { create(:dossier, :for_tiers_without_notification, state: "brouillon", user: user, procedure: procedure) } + let(:dossier_params) { { individual_attributes: { gender: 'M', nom: 'Mouse', prenom: 'Mickey', email: 'mickey@gmail.com', notification_method: 'email' } } } + + it 'updates the individual with valid notification_method' do + dossier.reload + individual = dossier.individual.reload + expect(individual.errors.full_messages).to be_empty + expect(individual.notification_method).to eq('email') + expect(individual.email).to eq('mickey@gmail.com') + expect(response).to redirect_to(brouillon_dossier_path(dossier)) + end + + context 'when we want to change the mandataire' do + let(:dossier_params) { { mandataire_first_name: "Jean", mandataire_last_name: "Dupont" } } + + it 'updates the dossier mandataire first and last name' do + dossier.reload + individual = dossier.individual.reload + expect(dossier.errors.full_messages).to be_empty + expect(dossier.mandataire_first_name).to eq('Jean') + expect(dossier.mandataire_last_name).to eq('Dupont') + expect(dossier.mandataire_full_name).to eq('Jean Dupont') + end + end + end end describe '#siret' do diff --git a/spec/models/individual_spec.rb b/spec/models/individual_spec.rb index d41c85f1d..64820f03d 100644 --- a/spec/models/individual_spec.rb +++ b/spec/models/individual_spec.rb @@ -33,5 +33,15 @@ describe Individual do it { expect(individual.birthdate).to be_nil } end end + + context 'when an individual has an invalid notification_method' do + let(:invalid_individual) { build(:individual, notification_method: 'invalid_method') } + + it 'raises an ArgumentError' do + expect { + invalid_individual.valid? + }.to raise_error(ArgumentError, "'invalid_method' is not a valid notification_method") + end + end end end diff --git a/spec/system/users/dossier_creation_spec.rb b/spec/system/users/dossier_creation_spec.rb index 2e026843a..4bfa82c6d 100644 --- a/spec/system/users/dossier_creation_spec.rb +++ b/spec/system/users/dossier_creation_spec.rb @@ -22,8 +22,8 @@ describe 'Creating a new dossier:' do expect(page).to have_title(libelle) find('label', text: 'Monsieur').click - fill_in('dossier[individual_attributes][prenom]', with: 'prenom', visible: true) - fill_in('dossier[individual_attributes][nom]', with: 'prenom', visible: true) + fill_in('indiv_first_name', with: 'prenom') + fill_in('indiv_last_name', with: 'nom') end shared_examples 'the user can create a new draft' do @@ -62,6 +62,44 @@ describe 'Creating a new dossier:' do end end + context 'when identifying as mandataire' do + let(:libelle) { "[title] with characters to escape : '@*^$" } + let(:procedure) { create(:procedure, :published, :for_individual, :with_service, ask_birthday: ask_birthday, libelle: libelle) } + let(:ask_birthday) { false } + let(:expected_birthday) { nil } + + before do + visit commencer_path(path: procedure.path) + click_on 'Commencer la démarche' + + expect(page).to have_current_path identite_dossier_path(user.reload.dossiers.last) + expect(page).to have_title(libelle) + + find('#radio-tiers-manage').click + fill_in('mandataire_first_name', with: 'John') + fill_in('mandataire_last_name', with: 'Doe') + + find('label', text: 'Monsieur').click + fill_in('indiv_first_name', with: 'prenom') + fill_in('indiv_last_name', with: 'nom') + end + + it 'completes the form with email notification method selected' do + find('#notification_method_email').click + fill_in('dossier_individual_attributes_email', with: 'prenom.nom@mail.com') + click_button('Continuer') + expect(procedure.dossiers.last.individual.notification_method == 'email') + expect(page).to have_current_path(brouillon_dossier_path(procedure.dossiers.last)) + end + + it 'completes the form with no notification method selected' do + find('#notification_method_no_notification').click + click_button('Continuer') + expect(procedure.dossiers.last.individual.notification_method.empty?) + expect(page).to have_current_path(brouillon_dossier_path(procedure.dossiers.last)) + end + end + context 'when identifying through SIRET' do let(:procedure) { create(:procedure, :published, :with_service, :with_type_de_champ) } let(:dossier) { procedure.dossiers.last } diff --git a/spec/system/users/list_dossiers_spec.rb b/spec/system/users/list_dossiers_spec.rb index c00436d63..18b5d4208 100644 --- a/spec/system/users/list_dossiers_spec.rb +++ b/spec/system/users/list_dossiers_spec.rb @@ -58,6 +58,14 @@ describe 'user access to the list of their dossiers', js: true do end end + context 'when the dossier is for_tiers' do + let(:dossier) { create(:dossier, :for_tiers_without_notification, user: user) } + let(:individual) { dossier.individual } + it 'displays the name of the mandataire' do + expect(page).to have_content("#{individual.prenom} #{individual.nom}, dossier rempli par le mandataire #{dossier.mandataire_full_name}") + end + end + context 'when user uses filter' do scenario 'user filters state on tab "en-cours"' do expect(page).to have_text('5 en cours') diff --git a/spec/views/users/dossiers/brouillon.html.haml_spec.rb b/spec/views/users/dossiers/brouillon.html.haml_spec.rb index baf50c95f..31be3dc9d 100644 --- a/spec/views/users/dossiers/brouillon.html.haml_spec.rb +++ b/spec/views/users/dossiers/brouillon.html.haml_spec.rb @@ -35,6 +35,24 @@ describe 'users/dossiers/brouillon', type: :view do let(:procedure) { create(:procedure) } it { is_expected.not_to have_link("Télécharger le guide de la démarche") } end + + context 'when a dossier is for_tiers and the dossier is in brouillon with email notification' do + let(:dossier) { create(:dossier, :for_tiers_with_notification) } + + it 'displays the informations of the mandataire and the beneficiaire email' do + expect(rendered).to have_text("#{dossier.mandataire_full_name} agit pour le compte du bénéficiaire :") + expect(rendered).to have_text("Email :\n\n\n#{dossier.individual.email}") + end + end + + context 'when a dossier is for_tiers and the dossier is in brouillon with no notification' do + let!(:dossier) { create(:dossier, :for_tiers_without_notification) } + + it 'displays the informations of the mandataire and do not display the beneficiary email' do + expect(rendered).to have_text("#{dossier.mandataire_full_name} agit pour le compte du bénéficiaire :") + expect(rendered).not_to have_text("Email :\n\n\n#{dossier.individual.email}") + end + end end context "as an administrateur" do diff --git a/spec/views/users/dossiers/demande.html.haml_spec.rb b/spec/views/users/dossiers/demande.html.haml_spec.rb index 90c80ef4c..b5b85b9ae 100644 --- a/spec/views/users/dossiers/demande.html.haml_spec.rb +++ b/spec/views/users/dossiers/demande.html.haml_spec.rb @@ -48,4 +48,14 @@ describe 'users/dossiers/demande', type: :view do expect(view.content_for(:notice_info)).to have_text("Le dossier a été déposé par le compte de #{france_connect_information.given_name} #{france_connect_information.family_name}, authentifié par FranceConnect le #{france_connect_information.updated_at.strftime('%d/%m/%Y')}") end end + + context 'when a dossier is for_tiers and the dossier is en_construction with email notification' do + let(:dossier) { create(:dossier, :en_construction, :for_tiers_with_notification) } + + it 'displays the informations of the mandataire' do + expect(rendered).to have_text('Email du mandataire') + expect(rendered).to have_text("#{dossier.mandataire_full_name} agit pour le compte du bénéficiaire :") + expect(rendered).to have_text(dossier.individual.email.to_s) + end + end end