2019-04-30 10:27:42 +10:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-10-11 10:41:23 +01:00
|
|
|
require 'rails_helper'
|
2015-08-24 11:51:34 +05:30
|
|
|
|
|
|
|
describe UserActivator do
|
|
|
|
|
|
|
|
describe 'email_activator' do
|
|
|
|
|
|
|
|
it 'does not create new email token unless required' do
|
|
|
|
SiteSetting.email_token_valid_hours = 24
|
|
|
|
user = Fabricate(:user)
|
|
|
|
activator = EmailActivator.new(user, nil, nil, nil)
|
|
|
|
|
2016-04-07 14:38:43 +10:00
|
|
|
Jobs.expects(:enqueue).with(:critical_user_email, has_entries(type: :signup, email_token: user.email_tokens.first.token))
|
2015-08-24 11:51:34 +05:30
|
|
|
activator.activate
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates and send new email token if the existing token expired' do
|
2020-03-10 22:13:17 +01:00
|
|
|
now = freeze_time
|
|
|
|
|
2015-08-24 11:51:34 +05:30
|
|
|
SiteSetting.email_token_valid_hours = 24
|
|
|
|
user = Fabricate(:user)
|
|
|
|
email_token = user.email_tokens.first
|
|
|
|
email_token.update_column(:created_at, 48.hours.ago)
|
|
|
|
activator = EmailActivator.new(user, nil, nil, nil)
|
|
|
|
|
2016-04-07 14:38:43 +10:00
|
|
|
Jobs.expects(:enqueue).with(:critical_user_email, has_entries(type: :signup))
|
|
|
|
Jobs.expects(:enqueue).with(:critical_user_email, has_entries(type: :signup, email_token: email_token.token)).never
|
2015-08-24 11:51:34 +05:30
|
|
|
activator.activate
|
|
|
|
|
|
|
|
user.reload
|
2020-03-10 22:13:17 +01:00
|
|
|
expect(user.email_tokens.last.created_at).to eq_time(now)
|
2015-08-24 11:51:34 +05:30
|
|
|
end
|
2016-08-05 12:01:16 -04:00
|
|
|
|
2015-08-24 11:51:34 +05:30
|
|
|
end
|
|
|
|
end
|