2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-10-11 05:41:23 -04:00
|
|
|
require 'rails_helper'
|
2015-08-24 02:21:34 -04:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2020-07-24 05:16:52 -04:00
|
|
|
expect_enqueued_with(job: :critical_user_email, args: { type: :signup, email_token: user.email_tokens.first.token }) do
|
|
|
|
activator.activate
|
|
|
|
end
|
2015-08-24 02:21:34 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates and send new email token if the existing token expired' do
|
2020-03-10 17:13:17 -04:00
|
|
|
now = freeze_time
|
|
|
|
|
2015-08-24 02:21:34 -04:00
|
|
|
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)
|
|
|
|
|
2020-07-24 05:16:52 -04:00
|
|
|
expect_not_enqueued_with(job: :critical_user_email, args: { type: :signup, user_id: user.id, email_token: email_token.token }) do
|
|
|
|
activator.activate
|
|
|
|
end
|
2015-08-24 02:21:34 -04:00
|
|
|
|
2020-07-24 05:16:52 -04:00
|
|
|
email_token = user.reload.email_tokens.last
|
|
|
|
|
|
|
|
expect(job_enqueued?(job: :critical_user_email, args: {
|
|
|
|
type: :signup,
|
|
|
|
user_id: user.id,
|
|
|
|
email_token: email_token.token
|
|
|
|
})).to eq(true)
|
|
|
|
|
|
|
|
expect(email_token.created_at).to eq_time(now)
|
2015-08-24 02:21:34 -04:00
|
|
|
end
|
2016-08-05 12:01:16 -04:00
|
|
|
|
2015-08-24 02:21:34 -04:00
|
|
|
end
|
|
|
|
end
|