FC ParticulierControllerSpec: remove one context
This commit is contained in:
parent
4f86b6305b
commit
ab116895b7
1 changed files with 73 additions and 75 deletions
|
@ -33,95 +33,93 @@ describe FranceConnect::ParticulierController, type: :controller do
|
||||||
it { is_expected.to redirect_to(new_user_session_path) }
|
it { is_expected.to redirect_to(new_user_session_path) }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when params code is present' do
|
context 'when code is correct' do
|
||||||
context 'when code is correct' do
|
before do
|
||||||
before do
|
allow(FranceConnectService).to receive(:retrieve_user_informations_particulier)
|
||||||
allow(FranceConnectService).to receive(:retrieve_user_informations_particulier)
|
.and_return(FranceConnectInformation.new(user_info))
|
||||||
.and_return(FranceConnectInformation.new(user_info))
|
end
|
||||||
end
|
|
||||||
|
|
||||||
context 'when france_connect_particulier_id exist in database' do
|
context 'when france_connect_particulier_id exist in database' do
|
||||||
let!(:france_connect_information) { create(:france_connect_information, france_connect_particulier_id: france_connect_particulier_id, given_name: given_name, family_name: family_name, birthdate: birthdate, gender: gender, birthplace: birthplace) }
|
let!(:france_connect_information) { create(:france_connect_information, france_connect_particulier_id: france_connect_particulier_id, given_name: given_name, family_name: family_name, birthdate: birthdate, gender: gender, birthplace: birthplace) }
|
||||||
|
|
||||||
context {
|
context {
|
||||||
subject { get :callback, params: {code: code} }
|
|
||||||
|
|
||||||
it 'does not create a new france_connect_information in database' do
|
|
||||||
expect { subject }.not_to change { FranceConnectInformation.count }
|
|
||||||
end
|
|
||||||
}
|
|
||||||
|
|
||||||
context 'when france_connect_particulier_id have an associate user' do
|
|
||||||
before do
|
|
||||||
create(:user, email: email, france_connect_information: france_connect_information)
|
|
||||||
|
|
||||||
get :callback, params: {code: code}
|
|
||||||
end
|
|
||||||
|
|
||||||
let(:email) { 'plop@plop.com' }
|
|
||||||
let(:current_user) { User.find_by_email(email) }
|
|
||||||
let(:stored_location) { '/plip/plop' }
|
|
||||||
|
|
||||||
it 'current user have attribut loged_in_with_france_connect? at true' do
|
|
||||||
expect(current_user.loged_in_with_france_connect?).to be_truthy
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'redirect to stored location' do
|
|
||||||
subject.store_location_for(:user, stored_location)
|
|
||||||
|
|
||||||
get :callback, params: {code: code}
|
|
||||||
expect(response).to redirect_to(stored_location)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when france_connect_particulier_id does not have an associate user' do
|
|
||||||
before do
|
|
||||||
get :callback, params: {code: code}
|
|
||||||
end
|
|
||||||
|
|
||||||
it {expect(response).to redirect_to(root_path)}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when france_connect_particulier_id does not exist in database' do
|
|
||||||
let(:last_france_connect_information) { FranceConnectInformation.last }
|
|
||||||
subject { get :callback, params: {code: code} }
|
subject { get :callback, params: {code: code} }
|
||||||
|
|
||||||
it { expect { subject }.to change { FranceConnectInformation.count }.by(1) }
|
it 'does not create a new france_connect_information in database' do
|
||||||
|
expect { subject }.not_to change { FranceConnectInformation.count }
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
describe 'FranceConnectInformation attributs' do
|
context 'when france_connect_particulier_id have an associate user' do
|
||||||
before do
|
before do
|
||||||
get :callback, params: {code: code}
|
create(:user, email: email, france_connect_information: france_connect_information)
|
||||||
end
|
|
||||||
|
|
||||||
subject { last_france_connect_information }
|
get :callback, params: {code: code}
|
||||||
|
|
||||||
it { expect(subject.gender).to eq gender }
|
|
||||||
it { expect(subject.given_name).to eq given_name }
|
|
||||||
it { expect(subject.family_name).to eq family_name }
|
|
||||||
it { expect(subject.email_france_connect).to eq email }
|
|
||||||
it { expect(subject.birthdate.to_time.to_i).to eq birthdate.to_time.to_i }
|
|
||||||
it { expect(subject.birthplace).to eq birthplace }
|
|
||||||
it { expect(subject.france_connect_particulier_id).to eq france_connect_particulier_id }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it { expect(subject).to redirect_to(root_path) }
|
let(:email) { 'plop@plop.com' }
|
||||||
|
let(:current_user) { User.find_by_email(email) }
|
||||||
|
let(:stored_location) { '/plip/plop' }
|
||||||
|
|
||||||
|
it 'current user have attribut loged_in_with_france_connect? at true' do
|
||||||
|
expect(current_user.loged_in_with_france_connect?).to be_truthy
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'redirect to stored location' do
|
||||||
|
subject.store_location_for(:user, stored_location)
|
||||||
|
|
||||||
|
get :callback, params: {code: code}
|
||||||
|
expect(response).to redirect_to(stored_location)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when france_connect_particulier_id does not have an associate user' do
|
||||||
|
before do
|
||||||
|
get :callback, params: {code: code}
|
||||||
|
end
|
||||||
|
|
||||||
|
it {expect(response).to redirect_to(root_path)}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when code is not correct' do
|
context 'when france_connect_particulier_id does not exist in database' do
|
||||||
before do
|
let(:last_france_connect_information) { FranceConnectInformation.last }
|
||||||
allow(FranceConnectService).to receive(:retrieve_user_informations_particulier) { raise Rack::OAuth2::Client::Error.new(500, error: 'Unknown') }
|
subject { get :callback, params: {code: code} }
|
||||||
get :callback, params: {code: code}
|
|
||||||
|
it { expect { subject }.to change { FranceConnectInformation.count }.by(1) }
|
||||||
|
|
||||||
|
describe 'FranceConnectInformation attributs' do
|
||||||
|
before do
|
||||||
|
get :callback, params: {code: code}
|
||||||
|
end
|
||||||
|
|
||||||
|
subject { last_france_connect_information }
|
||||||
|
|
||||||
|
it { expect(subject.gender).to eq gender }
|
||||||
|
it { expect(subject.given_name).to eq given_name }
|
||||||
|
it { expect(subject.family_name).to eq family_name }
|
||||||
|
it { expect(subject.email_france_connect).to eq email }
|
||||||
|
it { expect(subject.birthdate.to_time.to_i).to eq birthdate.to_time.to_i }
|
||||||
|
it { expect(subject.birthplace).to eq birthplace }
|
||||||
|
it { expect(subject.france_connect_particulier_id).to eq france_connect_particulier_id }
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'redirect to login page' do
|
it { expect(subject).to redirect_to(root_path) }
|
||||||
expect(response).to redirect_to(new_user_session_path)
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'display error message' do
|
context 'when code is not correct' do
|
||||||
expect(flash[:alert]).to be_present
|
before do
|
||||||
end
|
allow(FranceConnectService).to receive(:retrieve_user_informations_particulier) { raise Rack::OAuth2::Client::Error.new(500, error: 'Unknown') }
|
||||||
|
get :callback, params: {code: code}
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'redirect to login page' do
|
||||||
|
expect(response).to redirect_to(new_user_session_path)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'display error message' do
|
||||||
|
expect(flash[:alert]).to be_present
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue