demarches-normaliennes/spec/controllers/france_connect/entreprise_controller_spec.rb

62 lines
1.9 KiB
Ruby
Raw Normal View History

2015-10-06 16:02:30 +02:00
require 'spec_helper'
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
let(:code) { 'plop' }
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
let(:email) { 'patator@cake.com' }
let(:current_user) { User.find_by_email(email) }
2015-10-06 16:17:15 +02:00
before do
allow(FranceConnectService).to receive(:retrieve_user_informations_entreprise).and_return(user_info)
get :callback, code: code
2015-10-06 16:17:15 +02:00
end
it 'current user have attribut loged_in_with_france_connect at enterprise' do
expect(current_user.loged_in_with_france_connect).to eq 'entreprise'
end
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
expect(response).to redirect_to(stored_location)
2015-10-06 16:17:15 +02:00
end
end
context 'when code is not correct' do
before do
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
end
it 'redirect to login page' do
2015-10-06 16:47:25 +02:00
expect(response).to redirect_to(new_user_session_path)
end
2015-10-06 17:06:37 +02:00
it 'display error message' do
expect(flash[:alert]).to be_present
end
end
2015-10-06 16:17:15 +02:00
end
end
2015-10-06 16:02:30 +02:00
end