2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-10-06 11:47:42 +02:00
|
|
|
describe FranceConnectService do
|
2015-12-24 10:12:23 +01:00
|
|
|
describe '.retrieve_user_informations_particulier' do
|
|
|
|
let(:code) { 'plop' }
|
2024-05-13 16:38:37 +02:00
|
|
|
let(:access_token) { +'my access_token' }
|
2015-12-24 10:12:23 +01:00
|
|
|
|
|
|
|
let(:given_name) { 'plop1' }
|
|
|
|
let(:family_name) { 'plop2' }
|
2018-01-11 18:16:38 +01:00
|
|
|
let(:birthdate) { '2012-12-31' }
|
2015-12-24 10:12:23 +01:00
|
|
|
let(:gender) { 'plop4' }
|
|
|
|
let(:birthplace) { 'plop5' }
|
|
|
|
let(:email) { 'plop@emaiL.com' }
|
|
|
|
let(:phone) { '012345678' }
|
|
|
|
let(:france_connect_particulier_id) { 'izhikziogjuziegj' }
|
|
|
|
|
2018-01-16 13:34:24 +01:00
|
|
|
let(:user_info_hash) { { sub: france_connect_particulier_id, given_name: given_name, family_name: family_name, birthdate: birthdate, gender: gender, birthplace: birthplace, email: email, phone: phone } }
|
2015-12-24 10:12:23 +01:00
|
|
|
let(:user_info) { instance_double('OpenIDConnect::ResponseObject::UserInfo', raw_attributes: user_info_hash) }
|
|
|
|
|
2021-02-01 14:28:04 +01:00
|
|
|
subject { described_class.find_or_retrieve_france_connect_information code }
|
2015-12-24 10:12:23 +01:00
|
|
|
|
|
|
|
before do
|
|
|
|
allow_any_instance_of(FranceConnectParticulierClient).to receive(:access_token!).and_return(access_token)
|
|
|
|
allow(access_token).to receive(:userinfo!).and_return(user_info)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'set code for FranceConnectEntrepriseClient' do
|
|
|
|
expect_any_instance_of(FranceConnectParticulierClient).to receive(:authorization_code=).with(code)
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
2018-01-11 18:16:38 +01:00
|
|
|
it 'returns user informations' do
|
|
|
|
expect(subject).to have_attributes({
|
|
|
|
given_name: given_name,
|
|
|
|
family_name: family_name,
|
2019-11-25 14:39:42 +01:00
|
|
|
birthdate: Time.zone.parse(birthdate).to_date,
|
2018-01-11 18:16:38 +01:00
|
|
|
birthplace: birthplace,
|
|
|
|
gender: gender,
|
|
|
|
email_france_connect: email,
|
2018-01-15 19:24:05 +01:00
|
|
|
france_connect_particulier_id: france_connect_particulier_id
|
|
|
|
})
|
2015-12-24 10:12:23 +01:00
|
|
|
end
|
|
|
|
end
|
2017-04-04 15:27:04 +02:00
|
|
|
end
|