2015-10-06 16:02:30 +02:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2015-12-18 12:01:26 +01:00
|
|
|
describe FranceConnect::EntrepriseController, type: :controller do
|
2015-10-06 16:02:30 +02:00
|
|
|
|
|
|
|
describe '.login' do
|
|
|
|
it 'redirect to france connect serveur' do
|
|
|
|
get :login
|
|
|
|
expect(response.status).to eq(302)
|
|
|
|
end
|
|
|
|
end
|
2015-10-06 16:17:15 +02:00
|
|
|
|
|
|
|
describe '.callback' do
|
|
|
|
context 'when param code is missing' do
|
|
|
|
it 'redirect to login page' do
|
|
|
|
get :callback
|
|
|
|
expect(response).to redirect_to(new_user_session_path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
context 'when params code is present' do
|
2015-10-06 16:35:03 +02:00
|
|
|
let(:code) { 'plop' }
|
2015-10-07 12:01:05 +02:00
|
|
|
let(:email) { 'patator@cake.com' }
|
|
|
|
let(:siret) { '41123069100049' }
|
|
|
|
let(:user_info) { Hashie::Mash.new(email: email, siret: siret) }
|
2015-10-06 16:17:15 +02:00
|
|
|
context 'when code is correct' do
|
2015-10-07 11:24:07 +02:00
|
|
|
let(:email) { 'patator@cake.com' }
|
|
|
|
let(:current_user) { User.find_by_email(email) }
|
2015-10-07 12:01:05 +02:00
|
|
|
|
2015-10-06 16:17:15 +02:00
|
|
|
before do
|
2015-12-18 12:01:26 +01:00
|
|
|
allow(FranceConnectService).to receive(:retrieve_user_informations_entreprise).and_return(user_info)
|
2015-10-07 11:24:07 +02:00
|
|
|
get :callback, code: code
|
2015-10-06 16:17:15 +02:00
|
|
|
end
|
2015-10-07 11:24:07 +02:00
|
|
|
|
2015-12-24 10:12:23 +01:00
|
|
|
it 'current user have attribut loged_in_with_france_connect at enterprise' do
|
|
|
|
expect(current_user.loged_in_with_france_connect).to eq 'entreprise'
|
2015-10-07 11:24:07 +02:00
|
|
|
end
|
2015-10-07 16:49:42 +02:00
|
|
|
let(:stored_location) { '/plip/plop' }
|
|
|
|
it 'redirect to stored location' do
|
|
|
|
subject.store_location_for(:user, stored_location)
|
2015-10-06 16:47:25 +02:00
|
|
|
get :callback, code: code
|
2015-10-07 16:49:42 +02:00
|
|
|
expect(response).to redirect_to(stored_location)
|
2015-10-06 16:17:15 +02:00
|
|
|
end
|
|
|
|
end
|
2015-10-06 16:35:03 +02:00
|
|
|
|
2015-10-07 16:49:42 +02:00
|
|
|
context 'when code is not correct' do
|
2015-10-06 16:35:03 +02:00
|
|
|
before do
|
2015-12-18 12:01:26 +01:00
|
|
|
allow(FranceConnectService).to receive(:retrieve_user_informations_entreprise) { raise Rack::OAuth2::Client::Error.new(500, error: 'Unknown') }
|
2015-10-06 17:06:37 +02:00
|
|
|
get :callback, code: code
|
2015-10-06 16:35:03 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'redirect to login page' do
|
2015-10-06 16:47:25 +02:00
|
|
|
expect(response).to redirect_to(new_user_session_path)
|
2015-10-06 16:35:03 +02:00
|
|
|
end
|
|
|
|
|
2015-10-06 17:06:37 +02:00
|
|
|
it 'display error message' do
|
|
|
|
expect(flash[:alert]).to be_present
|
2015-10-06 16:35:03 +02:00
|
|
|
end
|
|
|
|
end
|
2015-10-06 16:17:15 +02:00
|
|
|
end
|
|
|
|
end
|
2015-10-06 16:02:30 +02:00
|
|
|
end
|
|
|
|
|