login_token: add missing tests

This commit is contained in:
simon lehericey 2019-01-03 16:00:58 +01:00 committed by Pierre de La Morinerie
parent 67e92ffa17
commit 5daa565a80
2 changed files with 23 additions and 1 deletions

View file

@ -253,13 +253,15 @@ describe Users::SessionsController, type: :controller do
describe '#sign_in_by_link' do
context 'when the gestionnaire has non other account' do
let(:gestionnaire) { create(:gestionnaire) }
let!(:good_jeton) { gestionnaire.login_token! }
before do
allow(controller).to receive(:trust_device)
post :sign_in_by_link, params: { id: gestionnaire.id, jeton: jeton }
end
context 'when the token is valid' do
let(:jeton) { gestionnaire.login_token! }
let(:jeton) { good_jeton }
# TODO when the gestionnaire has no other account, and the token is valid, and the user signing in was not starting a demarche,
# redirect to root_path, then redirect to gestionnaire_procedures_path (see root_controller)

View file

@ -393,6 +393,26 @@ describe Gestionnaire, type: :model do
end
end
describe '#login_token_valid?' do
let!(:gestionnaire) { create(:gestionnaire) }
let!(:good_token) { gestionnaire.login_token! }
it { expect(gestionnaire.login_token_valid?(good_token)).to be true }
it { expect(gestionnaire.login_token_valid?('bad_token')).to be false }
context 'when the token as expired' do
before { gestionnaire.update(login_token_created_at: 31.minutes.ago) }
it { expect(gestionnaire.login_token_valid?(good_token)).to be false }
end
context 'when the gestionnaire does not have a token' do
before { gestionnaire.update(encrypted_login_token: nil) }
it { expect(gestionnaire.login_token_valid?(nil)).to be false }
end
end
private
def assign(procedure_to_assign)