add test to france connect controller

This commit is contained in:
Tanguy PATTE 2015-10-06 16:47:25 +02:00
parent b979c9df32
commit c57cb5b75d
2 changed files with 7 additions and 5 deletions

View file

@ -25,5 +25,8 @@ class FranceConnectController < ApplicationController
redirect_to(controller: 'users/dossiers', action: :index)
end
rescue Rack::OAuth2::Client::Error => e
Rails.logger.error e.message
redirect_to(new_user_session_path)
end
end

View file

@ -18,26 +18,25 @@ describe FranceConnectController, type: :controller do
end
context 'when params code is present' do
let(:code) { 'plop' }
before do
get :callback, code: code
end
context 'when code is correct' do
before do
allow(FranceConnectService).to receive(:retrieve_user_informations).and_return(Hashie::Mash.new(email: 'patator@cake.com'))
end
it 'redirect to dossiers list' do
get :callback, code: code
expect(response).to redirect_to(controller: 'users/dossiers', action: :index)
end
end
context 'wen code is not correct' do
before do
allow(FranceConnectService).to receive(:retrieve_user_informations).and_raise(Rack::OAuth2::Client::Error)
allow(FranceConnectService).to receive(:retrieve_user_informations) { raise Rack::OAuth2::Client::Error.new(500, error: 'Unknown') }
end
it 'redirect to login page' do
expect(response).to redirect_to(controller: 'users/sign_in', action: :index)
get :callback, code: code
expect(response).to redirect_to(new_user_session_path)
end
it 'flash message error connexion with France Connect' do