2015-10-06 17:06:59 +02:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
feature 'France Connect Connexion' do
|
|
|
|
|
|
|
|
context 'when user is on login page' do
|
|
|
|
|
|
|
|
before do
|
|
|
|
visit new_user_session_path
|
|
|
|
end
|
|
|
|
|
|
|
|
scenario 'link to France Connect is present' do
|
2015-10-08 11:26:12 +02:00
|
|
|
expect(page).to have_css('a#btn_fc')
|
2015-10-06 17:06:59 +02:00
|
|
|
end
|
|
|
|
|
2015-10-06 17:22:06 +02:00
|
|
|
context 'and click on france connect link' do
|
|
|
|
let(:code) { 'plop' }
|
2015-10-06 17:41:49 +02:00
|
|
|
|
|
|
|
context 'when authentification is ok' do
|
|
|
|
before do
|
|
|
|
allow_any_instance_of(FranceConnectClient).to receive(:authorization_uri).and_return(france_connect_callback_path(code: code))
|
|
|
|
allow(FranceConnectService).to receive(:retrieve_user_informations).and_return(Hashie::Mash.new(email: 'patator@cake.com'))
|
2015-10-08 11:26:12 +02:00
|
|
|
page.find_by_id('btn_fc').click
|
2015-10-06 17:41:49 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
scenario 'he is redirected to france connect' do
|
2015-11-30 15:56:06 +01:00
|
|
|
expect(page).to have_content('Mes dossiers')
|
2015-10-06 17:41:49 +02:00
|
|
|
end
|
2015-10-06 17:22:06 +02:00
|
|
|
end
|
2015-10-06 17:41:49 +02:00
|
|
|
|
|
|
|
context 'when authentification is not ok' do
|
|
|
|
before do
|
|
|
|
allow_any_instance_of(FranceConnectClient).to receive(:authorization_uri).and_return(france_connect_callback_path(code: code))
|
|
|
|
allow(FranceConnectService).to receive(:retrieve_user_informations) { raise Rack::OAuth2::Client::Error.new(500, error: 'Unknown') }
|
2015-10-08 11:26:12 +02:00
|
|
|
page.find_by_id('btn_fc').click
|
2015-10-06 17:41:49 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
scenario 'he is redirected to login page' do
|
2015-10-08 11:26:12 +02:00
|
|
|
expect(page).to have_css('a#btn_fc')
|
2015-10-06 17:41:49 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
scenario 'error message is displayed' do
|
|
|
|
expect(page).to have_content(I18n.t('errors.messages.france_connect.connexion'))
|
|
|
|
end
|
2015-10-06 17:22:06 +02:00
|
|
|
end
|
|
|
|
end
|
2015-10-06 17:06:59 +02:00
|
|
|
end
|
2015-10-07 16:49:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
feature 'redirection' do
|
|
|
|
before do
|
|
|
|
visit initial_path
|
|
|
|
end
|
|
|
|
context 'when he use france connect' do
|
|
|
|
let(:code) { 'my_code' }
|
|
|
|
let(:email) { 'plop@plop.com' }
|
|
|
|
let(:siret) { '00000000000000' }
|
|
|
|
let(:user_infos) { Hashie::Mash.new(email: email, siret: siret) }
|
|
|
|
before do
|
|
|
|
allow_any_instance_of(FranceConnectClient).to receive(:authorization_uri).and_return(france_connect_callback_path(code: code))
|
|
|
|
allow(FranceConnectService).to receive(:retrieve_user_informations).and_return(user_infos)
|
2015-10-08 11:26:12 +02:00
|
|
|
page.find_by_id('btn_fc').click
|
2015-10-07 16:49:42 +02:00
|
|
|
end
|
|
|
|
context 'when starting page is dossiers list' do
|
|
|
|
let(:initial_path) { users_dossiers_path }
|
|
|
|
scenario 'he is redirected to dossier list' do
|
2015-12-02 16:52:09 +01:00
|
|
|
expect(page).to have_css('#users_index')
|
2015-10-07 16:49:42 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
context 'when starting page is procedure' do
|
|
|
|
let(:procedure) { create(:procedure) }
|
2015-12-03 12:00:22 +01:00
|
|
|
let(:initial_path) { new_users_dossiers_path(procedure_id: procedure.id ) }
|
2015-10-07 16:49:42 +02:00
|
|
|
scenario 'he is redirected to siret page' do
|
|
|
|
expect(page).to have_css('#users_siret_index')
|
|
|
|
end
|
2015-10-08 11:22:55 +02:00
|
|
|
|
|
|
|
scenario 'the siret is already written in form' do
|
2015-12-03 12:00:22 +01:00
|
|
|
expect(page.find_by_id('dossier_siret').value).to have_content(siret)
|
2015-10-08 11:22:55 +02:00
|
|
|
end
|
2015-10-07 16:49:42 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-10-06 17:06:59 +02:00
|
|
|
end
|