demarches-normaliennes/spec/models/france_connect_information_spec.rb
2021-10-14 14:47:50 +02:00

46 lines
1.4 KiB
Ruby

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
describe 'associate_user!' do
context 'when there is no user with same email' do
let(:fci) { build(:france_connect_information) }
let(:subject) { fci.associate_user! }
it { expect { subject }.to change(User, :count).by(1) }
it do
subject
expect(fci.user.email).to eq(fci.email_france_connect)
end
end
end
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
end