2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-01-21 17:06:09 +01:00
|
|
|
describe FranceConnectInformation, type: :model do
|
|
|
|
describe 'validation' do
|
|
|
|
context 'france_connect_particulier_id' do
|
|
|
|
it { is_expected.not_to allow_value(nil).for(:france_connect_particulier_id) }
|
|
|
|
it { is_expected.not_to allow_value('').for(:france_connect_particulier_id) }
|
|
|
|
it { is_expected.to allow_value('mon super projet').for(:france_connect_particulier_id) }
|
|
|
|
end
|
|
|
|
end
|
2021-02-01 14:28:04 +01:00
|
|
|
|
|
|
|
describe 'associate_user!' do
|
|
|
|
context 'when there is no user with same email' do
|
2021-10-13 00:18:00 +02:00
|
|
|
let(:email) { 'A@email.com' }
|
2021-04-26 16:26:42 +02:00
|
|
|
let(:fci) { build(:france_connect_information) }
|
2021-10-13 00:18:00 +02:00
|
|
|
|
|
|
|
subject { fci.associate_user!(email) }
|
2021-02-01 14:28:04 +01:00
|
|
|
|
|
|
|
it { expect { subject }.to change(User, :count).by(1) }
|
2021-10-13 00:18:00 +02:00
|
|
|
|
2021-02-01 14:28:04 +01:00
|
|
|
it do
|
|
|
|
subject
|
2021-10-13 00:18:00 +02:00
|
|
|
expect(fci.user.email).to eq('a@email.com')
|
2024-05-27 10:01:14 +02:00
|
|
|
expect(fci.user.email_verified_at).to be_present
|
2021-02-01 14:28:04 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-10-13 00:14:12 +02:00
|
|
|
|
|
|
|
describe '#valid_for_merge?' do
|
|
|
|
let(:fci) { create(:france_connect_information) }
|
|
|
|
|
|
|
|
subject { fci.valid_for_merge? }
|
|
|
|
|
|
|
|
context 'when the merge token is young enough' do
|
|
|
|
before { fci.merge_token_created_at = 1.minute.ago }
|
|
|
|
|
|
|
|
it { is_expected.to be(true) }
|
|
|
|
|
|
|
|
context 'but the fci is already linked to an user' do
|
|
|
|
before { fci.update(user: create(:user)) }
|
|
|
|
|
|
|
|
it { is_expected.to be(false) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the merge token is too old' do
|
|
|
|
before { fci.merge_token_created_at = (FranceConnectInformation::MERGE_VALIDITY + 1.minute).ago }
|
|
|
|
|
|
|
|
it { is_expected.to be(false) }
|
|
|
|
end
|
|
|
|
end
|
2021-10-13 00:40:15 +02:00
|
|
|
|
|
|
|
describe '#create_merge_token!' do
|
|
|
|
let(:fci) { create(:france_connect_information) }
|
|
|
|
|
|
|
|
it 'returns a merge_token and register it s creation date' do
|
|
|
|
token = fci.create_merge_token!
|
|
|
|
|
|
|
|
expect(fci.merge_token).to eq(token)
|
|
|
|
expect(fci.merge_token_created_at).not_to be_nil
|
|
|
|
end
|
|
|
|
end
|
2016-01-21 17:06:09 +01:00
|
|
|
end
|