2015-11-04 17:27:01 +01:00
|
|
|
require 'spec_helper'
|
2015-10-23 16:19:55 +02:00
|
|
|
|
2015-11-04 17:27:01 +01:00
|
|
|
describe Administrateur, type: :model do
|
2018-05-31 18:07:19 +02:00
|
|
|
let(:administration) { create(:administration) }
|
|
|
|
|
2015-11-10 10:23:15 +01:00
|
|
|
describe 'assocations' do
|
2019-08-06 11:02:54 +02:00
|
|
|
it { is_expected.to have_and_belong_to_many(:instructeurs) }
|
2015-11-10 10:23:15 +01:00
|
|
|
it { is_expected.to have_many(:procedures) }
|
|
|
|
end
|
|
|
|
|
2018-08-24 16:45:43 +02:00
|
|
|
describe "#renew_api_token" do
|
2018-09-26 17:22:36 +02:00
|
|
|
let!(:administrateur) { create(:administrateur) }
|
|
|
|
let!(:token) { administrateur.renew_api_token }
|
2018-08-24 16:45:43 +02:00
|
|
|
|
2018-09-26 17:22:36 +02:00
|
|
|
it { expect(BCrypt::Password.new(administrateur.encrypted_token)).to eq(token) }
|
2018-08-24 16:45:43 +02:00
|
|
|
|
|
|
|
context 'when it s called twice' do
|
2018-09-26 17:22:36 +02:00
|
|
|
let!(:new_token) { administrateur.renew_api_token }
|
2018-08-24 16:45:43 +02:00
|
|
|
|
2018-09-26 17:22:36 +02:00
|
|
|
it { expect(new_token).not_to eq(token) }
|
2018-08-24 16:45:43 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-08-09 10:41:10 +02:00
|
|
|
# describe '#password_complexity' do
|
|
|
|
# let(:email) { 'mail@beta.gouv.fr' }
|
|
|
|
# let(:passwords) { ['pass', '12pass23', 'démarches ', 'démarches-simple', 'démarches-simplifiées-pwd'] }
|
|
|
|
# let(:administrateur) { build(:administrateur, email: email, password: password) }
|
|
|
|
# let(:min_complexity) { PASSWORD_COMPLEXITY_FOR_ADMIN }
|
2018-01-25 10:50:06 +01:00
|
|
|
|
2019-08-09 10:41:10 +02:00
|
|
|
# subject do
|
|
|
|
# administrateur.save
|
|
|
|
# administrateur.errors.full_messages
|
|
|
|
# end
|
2019-06-20 00:41:15 +02:00
|
|
|
|
2019-08-09 10:41:10 +02:00
|
|
|
# context 'when password is too short' do
|
|
|
|
# let(:password) { 's' * (PASSWORD_MIN_LENGTH - 1) }
|
2018-01-25 10:50:06 +01:00
|
|
|
|
2019-08-09 10:41:10 +02:00
|
|
|
# it { expect(subject).to eq(["Le mot de passe est trop court"]) }
|
|
|
|
# end
|
2019-06-20 00:41:15 +02:00
|
|
|
|
2019-08-09 10:41:10 +02:00
|
|
|
# context 'when password is too simple' do
|
|
|
|
# let(:password) { passwords[min_complexity - 1] }
|
2018-01-25 10:50:06 +01:00
|
|
|
|
2019-08-09 10:41:10 +02:00
|
|
|
# it { expect(subject).to eq(["Le mot de passe n'est pas assez complexe"]) }
|
|
|
|
# end
|
2019-06-20 00:41:15 +02:00
|
|
|
|
2019-08-09 10:41:10 +02:00
|
|
|
# context 'when password is acceptable' do
|
|
|
|
# let(:password) { passwords[min_complexity] }
|
|
|
|
|
|
|
|
# it { expect(subject).to eq([]) }
|
|
|
|
# end
|
|
|
|
# end
|
2019-10-24 11:21:12 +02:00
|
|
|
|
|
|
|
describe '#active?' do
|
|
|
|
let!(:administrateur) { create(:administrateur) }
|
|
|
|
|
|
|
|
subject { administrateur.active? }
|
|
|
|
|
|
|
|
context 'when the user has never signed in' do
|
|
|
|
before { administrateur.user.update(last_sign_in_at: nil) }
|
|
|
|
|
|
|
|
it { is_expected.to be false }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the user has already signed in' do
|
|
|
|
before { administrateur.user.update(last_sign_in_at: Time.zone.now) }
|
|
|
|
|
|
|
|
it { is_expected.to be true }
|
|
|
|
end
|
|
|
|
end
|
2015-10-23 16:19:55 +02:00
|
|
|
end
|