diff --git a/app/views/france_connect/particulier/_password_confirmation.html.haml b/app/views/france_connect/particulier/_password_confirmation.html.haml index c83addb8c..0bc209dff 100644 --- a/app/views/france_connect/particulier/_password_confirmation.html.haml +++ b/app/views/france_connect/particulier/_password_confirmation.html.haml @@ -7,6 +7,6 @@ = hidden_field_tag :merge_token, merge_token = hidden_field_tag :email, email = label_tag :password, 'Mot de passe (8 caractères minimum)' - = password_field_tag :password, nil, autocomplete: 'current-password' + = password_field_tag :password, nil, autocomplete: 'current-password', id: 'password-for-another-account' = button_tag 'revenir en arrière', type: 'button', class: 'button secondary', onclick: 'DS.showNewAccount(event);' = submit_tag 'Fusionner les comptes', class: 'button primary' diff --git a/app/views/france_connect/particulier/merge.html.haml b/app/views/france_connect/particulier/merge.html.haml index f2acdb168..c8f4ae656 100644 --- a/app/views/france_connect/particulier/merge.html.haml +++ b/app/views/france_connect/particulier/merge.html.haml @@ -15,11 +15,11 @@ %label Ce compte #{@fci.email_france_connect} vous appartient-il ? %fieldset.radios %label{ onclick: "DS.showFusion(event);" } - = radio_button_tag :value, true, false, autocomplete: "off" + = radio_button_tag :value, true, false, autocomplete: "off", id: 'it-is-mine' Oui %label{ onclick: "DS.showNewAccount(event);" } - = radio_button_tag :value, false, false, autocomplete: "off" + = radio_button_tag :value, false, false, autocomplete: "off", id: 'it-is-not-mine' Non .fusion.hidden diff --git a/spec/features/france_connect/france_connect_particulier_spec.rb b/spec/features/france_connect/france_connect_particulier_spec.rb index 6c5b98520..4498f8031 100644 --- a/spec/features/france_connect/france_connect_particulier_spec.rb +++ b/spec/features/france_connect/france_connect_particulier_spec.rb @@ -34,18 +34,67 @@ feature 'France Connect Particulier Connexion' do allow(FranceConnectService).to receive(:retrieve_user_informations_particulier).and_return(france_connect_information) end - context 'when is the first connexion' do + context 'when no user is linked' do let(:france_connect_information) { build(:france_connect_information, user_info) } - before { page.find('.france-connect-login-button').click } + context 'and no user has the same email' do + before { page.find('.france-connect-login-button').click } - scenario 'he is redirected to user dossiers page' do - expect(page).to have_content('Dossiers') - expect(User.find_by(email: email)).not_to be nil + scenario 'he is redirected to user dossiers page' do + expect(page).to have_content('Dossiers') + expect(User.find_by(email: email)).not_to be nil + end + end + + context 'and an user exists with the same email' do + let!(:user) { create(:user, email: email, password: 'my-s3cure-p4ssword') } + + before do + page.find('.france-connect-login-button').click + end + + scenario 'he is redirected to the merge page' do + expect(page).to have_content('Fusion des comptes') + end + + scenario 'it merges its account' do + page.find('#it-is-mine').click + fill_in 'password', with: 'my-s3cure-p4ssword' + click_on 'Fusionner les comptes' + + expect(page).to have_content('Dossiers') + end + + scenario 'it uses another email that belongs to nobody' do + page.find('#it-is-not-mine').click + fill_in 'email', with: 'new_email@a.com' + click_on 'Utiliser ce mail' + + expect(page).to have_content('Dossiers') + end + + context 'and the user wants an email that belongs to another account', js: true do + let!(:another_user) { create(:user, email: 'an_existing_email@a.com', password: 'my-s3cure-p4ssword') } + + scenario 'it uses another email that belongs to another account' do + page.find('#it-is-not-mine').click + fill_in 'email', with: 'an_existing_email@a.com' + click_on 'Utiliser ce mail' + + expect(page).to have_css('#password-for-another-account', visible: true) + + within '.new-account-password-confirmation' do + fill_in 'password', with: 'my-s3cure-p4ssword' + click_on 'Fusionner les comptes' + end + + expect(page).to have_content('Dossiers') + end + end end end - context 'when is not the first connexion' do + context 'when a user is linked' do let!(:france_connect_information) do create(:france_connect_information, :with_user, user_info.merge(created_at: Time.zone.parse('12/12/2012'), updated_at: Time.zone.parse('12/12/2012'))) end