fix siret retrieval from OpenIDConnect::ResponseObject::UserInfo

This commit is contained in:
Tanguy PATTE 2015-10-07 12:01:05 +02:00
parent 6db8efb078
commit 6dc891a320
6 changed files with 36 additions and 19 deletions

View file

@ -3,6 +3,7 @@ class FranceConnectService
client = FranceConnectClient.new code: code
access_token = client.access_token!(client_auth_method: :secret)
access_token.userinfo!
user_info = access_token.userinfo!
Hashie::Mash.new user_info.raw_attributes
end
end

View file

@ -18,10 +18,13 @@ describe FranceConnectController, type: :controller do
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) }
context 'when code is correct' do
before do
allow(FranceConnectService).to receive(:retrieve_user_informations).and_return(Hashie::Mash.new(email: 'patator@cake.com'))
allow(FranceConnectService).to receive(:retrieve_user_informations).and_return(user_info)
end
it 'redirect to dossiers list' do
get :callback, code: code

View file

@ -16,10 +16,12 @@ feature 'user path for dossier creation' do
context 'user sign_in' do
before do
within('#new_user') do
page.find_by_id('user_email').set user.email
page.find_by_id('user_password').set user.password
page.click_on 'Se connecter'
end
end
scenario 'redirects to siret page' do
expect(page).to have_css('#siret')
end

View file

@ -9,10 +9,12 @@ feature 'user access to the list of his dossier' do
before do
last_updated_dossier.update_attributes(nom_projet: 'salut la compagnie')
visit root_path
within('#new_user') do
page.find_by_id('user_email').set user.email
page.find_by_id('user_password').set user.password
page.click_on 'Se connecter'
end
end
scenario 'the list of dossier is displayed' do
expect(page).to have_content(dossier1.nom_projet)
expect(page).not_to have_content(dossier2.nom_projet)

View file

@ -14,10 +14,12 @@ feature 'user arrive on siret page' do
end
context 'when he enter login information' do
before do
within('#new_user') do
page.find_by_id('user_email').set user.email
page.find_by_id('user_password').set user.password
page.click_on 'Se connecter'
end
end
scenario 'he is redirected to siret page to enter a siret' do
expect(page).to have_css('#pro_section')
end

View file

@ -3,21 +3,28 @@ require 'spec_helper'
describe FranceConnectService do
describe '.retrieve_user_informations' do
let(:code) { 'plop' }
let(:mocky) { 'my mocky' }
let(:user_info) { 'user_informations' }
let(:access_token) { 'my access_token' }
let(:email) { 'patator@cake.com' }
let(:siret) { '41123069100049' }
let(:user_info_hash) { {'email' => email, 'siret' => siret} }
let(:user_info) { instance_double('OpenIDConnect::ResponseObject::UserInfo', raw_attributes: user_info_hash, email: email) }
subject { described_class.retrieve_user_informations code }
before do
allow_any_instance_of(FranceConnectClient).to receive(:access_token!).and_return(mocky)
allow(mocky).to receive(:userinfo!).and_return(user_info)
allow_any_instance_of(FranceConnectClient).to receive(:access_token!).and_return(access_token)
allow(access_token).to receive(:userinfo!).and_return(user_info)
end
it 'set code for FranceConnectClient' do
expect_any_instance_of(FranceConnectClient).to receive(:initialize).with(code: code)
expect_any_instance_of(FranceConnectClient).to receive(:authorization_code=).with(code)
described_class.retrieve_user_informations code
end
it 'returns user informations' do
expect(subject).to eq(user_info)
it 'returns user informations in a object' do
expect(subject.email).to eq(email)
expect(subject.siret).to eq(siret)
end
end
end