mirror of
https://github.com/internetee/registry.git
synced 2025-06-13 08:04:45 +02:00
Move jobs from Que to ActiveJob
This commit is contained in:
parent
1d3be40e14
commit
313731232e
53 changed files with 390 additions and 157 deletions
|
@ -9,7 +9,7 @@ module Domains
|
||||||
clean_pendings
|
clean_pendings
|
||||||
|
|
||||||
to_stdout("DomainCron.clean_expired_pendings: ##{domain.id} (#{domain.name})")
|
to_stdout("DomainCron.clean_expired_pendings: ##{domain.id} (#{domain.name})")
|
||||||
UpdateWhoisRecordJob.enqueue domain.name, 'domain'
|
UpdateWhoisRecordJob.perform_later domain.name, 'domain'
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -17,7 +17,7 @@ module Domains
|
||||||
update_domain
|
update_domain
|
||||||
clean_pendings!
|
clean_pendings!
|
||||||
|
|
||||||
WhoisRecord.find_by(domain_id: domain.id).save # need to reload model
|
WhoisRecord.find_by(domain_id: domain.id)&.save # need to reload model
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_domain
|
def update_domain
|
||||||
|
|
|
@ -1,2 +1,4 @@
|
||||||
class ApplicationJob < ActiveJob::Base
|
class ApplicationJob < ActiveJob::Base
|
||||||
|
discard_on NoMethodError
|
||||||
|
queue_as :default
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
class DirectoInvoiceForwardJob < Que::Job
|
class DirectoInvoiceForwardJob < ApplicationJob
|
||||||
def run(monthly: false, dry: false)
|
def perform(monthly: false, dry: false)
|
||||||
@dry = dry
|
@dry = dry
|
||||||
(@month = Time.zone.now - 1.month) if monthly
|
(@month = Time.zone.now - 1.month) if monthly
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
class DisputeStatusUpdateJob < Que::Job
|
class DisputeStatusUpdateJob < ApplicationJob
|
||||||
def run(logger: Logger.new(STDOUT))
|
def perform(logger: Logger.new(STDOUT))
|
||||||
@logger = logger
|
@logger = logger
|
||||||
|
|
||||||
@backlog = { 'activated': 0, 'closed': 0, 'activate_fail': [], 'close_fail': [] }
|
@backlog = { 'activated': 0, 'closed': 0, 'activate_fail': [], 'close_fail': [] }
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
class DomainDeleteConfirmJob < ApplicationJob
|
class DomainDeleteConfirmJob < ApplicationJob
|
||||||
queue_as :default
|
|
||||||
|
|
||||||
def perform(domain_id, action, initiator = nil)
|
def perform(domain_id, action, initiator = nil)
|
||||||
domain = Epp::Domain.find(domain_id)
|
domain = Epp::Domain.find(domain_id)
|
||||||
|
|
||||||
|
@ -8,4 +6,34 @@ class DomainDeleteConfirmJob < ApplicationJob
|
||||||
action: action,
|
action: action,
|
||||||
initiator: initiator)
|
initiator: initiator)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def action_confirmed(domain)
|
||||||
|
domain.notify_registrar(:poll_pending_delete_confirmed_by_registrant)
|
||||||
|
domain.apply_pending_delete!
|
||||||
|
raise_errors!(domain)
|
||||||
|
end
|
||||||
|
|
||||||
|
def action_rejected(domain)
|
||||||
|
domain.statuses.delete(DomainStatus::PENDING_DELETE_CONFIRMATION)
|
||||||
|
domain.notify_registrar(:poll_pending_delete_rejected_by_registrant)
|
||||||
|
|
||||||
|
domain.cancel_pending_delete
|
||||||
|
domain.save(validate: false)
|
||||||
|
raise_errors!(domain)
|
||||||
|
notify_on_domain(domain)
|
||||||
|
end
|
||||||
|
|
||||||
|
def notify_on_domain(domain)
|
||||||
|
if domain.registrant_verification_token.blank?
|
||||||
|
Rails.logger.warn 'EMAIL NOT DELIVERED: registrant_verification_token is missing for '\
|
||||||
|
"#{domain.name}"
|
||||||
|
elsif domain.registrant_verification_asked_at.blank?
|
||||||
|
Rails.logger.warn 'EMAIL NOT DELIVERED: registrant_verification_asked_at is missing for '\
|
||||||
|
"#{domain.name}"
|
||||||
|
else
|
||||||
|
DomainDeleteMailer.rejected(domain).deliver_now
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
class DomainDeleteJob < Que::Job
|
class DomainDeleteJob < ApplicationJob
|
||||||
|
def perform(domain_id)
|
||||||
def run(domain_id)
|
|
||||||
domain = Domain.find(domain_id)
|
domain = Domain.find(domain_id)
|
||||||
|
|
||||||
Domains::Delete::DoDelete.run(domain: domain)
|
Domains::Delete::DoDelete.run(domain: domain)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
class DomainExpireEmailJob < Que::Job
|
class DomainExpireEmailJob < Que::Job
|
||||||
def run(domain_id, email)
|
def perform(domain_id, email)
|
||||||
domain = Domain.find(domain_id)
|
domain = Domain.find(domain_id)
|
||||||
|
|
||||||
return if domain.registered?
|
return if domain.registered?
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
class DomainUpdateConfirmJob < ApplicationJob
|
class DomainUpdateConfirmJob < ApplicationJob
|
||||||
queue_as :default
|
|
||||||
|
|
||||||
def perform(domain_id, action, initiator = nil)
|
def perform(domain_id, action, initiator = nil)
|
||||||
domain = Epp::Domain.find(domain_id)
|
domain = Epp::Domain.find(domain_id)
|
||||||
Domains::UpdateConfirm::ProcessAction.run(domain: domain,
|
Domains::UpdateConfirm::ProcessAction.run(domain: domain,
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
class RegenerateRegistrarWhoisesJob < Que::Job
|
class RegenerateRegistrarWhoisesJob < ApplicationJob
|
||||||
def run(registrar_id)
|
retry_on StandardError, wait: 2.seconds, attempts: 3
|
||||||
|
|
||||||
|
def perform(registrar_id)
|
||||||
# no return as we want restart job if fails
|
# no return as we want restart job if fails
|
||||||
registrar = Registrar.find(registrar_id)
|
registrar = Registrar.find(registrar_id)
|
||||||
|
|
||||||
registrar.whois_records.select(:name).find_in_batches(batch_size: 20) do |group|
|
registrar.whois_records.select(:name).find_in_batches(batch_size: 20) do |group|
|
||||||
UpdateWhoisRecordJob.enqueue group.map(&:name), 'domain'
|
UpdateWhoisRecordJob.perform_later group.map(&:name), 'domain'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -1,11 +1,11 @@
|
||||||
class RegenerateSubzoneWhoisesJob < Que::Job
|
class RegenerateSubzoneWhoisesJob < ApplicationJob
|
||||||
def run
|
def perform
|
||||||
subzones = DNS::Zone.all
|
subzones = DNS::Zone.all
|
||||||
|
|
||||||
subzones.each do |zone|
|
subzones.each do |zone|
|
||||||
next unless zone.subzone?
|
next unless zone.subzone?
|
||||||
|
|
||||||
UpdateWhoisRecordJob.enqueue zone.origin, 'zone'
|
UpdateWhoisRecordJob.perform_later zone.origin, 'zone'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
class RegistrantChangeConfirmEmailJob < Que::Job
|
class RegistrantChangeConfirmEmailJob < ApplicationJob
|
||||||
def run(domain_id, new_registrant_id)
|
def perform(domain_id, new_registrant_id)
|
||||||
domain = Domain.find(domain_id)
|
domain = Domain.find(domain_id)
|
||||||
new_registrant = Registrant.find(new_registrant_id)
|
new_registrant = Registrant.find(new_registrant_id)
|
||||||
|
|
||||||
|
|
22
app/jobs/registrant_change_expired_email_job.rb
Normal file
22
app/jobs/registrant_change_expired_email_job.rb
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
class RegistrantChangeExpiredEmailJob < ApplicationJob
|
||||||
|
def perform(domain_id)
|
||||||
|
domain = Domain.find(domain_id)
|
||||||
|
log(domain)
|
||||||
|
RegistrantChangeMailer.expired(domain: domain,
|
||||||
|
registrar: domain.registrar,
|
||||||
|
registrant: domain.registrant,
|
||||||
|
send_to: [domain.new_registrant_email,
|
||||||
|
domain.registrant.email]).deliver_now
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def log(domain)
|
||||||
|
message = "Send RegistrantChangeMailer#expired email for domain #{domain.name} (##{domain.id}) to #{domain.new_registrant_email}"
|
||||||
|
logger.info(message)
|
||||||
|
end
|
||||||
|
|
||||||
|
def logger
|
||||||
|
Rails.logger
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,5 +1,5 @@
|
||||||
class RegistrantChangeNoticeEmailJob < Que::Job
|
class RegistrantChangeNoticeEmailJob < ApplicationJob
|
||||||
def run(domain_id, new_registrant_id)
|
def perform(domain_id, new_registrant_id)
|
||||||
domain = Domain.find(domain_id)
|
domain = Domain.find(domain_id)
|
||||||
new_registrant = Registrant.find(new_registrant_id)
|
new_registrant = Registrant.find(new_registrant_id)
|
||||||
log(domain, new_registrant)
|
log(domain, new_registrant)
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
class SendEInvoiceJob < Que::Job
|
class SendEInvoiceJob < ApplicationJob
|
||||||
def run(invoice_id, payable = true)
|
discard_on HTTPClient::TimeoutError
|
||||||
invoice = run_condition(Invoice.find_by(id: invoice_id), payable: payable)
|
|
||||||
|
|
||||||
invoice.to_e_invoice(payable: payable).deliver
|
def perform(invoice_id, payable = true)
|
||||||
ActiveRecord::Base.transaction do
|
invoice = Invoice.find_by(id: invoice_id)
|
||||||
invoice.update(e_invoice_sent_at: Time.zone.now)
|
return unless need_to_process_invoice?(invoice: invoice, payable: payable)
|
||||||
log_success(invoice)
|
|
||||||
destroy
|
process(invoice: invoice, payable: payable)
|
||||||
end
|
|
||||||
rescue StandardError => e
|
rescue StandardError => e
|
||||||
log_error(invoice: invoice, error: e)
|
log_error(invoice: invoice, error: e)
|
||||||
raise e
|
raise e
|
||||||
|
@ -15,10 +13,17 @@ class SendEInvoiceJob < Que::Job
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def run_condition(invoice, payable: true)
|
def need_to_process_invoice?(invoice:, payable:)
|
||||||
destroy unless invoice
|
return false if invoice.blank?
|
||||||
destroy if invoice.do_not_send_e_invoice? && payable
|
return false if invoice.do_not_send_e_invoice? && payable
|
||||||
invoice
|
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
def process(invoice:, payable:)
|
||||||
|
invoice.to_e_invoice(payable: payable).deliver
|
||||||
|
invoice.update(e_invoice_sent_at: Time.zone.now)
|
||||||
|
log_success(invoice)
|
||||||
end
|
end
|
||||||
|
|
||||||
def log_success(invoice)
|
def log_success(invoice)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
class UpdateWhoisRecordJob < Que::Job
|
class UpdateWhoisRecordJob < ApplicationJob
|
||||||
def run(names, type)
|
def perform(names, type)
|
||||||
Whois::Update.run(names: [names].flatten, type: type)
|
Whois::Update.run(names: [names].flatten, type: type)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,14 +1,11 @@
|
||||||
class VerifyEmailsJob < Que::Job
|
class VerifyEmailsJob < ApplicationJob
|
||||||
def run(verification_id)
|
discard_on StandardError
|
||||||
email_address_verification = run_condition(EmailAddressVerification.find(verification_id))
|
|
||||||
|
|
||||||
return if email_address_verification.recently_verified?
|
def perform(verification_id)
|
||||||
|
email_address_verification = EmailAddressVerification.find(verification_id)
|
||||||
|
return unless need_to_verify?(email_address_verification)
|
||||||
|
|
||||||
ActiveRecord::Base.transaction do
|
process(email_address_verification)
|
||||||
email_address_verification.verify
|
|
||||||
log_success(email_address_verification)
|
|
||||||
destroy
|
|
||||||
end
|
|
||||||
rescue StandardError => e
|
rescue StandardError => e
|
||||||
log_error(verification: email_address_verification, error: e)
|
log_error(verification: email_address_verification, error: e)
|
||||||
raise e
|
raise e
|
||||||
|
@ -16,11 +13,16 @@ class VerifyEmailsJob < Que::Job
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def run_condition(email_address_verification)
|
def need_to_verify?(email_address_verification)
|
||||||
destroy unless email_address_verification
|
return false if email_address_verification.blank?
|
||||||
destroy if email_address_verification.recently_verified?
|
return false if email_address_verification.recently_verified?
|
||||||
|
|
||||||
email_address_verification
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
def process(email_address_verification)
|
||||||
|
email_address_verification.verify
|
||||||
|
log_success(email_address_verification)
|
||||||
end
|
end
|
||||||
|
|
||||||
def logger
|
def logger
|
||||||
|
|
|
@ -34,6 +34,6 @@ class BlockedDomain < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove_data
|
def remove_data
|
||||||
UpdateWhoisRecordJob.enqueue name, 'blocked'
|
UpdateWhoisRecordJob.perform_later name, 'blocked'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,11 +7,14 @@ module Domain::Deletable
|
||||||
DomainStatus::FORCE_DELETE,
|
DomainStatus::FORCE_DELETE,
|
||||||
].freeze
|
].freeze
|
||||||
|
|
||||||
|
def deletion_time
|
||||||
|
@deletion_time ||= Time.zone.at(rand(deletion_time_span))
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def delete_later
|
def delete_later
|
||||||
deletion_time = Time.zone.at(rand(deletion_time_span))
|
DomainDeleteJob.set(wait_until: deletion_time).perform_later(id)
|
||||||
DomainDeleteJob.enqueue(id, run_at: deletion_time, priority: 1)
|
|
||||||
logger.info "Domain #{name} is scheduled to be deleted around #{deletion_time}"
|
logger.info "Domain #{name} is scheduled to be deleted around #{deletion_time}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ module Invoice::Payable
|
||||||
end
|
end
|
||||||
|
|
||||||
def paid?
|
def paid?
|
||||||
account_activity
|
account_activity.present?
|
||||||
end
|
end
|
||||||
|
|
||||||
def receipt_date
|
def receipt_date
|
||||||
|
|
|
@ -11,7 +11,7 @@ module Zone::WhoisQueryable
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_whois_record
|
def update_whois_record
|
||||||
UpdateWhoisRecordJob.enqueue origin, 'zone'
|
UpdateWhoisRecordJob.perform_later origin, 'zone'
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate_data
|
def generate_data
|
||||||
|
|
|
@ -492,7 +492,7 @@ class Contact < ApplicationRecord
|
||||||
return if saved_changes.slice(*(self.class.column_names - ignored_columns)).empty?
|
return if saved_changes.slice(*(self.class.column_names - ignored_columns)).empty?
|
||||||
|
|
||||||
names = related_domain_descriptions.keys
|
names = related_domain_descriptions.keys
|
||||||
UpdateWhoisRecordJob.enqueue(names, 'domain') if names.present?
|
UpdateWhoisRecordJob.perform_later(names, 'domain') if names.present?
|
||||||
end
|
end
|
||||||
|
|
||||||
def children_log
|
def children_log
|
||||||
|
|
|
@ -84,7 +84,7 @@ class Dispute < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove_data
|
def remove_data
|
||||||
UpdateWhoisRecordJob.enqueue domain_name, 'disputed'
|
UpdateWhoisRecordJob.perform_later domain_name, 'disputed'
|
||||||
end
|
end
|
||||||
|
|
||||||
def fill_empty_passwords
|
def fill_empty_passwords
|
||||||
|
|
|
@ -425,8 +425,8 @@ class Domain < ApplicationRecord
|
||||||
new_registrant_email = registrant.email
|
new_registrant_email = registrant.email
|
||||||
new_registrant_name = registrant.name
|
new_registrant_name = registrant.name
|
||||||
|
|
||||||
RegistrantChangeConfirmEmailJob.enqueue(id, new_registrant_id)
|
RegistrantChangeConfirmEmailJob.perform_later(id, new_registrant_id)
|
||||||
RegistrantChangeNoticeEmailJob.enqueue(id, new_registrant_id)
|
RegistrantChangeNoticeEmailJob.perform_later(id, new_registrant_id)
|
||||||
|
|
||||||
reload
|
reload
|
||||||
|
|
||||||
|
@ -670,7 +670,7 @@ class Domain < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_whois_record
|
def update_whois_record
|
||||||
UpdateWhoisRecordJob.enqueue name, 'domain'
|
UpdateWhoisRecordJob.perform_later name, 'domain'
|
||||||
end
|
end
|
||||||
|
|
||||||
def status_notes_array=(notes)
|
def status_notes_array=(notes)
|
||||||
|
|
|
@ -30,12 +30,12 @@ class RegistrantVerification < ApplicationRecord
|
||||||
def domain_registrant_delete_confirm!(initiator)
|
def domain_registrant_delete_confirm!(initiator)
|
||||||
self.action_type = DOMAIN_DELETE
|
self.action_type = DOMAIN_DELETE
|
||||||
self.action = CONFIRMED
|
self.action = CONFIRMED
|
||||||
DomainDeleteConfirmJob.perform_later domain.id, CONFIRMED, initiator if save
|
DomainDeleteConfirmJob.perform_later(domain.id, CONFIRMED, initiator) if save
|
||||||
end
|
end
|
||||||
|
|
||||||
def domain_registrant_delete_reject!(initiator)
|
def domain_registrant_delete_reject!(initiator)
|
||||||
self.action_type = DOMAIN_DELETE
|
self.action_type = DOMAIN_DELETE
|
||||||
self.action = REJECTED
|
self.action = REJECTED
|
||||||
DomainDeleteConfirmJob.perform_later domain.id, REJECTED, initiator if save
|
DomainDeleteConfirmJob.perform_later(domain.id, REJECTED, initiator) if save
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -43,7 +43,7 @@ class Registrar < ApplicationRecord
|
||||||
after_commit :update_whois_records
|
after_commit :update_whois_records
|
||||||
def update_whois_records
|
def update_whois_records
|
||||||
return true unless changed? && (changes.keys & WHOIS_TRIGGERS).present?
|
return true unless changed? && (changes.keys & WHOIS_TRIGGERS).present?
|
||||||
RegenerateRegistrarWhoisesJob.enqueue id
|
RegenerateRegistrarWhoisesJob.perform_later id
|
||||||
end
|
end
|
||||||
|
|
||||||
self.ignored_columns = %w[legacy_id]
|
self.ignored_columns = %w[legacy_id]
|
||||||
|
@ -104,7 +104,7 @@ class Registrar < ApplicationRecord
|
||||||
InvoiceMailer.invoice_email(invoice: invoice, recipient: billing_email).deliver_now
|
InvoiceMailer.invoice_email(invoice: invoice, recipient: billing_email).deliver_now
|
||||||
end
|
end
|
||||||
|
|
||||||
SendEInvoiceJob.enqueue(invoice.id, payable)
|
SendEInvoiceJob.perform_later(invoice.id, payable)
|
||||||
|
|
||||||
invoice
|
invoice
|
||||||
end
|
end
|
||||||
|
|
|
@ -59,6 +59,6 @@ class ReservedDomain < ApplicationRecord
|
||||||
alias_method :update_whois_record, :generate_data
|
alias_method :update_whois_record, :generate_data
|
||||||
|
|
||||||
def remove_data
|
def remove_data
|
||||||
UpdateWhoisRecordJob.enqueue name, 'reserved'
|
UpdateWhoisRecordJob.perform_later name, 'reserved'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -44,6 +44,8 @@ module DomainNameRegistry
|
||||||
|
|
||||||
config.active_record.schema_format = :sql
|
config.active_record.schema_format = :sql
|
||||||
|
|
||||||
|
config.active_job.queue_adapter = :que
|
||||||
|
|
||||||
config.generators do |g|
|
config.generators do |g|
|
||||||
g.stylesheets false
|
g.stylesheets false
|
||||||
g.javascripts false
|
g.javascripts false
|
||||||
|
|
|
@ -56,7 +56,7 @@ Rails.application.configure do
|
||||||
# config.cache_store = :mem_cache_store
|
# config.cache_store = :mem_cache_store
|
||||||
|
|
||||||
# Use a real queuing backend for Active Job (and separate queues per environment)
|
# Use a real queuing backend for Active Job (and separate queues per environment)
|
||||||
# config.active_job.queue_adapter = :resque
|
config.active_job.queue_adapter = :que
|
||||||
# config.active_job.queue_name_prefix = "domain_name_registry_#{Rails.env}"
|
# config.active_job.queue_name_prefix = "domain_name_registry_#{Rails.env}"
|
||||||
config.action_mailer.perform_caching = false
|
config.action_mailer.perform_caching = false
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,8 @@ Rails.application.configure do
|
||||||
# preloads Rails for running tests, you may have to set it to true.
|
# preloads Rails for running tests, you may have to set it to true.
|
||||||
config.eager_load = false
|
config.eager_load = false
|
||||||
|
|
||||||
|
config.active_job.queue_adapter = :test
|
||||||
|
|
||||||
config.consider_all_requests_local = true
|
config.consider_all_requests_local = true
|
||||||
config.action_controller.perform_caching = false
|
config.action_controller.perform_caching = false
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ namespace :verify_email do
|
||||||
verifications_by_domain = EmailAddressVerification.not_verified_recently.group_by(&:domain)
|
verifications_by_domain = EmailAddressVerification.not_verified_recently.group_by(&:domain)
|
||||||
verifications_by_domain.each do |_domain, verifications|
|
verifications_by_domain.each do |_domain, verifications|
|
||||||
ver = verifications.sample # Verify random email to not to clog the SMTP servers
|
ver = verifications.sample # Verify random email to not to clog the SMTP servers
|
||||||
VerifyEmailsJob.enqueue(ver.id)
|
VerifyEmailsJob.perform_later(ver.id)
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -18,6 +18,6 @@ namespace :verify_email do
|
||||||
|
|
||||||
verifications_by_domain = EmailAddressVerification.not_verified_recently
|
verifications_by_domain = EmailAddressVerification.not_verified_recently
|
||||||
.by_domain(args[:domain_name])
|
.by_domain(args[:domain_name])
|
||||||
verifications_by_domain.map { |ver| VerifyEmailsJob.enqueue(ver.id) }
|
verifications_by_domain.map { |ver| VerifyEmailsJob.perform_later(ver.id) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -23,22 +23,23 @@ namespace :whois do
|
||||||
|
|
||||||
print "\n-----> Update domains whois_records"
|
print "\n-----> Update domains whois_records"
|
||||||
Domain.find_in_batches.each do |group|
|
Domain.find_in_batches.each do |group|
|
||||||
UpdateWhoisRecordJob.enqueue group.map(&:name), 'domain'
|
UpdateWhoisRecordJob.perform_later group.map(&:name), 'domain'
|
||||||
end
|
end
|
||||||
|
|
||||||
print "\n-----> Update blocked domains whois_records"
|
print "\n-----> Update blocked domains whois_records"
|
||||||
BlockedDomain.find_in_batches.each do |group|
|
BlockedDomain.find_in_batches.each do |group|
|
||||||
UpdateWhoisRecordJob.enqueue group.map(&:name), 'blocked'
|
UpdateWhoisRecordJob.perform_later group.map(&:name), 'blocked'
|
||||||
end
|
end
|
||||||
|
|
||||||
print "\n-----> Update reserved domains whois_records"
|
print "\n-----> Update reserved domains whois_records"
|
||||||
ReservedDomain.find_in_batches.each do |group|
|
ReservedDomain.find_in_batches.each do |group|
|
||||||
UpdateWhoisRecordJob.enqueue group.map(&:name), 'reserved'
|
UpdateWhoisRecordJob.perform_later group.map(&:name), 'reserved'
|
||||||
end
|
end
|
||||||
|
|
||||||
print "\n-----> Update disputed domains whois_records"
|
print "\n-----> Update disputed domains whois_records"
|
||||||
Dispute.active.find_in_batches.each do |group|
|
Dispute.active.find_in_batches.each do |group|
|
||||||
UpdateWhoisRecordJob.enqueue group.map(&:domain_name), 'disputed'
|
|
||||||
|
UpdateWhoisRecordJob.perform_later group.map(&:domain_name), 'disputed'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
puts "\n-----> all done in #{(Time.zone.now.to_f - start).round(2)} seconds"
|
puts "\n-----> all done in #{(Time.zone.now.to_f - start).round(2)} seconds"
|
||||||
|
|
|
@ -92,12 +92,13 @@ class EppDomainDeleteBaseTest < EppTestCase
|
||||||
perform_enqueued_jobs do
|
perform_enqueued_jobs do
|
||||||
post epp_delete_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
|
post epp_delete_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
|
||||||
end
|
end
|
||||||
|
|
||||||
@domain.reload
|
@domain.reload
|
||||||
|
|
||||||
assert @domain.registrant_verification_asked?
|
assert @domain.registrant_verification_asked?
|
||||||
assert @domain.pending_delete_confirmation?
|
assert @domain.pending_delete_confirmation?
|
||||||
assert_emails 1
|
|
||||||
assert_epp_response :completed_successfully_action_pending
|
assert_epp_response :completed_successfully_action_pending
|
||||||
|
assert_emails 1
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_skips_registrant_confirmation_when_not_required
|
def test_skips_registrant_confirmation_when_not_required
|
||||||
|
|
|
@ -2,6 +2,7 @@ require 'test_helper'
|
||||||
|
|
||||||
class EppDomainUpdateBaseTest < EppTestCase
|
class EppDomainUpdateBaseTest < EppTestCase
|
||||||
include ActionMailer::TestHelper
|
include ActionMailer::TestHelper
|
||||||
|
include ActiveJob::TestHelper
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
@domain = domains(:shop)
|
@domain = domains(:shop)
|
||||||
|
@ -134,15 +135,17 @@ class EppDomainUpdateBaseTest < EppTestCase
|
||||||
</epp>
|
</epp>
|
||||||
XML
|
XML
|
||||||
|
|
||||||
post epp_update_path, params: { frame: request_xml },
|
assert_no_enqueued_jobs
|
||||||
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
|
assert_enqueued_jobs 3 do
|
||||||
|
post epp_update_path, params: { frame: request_xml },
|
||||||
|
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
|
||||||
|
end
|
||||||
@domain.reload
|
@domain.reload
|
||||||
|
|
||||||
assert_epp_response :completed_successfully_action_pending
|
assert_epp_response :completed_successfully_action_pending
|
||||||
assert_not_equal new_registrant, @domain.registrant
|
assert_not_equal new_registrant, @domain.registrant
|
||||||
assert @domain.registrant_verification_asked?
|
assert @domain.registrant_verification_asked?
|
||||||
assert_includes @domain.statuses, DomainStatus::PENDING_UPDATE
|
assert_includes @domain.statuses, DomainStatus::PENDING_UPDATE
|
||||||
assert_verification_and_notification_emails
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_domain_should_doesnt_have_pending_update_when_updated_registrant_with_same_idents_data
|
def test_domain_should_doesnt_have_pending_update_when_updated_registrant_with_same_idents_data
|
||||||
|
@ -211,15 +214,17 @@ class EppDomainUpdateBaseTest < EppTestCase
|
||||||
</epp>
|
</epp>
|
||||||
XML
|
XML
|
||||||
|
|
||||||
post epp_update_path, params: { frame: request_xml },
|
assert_no_enqueued_jobs
|
||||||
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
|
assert_enqueued_jobs 3 do
|
||||||
|
post epp_update_path, params: { frame: request_xml },
|
||||||
|
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
|
||||||
|
end
|
||||||
@domain.reload
|
@domain.reload
|
||||||
|
|
||||||
assert_epp_response :completed_successfully_action_pending
|
assert_epp_response :completed_successfully_action_pending
|
||||||
assert_not_equal new_registrant, @domain.registrant
|
assert_not_equal new_registrant, @domain.registrant
|
||||||
assert @domain.registrant_verification_asked?
|
assert @domain.registrant_verification_asked?
|
||||||
assert_includes @domain.statuses, DomainStatus::PENDING_UPDATE
|
assert_includes @domain.statuses, DomainStatus::PENDING_UPDATE
|
||||||
assert_verification_and_notification_emails
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_updates_registrant_when_legaldoc_is_not_mandatory
|
def test_updates_registrant_when_legaldoc_is_not_mandatory
|
||||||
|
@ -247,15 +252,17 @@ class EppDomainUpdateBaseTest < EppTestCase
|
||||||
</epp>
|
</epp>
|
||||||
XML
|
XML
|
||||||
|
|
||||||
post epp_update_path, params: { frame: request_xml },
|
assert_no_enqueued_jobs
|
||||||
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
|
assert_enqueued_jobs 3 do
|
||||||
|
post epp_update_path, params: { frame: request_xml },
|
||||||
|
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
|
||||||
|
end
|
||||||
@domain.reload
|
@domain.reload
|
||||||
|
|
||||||
assert_epp_response :completed_successfully_action_pending
|
assert_epp_response :completed_successfully_action_pending
|
||||||
assert_not_equal new_registrant, @domain.registrant
|
assert_not_equal new_registrant, @domain.registrant
|
||||||
assert @domain.registrant_verification_asked?
|
assert @domain.registrant_verification_asked?
|
||||||
assert_includes @domain.statuses, DomainStatus::PENDING_UPDATE
|
assert_includes @domain.statuses, DomainStatus::PENDING_UPDATE
|
||||||
assert_verification_and_notification_emails
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_dows_not_update_registrant_when_legaldoc_is_mandatory
|
def test_dows_not_update_registrant_when_legaldoc_is_mandatory
|
||||||
|
|
45
test/jobs/active_job_queuing_test.rb
Normal file
45
test/jobs/active_job_queuing_test.rb
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
$VERBOSE=nil
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class ActiveJobQueuingTest < ActiveJob::TestCase
|
||||||
|
|
||||||
|
def test_job_discarded_after_error
|
||||||
|
assert_no_enqueued_jobs
|
||||||
|
assert_performed_jobs 1 do
|
||||||
|
TestDiscardedJob.perform_later
|
||||||
|
end
|
||||||
|
assert_no_enqueued_jobs
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_job_retried_after_error
|
||||||
|
assert_no_enqueued_jobs
|
||||||
|
assert_raises StandardError do
|
||||||
|
assert_performed_jobs 3 do
|
||||||
|
TestRetriedJob.perform_later
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_no_enqueued_jobs
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
class TestDiscardedJob < ApplicationJob
|
||||||
|
queue_as :default
|
||||||
|
|
||||||
|
discard_on StandardError
|
||||||
|
|
||||||
|
def perform
|
||||||
|
raise StandardError
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class TestRetriedJob < ApplicationJob
|
||||||
|
queue_as :default
|
||||||
|
|
||||||
|
retry_on StandardError, wait: 2.seconds, attempts: 3
|
||||||
|
|
||||||
|
def perform
|
||||||
|
raise StandardError
|
||||||
|
end
|
||||||
|
end
|
|
@ -38,7 +38,7 @@ class DirectoInvoiceForwardJobTest < ActiveSupport::TestCase
|
||||||
end.to_return(status: 200, body: response)
|
end.to_return(status: 200, body: response)
|
||||||
|
|
||||||
assert_nothing_raised do
|
assert_nothing_raised do
|
||||||
DirectoInvoiceForwardJob.run(monthly: false, dry: false)
|
DirectoInvoiceForwardJob.perform_now(monthly: false, dry: false)
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_not_empty @invoice.directo_records.first.request
|
assert_not_empty @invoice.directo_records.first.request
|
||||||
|
@ -52,7 +52,7 @@ class DirectoInvoiceForwardJobTest < ActiveSupport::TestCase
|
||||||
Setting.directo_monthly_number_max = 30991
|
Setting.directo_monthly_number_max = 30991
|
||||||
|
|
||||||
assert_raises 'RuntimeError' do
|
assert_raises 'RuntimeError' do
|
||||||
DirectoInvoiceForwardJob.run(monthly: true, dry: false)
|
DirectoInvoiceForwardJob.perform_now(monthly: true, dry: false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ class DirectoInvoiceForwardJobTest < ActiveSupport::TestCase
|
||||||
end.to_return(status: 200, body: response)
|
end.to_return(status: 200, body: response)
|
||||||
|
|
||||||
assert_difference 'Setting.directo_monthly_number_last' do
|
assert_difference 'Setting.directo_monthly_number_last' do
|
||||||
DirectoInvoiceForwardJob.run(monthly: true, dry: false)
|
DirectoInvoiceForwardJob.perform_now(monthly: true, dry: false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ class DirectoInvoiceForwardJobTest < ActiveSupport::TestCase
|
||||||
end.to_return(status: 200, body: response)
|
end.to_return(status: 200, body: response)
|
||||||
|
|
||||||
assert_difference 'Setting.directo_monthly_number_last' do
|
assert_difference 'Setting.directo_monthly_number_last' do
|
||||||
DirectoInvoiceForwardJob.run(monthly: true, dry: false)
|
DirectoInvoiceForwardJob.perform_now(monthly: true, dry: false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -126,7 +126,7 @@ class DirectoInvoiceForwardJobTest < ActiveSupport::TestCase
|
||||||
end.to_return(status: 200, body: response)
|
end.to_return(status: 200, body: response)
|
||||||
|
|
||||||
assert_difference 'Setting.directo_monthly_number_last' do
|
assert_difference 'Setting.directo_monthly_number_last' do
|
||||||
DirectoInvoiceForwardJob.run(monthly: true, dry: false)
|
DirectoInvoiceForwardJob.perform_now(monthly: true, dry: false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -148,7 +148,7 @@ class DirectoInvoiceForwardJobTest < ActiveSupport::TestCase
|
||||||
end.to_return(status: 200, body: response)
|
end.to_return(status: 200, body: response)
|
||||||
|
|
||||||
assert_difference 'Setting.directo_monthly_number_last' do
|
assert_difference 'Setting.directo_monthly_number_last' do
|
||||||
DirectoInvoiceForwardJob.run(monthly: true, dry: false)
|
DirectoInvoiceForwardJob.perform_now(monthly: true, dry: false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -186,7 +186,7 @@ class DirectoInvoiceForwardJobTest < ActiveSupport::TestCase
|
||||||
(body.include? 'StartDate') && (body.include? 'EndDate') && (body.include? 'goodnames')
|
(body.include? 'StartDate') && (body.include? 'EndDate') && (body.include? 'goodnames')
|
||||||
end.to_return(status: 200, body: response)
|
end.to_return(status: 200, body: response)
|
||||||
|
|
||||||
DirectoInvoiceForwardJob.run(monthly: true, dry: false)
|
DirectoInvoiceForwardJob.perform_now(monthly: true, dry: false)
|
||||||
|
|
||||||
assert_requested first_registrar_stub
|
assert_requested first_registrar_stub
|
||||||
assert_requested second_registrar_stub
|
assert_requested second_registrar_stub
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
require "test_helper"
|
require "test_helper"
|
||||||
|
|
||||||
class DisputeStatusUpdateJobTest < ActiveSupport::TestCase
|
class DisputeStatusUpdateJobTest < ActiveJob::TestCase
|
||||||
setup do
|
setup do
|
||||||
travel_to Time.zone.parse('2010-10-05')
|
travel_to Time.zone.parse('2010-10-05')
|
||||||
@logger = Rails.logger
|
@logger = Rails.logger
|
||||||
|
@ -8,13 +8,13 @@ class DisputeStatusUpdateJobTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
def test_nothing_is_raised
|
def test_nothing_is_raised
|
||||||
assert_nothing_raised do
|
assert_nothing_raised do
|
||||||
DisputeStatusUpdateJob.run(logger: @logger)
|
DisputeStatusUpdateJob.perform_now(logger: @logger)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_whois_data_added_when_dispute_activated
|
def test_whois_data_added_when_dispute_activated
|
||||||
dispute = disputes(:future)
|
dispute = disputes(:future)
|
||||||
DisputeStatusUpdateJob.run(logger: @logger)
|
DisputeStatusUpdateJob.perform_now(logger: @logger)
|
||||||
|
|
||||||
whois_record = Whois::Record.find_by(name: dispute.domain_name)
|
whois_record = Whois::Record.find_by(name: dispute.domain_name)
|
||||||
assert whois_record.present?
|
assert whois_record.present?
|
||||||
|
@ -25,7 +25,7 @@ class DisputeStatusUpdateJobTest < ActiveSupport::TestCase
|
||||||
dispute = disputes(:active)
|
dispute = disputes(:active)
|
||||||
dispute.update!(starts_at: Time.zone.today - 3.years - 1.day)
|
dispute.update!(starts_at: Time.zone.today - 3.years - 1.day)
|
||||||
|
|
||||||
DisputeStatusUpdateJob.run(logger: @logger)
|
DisputeStatusUpdateJob.perform_now(logger: @logger)
|
||||||
dispute.reload
|
dispute.reload
|
||||||
|
|
||||||
assert dispute.closed
|
assert dispute.closed
|
||||||
|
@ -37,7 +37,9 @@ class DisputeStatusUpdateJobTest < ActiveSupport::TestCase
|
||||||
def test_registered_domain_whois_data_is_added
|
def test_registered_domain_whois_data_is_added
|
||||||
Dispute.create(domain_name: 'shop.test', starts_at: '2010-07-05')
|
Dispute.create(domain_name: 'shop.test', starts_at: '2010-07-05')
|
||||||
travel_to Time.zone.parse('2010-07-05')
|
travel_to Time.zone.parse('2010-07-05')
|
||||||
DisputeStatusUpdateJob.run(logger: @logger)
|
perform_enqueued_jobs do
|
||||||
|
DisputeStatusUpdateJob.perform_now(logger: @logger)
|
||||||
|
end
|
||||||
|
|
||||||
whois_record = Whois::Record.find_by(name: 'shop.test')
|
whois_record = Whois::Record.find_by(name: 'shop.test')
|
||||||
assert_includes whois_record.json['status'], 'disputed'
|
assert_includes whois_record.json['status'], 'disputed'
|
||||||
|
@ -53,7 +55,9 @@ class DisputeStatusUpdateJobTest < ActiveSupport::TestCase
|
||||||
force_delete_date: nil)
|
force_delete_date: nil)
|
||||||
|
|
||||||
# Dispute status is added automatically if starts_at is not in future
|
# Dispute status is added automatically if starts_at is not in future
|
||||||
Dispute.create(domain_name: 'shop.test', starts_at: Time.zone.parse('2010-07-05'))
|
perform_enqueued_jobs do
|
||||||
|
Dispute.create(domain_name: 'shop.test', starts_at: Time.zone.parse('2010-07-05'))
|
||||||
|
end
|
||||||
domain.reload
|
domain.reload
|
||||||
|
|
||||||
whois_record = Whois::Record.find_by(name: 'shop.test')
|
whois_record = Whois::Record.find_by(name: 'shop.test')
|
||||||
|
@ -62,7 +66,9 @@ class DisputeStatusUpdateJobTest < ActiveSupport::TestCase
|
||||||
# Dispute status is removed night time day after it's ended
|
# Dispute status is removed night time day after it's ended
|
||||||
travel_to Time.zone.parse('2010-07-05') + 3.years + 1.day
|
travel_to Time.zone.parse('2010-07-05') + 3.years + 1.day
|
||||||
|
|
||||||
DisputeStatusUpdateJob.run(logger: @logger)
|
perform_enqueued_jobs do
|
||||||
|
DisputeStatusUpdateJob.perform_now(logger: @logger)
|
||||||
|
end
|
||||||
|
|
||||||
whois_record.reload
|
whois_record.reload
|
||||||
assert_not whois_record.json['status'].include? 'disputed'
|
assert_not whois_record.json['status'].include? 'disputed'
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
class RegenerateSubzoneWhoisesJobTest < ActiveSupport::TestCase
|
class RegenerateSubzoneWhoisesJobTest < ActiveJob::TestCase
|
||||||
def test_regenerates_whois_data_only_for_subzones
|
def test_regenerates_whois_data_only_for_subzones
|
||||||
subzone = dns_zones(:one).dup
|
subzone = dns_zones(:one).dup
|
||||||
subzone.origin = 'subzone.test'
|
subzone.origin = 'subzone.test'
|
||||||
|
@ -11,7 +11,9 @@ class RegenerateSubzoneWhoisesJobTest < ActiveSupport::TestCase
|
||||||
assert_nil Whois::Record.find_by(name: subzone.origin)
|
assert_nil Whois::Record.find_by(name: subzone.origin)
|
||||||
assert_nil Whois::Record.find_by(name: dns_zones(:one).origin)
|
assert_nil Whois::Record.find_by(name: dns_zones(:one).origin)
|
||||||
|
|
||||||
RegenerateSubzoneWhoisesJob.run
|
perform_enqueued_jobs do
|
||||||
|
RegenerateSubzoneWhoisesJob.perform_now
|
||||||
|
end
|
||||||
record = Whois::Record.find_by(name: subzone.origin)
|
record = Whois::Record.find_by(name: subzone.origin)
|
||||||
assert record
|
assert record
|
||||||
assert record.json['dnssec_keys'].is_a?(Array)
|
assert record.json['dnssec_keys'].is_a?(Array)
|
||||||
|
|
|
@ -11,7 +11,7 @@ class RegistrantChangeConfirmEmailJobTest < ActiveSupport::TestCase
|
||||||
domain_id = domains(:shop).id
|
domain_id = domains(:shop).id
|
||||||
new_registrant_id = contacts(:william).id
|
new_registrant_id = contacts(:william).id
|
||||||
|
|
||||||
RegistrantChangeConfirmEmailJob.enqueue(domain_id, new_registrant_id)
|
RegistrantChangeConfirmEmailJob.perform_now(domain_id, new_registrant_id)
|
||||||
|
|
||||||
assert_emails 1
|
assert_emails 1
|
||||||
end
|
end
|
||||||
|
|
24
test/jobs/registrant_change_expired_email_job_test.rb
Normal file
24
test/jobs/registrant_change_expired_email_job_test.rb
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class RegistrantChangeExpiredEmailJobTest < ActiveJob::TestCase
|
||||||
|
include ActionMailer::TestHelper
|
||||||
|
|
||||||
|
setup do
|
||||||
|
ActionMailer::Base.deliveries.clear
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_delivers_email
|
||||||
|
domain = domains(:shop)
|
||||||
|
domain.update!(pending_json: {new_registrant_email: 'aaa@bbb.com'})
|
||||||
|
domain_id = domain.id
|
||||||
|
|
||||||
|
assert_performed_jobs 1 do
|
||||||
|
perform_enqueued_jobs do
|
||||||
|
RegistrantChangeExpiredEmailJob.perform_later(domain_id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_emails 1
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -11,7 +11,7 @@ class RegistrantChangeNoticeEmailJobTest < ActiveSupport::TestCase
|
||||||
domain_id = domains(:shop).id
|
domain_id = domains(:shop).id
|
||||||
new_registrant_id = contacts(:william).id
|
new_registrant_id = contacts(:william).id
|
||||||
|
|
||||||
RegistrantChangeNoticeEmailJob.enqueue(domain_id, new_registrant_id)
|
RegistrantChangeNoticeEmailJob.perform_now(domain_id, new_registrant_id)
|
||||||
|
|
||||||
assert_emails 1
|
assert_emails 1
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,43 +1,22 @@
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
class SendEInvoiceJobTest < ActiveSupport::TestCase
|
class SendEInvoiceJobTest < ActiveJob::TestCase
|
||||||
|
|
||||||
def teardown
|
def teardown
|
||||||
EInvoice.provider = EInvoice::Providers::TestProvider.new
|
EInvoice.provider = EInvoice::Providers::TestProvider.new
|
||||||
EInvoice::Providers::TestProvider.deliveries.clear
|
EInvoice::Providers::TestProvider.deliveries.clear
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_if_invoice_is_sended
|
def test_if_invoice_is_sent
|
||||||
@invoice = invoices(:one)
|
@invoice = invoices(:one)
|
||||||
|
@invoice.account_activity.destroy
|
||||||
EInvoice.provider = EInvoice::Providers::TestProvider.new
|
EInvoice.provider = EInvoice::Providers::TestProvider.new
|
||||||
EInvoice::Providers::TestProvider.deliveries.clear
|
EInvoice::Providers::TestProvider.deliveries.clear
|
||||||
|
|
||||||
assert_nothing_raised do
|
assert_nothing_raised do
|
||||||
SendEInvoiceJob.enqueue(@invoice.id, true)
|
perform_enqueued_jobs do
|
||||||
end
|
SendEInvoiceJob.perform_now(@invoice.id, true)
|
||||||
@invoice.reload
|
end
|
||||||
|
|
||||||
assert_not @invoice.e_invoice_sent_at.blank?
|
|
||||||
assert_equal 1, EInvoice::Providers::TestProvider.deliveries.count
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_if_invoice_sending_retries
|
|
||||||
@invoice = invoices(:one)
|
|
||||||
provider_config = { password: nil,
|
|
||||||
test_mode: true }
|
|
||||||
EInvoice.provider = EInvoice::Providers::OmnivaProvider.new(provider_config)
|
|
||||||
stub_request(:get, "https://testfinance.post.ee/finance/erp/erpServices.wsdl").to_timeout
|
|
||||||
|
|
||||||
assert_raise HTTPClient::TimeoutError do
|
|
||||||
SendEInvoiceJob.enqueue(@invoice.id, true)
|
|
||||||
end
|
|
||||||
assert @invoicee_invoice_sent_at.blank?
|
|
||||||
|
|
||||||
EInvoice.provider = EInvoice::Providers::TestProvider.new
|
|
||||||
EInvoice::Providers::TestProvider.deliveries.clear
|
|
||||||
|
|
||||||
assert_nothing_raised do
|
|
||||||
SendEInvoiceJob.enqueue(@invoice.id, true)
|
|
||||||
end
|
end
|
||||||
@invoice.reload
|
@invoice.reload
|
||||||
|
|
||||||
|
|
28
test/jobs/update_whois_record_job_test.rb
Normal file
28
test/jobs/update_whois_record_job_test.rb
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class SendEInvoiceJobTest < ActiveJob::TestCase
|
||||||
|
|
||||||
|
def test_job_is_updating_domains
|
||||||
|
domain_names = Domain.find_in_batches.first.map(&:name)
|
||||||
|
assert_domains_processed_by_task(domain_names, 'domain')
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_job_is_updating_blocked_domains
|
||||||
|
domain_names = BlockedDomain.find_in_batches.first.map(&:name)
|
||||||
|
assert_domains_processed_by_task(domain_names, 'blocked')
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_job_is_updating_reserved_domains
|
||||||
|
domain_names = ReservedDomain.find_in_batches.first.map(&:name)
|
||||||
|
assert_domains_processed_by_task(domain_names, 'reserved')
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def assert_domains_processed_by_task(domain_names, type)
|
||||||
|
Rake::Task['whois:regenerate'].execute
|
||||||
|
|
||||||
|
perform_enqueued_jobs
|
||||||
|
assert_performed_with(job: UpdateWhoisRecordJob, args: [domain_names, type])
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,6 +1,6 @@
|
||||||
require "test_helper"
|
require "test_helper"
|
||||||
|
|
||||||
class VerifyEmailsJobTest < ActiveSupport::TestCase
|
class VerifyEmailsJobTest < ActiveJob::TestCase
|
||||||
def setup
|
def setup
|
||||||
@contact = contacts(:john)
|
@contact = contacts(:john)
|
||||||
@invalid_contact = contacts(:invalid_email)
|
@invalid_contact = contacts(:invalid_email)
|
||||||
|
@ -33,7 +33,9 @@ class VerifyEmailsJobTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_job_checks_if_email_valid
|
def test_job_checks_if_email_valid
|
||||||
VerifyEmailsJob.run(@contact_verification.id)
|
perform_enqueued_jobs do
|
||||||
|
VerifyEmailsJob.perform_now(@contact_verification.id)
|
||||||
|
end
|
||||||
@contact_verification.reload
|
@contact_verification.reload
|
||||||
|
|
||||||
assert @contact_verification.success
|
assert @contact_verification.success
|
||||||
|
@ -44,14 +46,18 @@ class VerifyEmailsJobTest < ActiveSupport::TestCase
|
||||||
@contact_verification.update(success: true, verified_at: old_verified_at)
|
@contact_verification.update(success: true, verified_at: old_verified_at)
|
||||||
assert @contact_verification.recently_verified?
|
assert @contact_verification.recently_verified?
|
||||||
|
|
||||||
VerifyEmailsJob.run(@contact_verification.id)
|
perform_enqueued_jobs do
|
||||||
|
VerifyEmailsJob.perform_now(@contact_verification.id)
|
||||||
|
end
|
||||||
@contact_verification.reload
|
@contact_verification.reload
|
||||||
|
|
||||||
assert_in_delta @contact_verification.verified_at.to_i, old_verified_at.to_i, 1
|
assert_in_delta @contact_verification.verified_at.to_i, old_verified_at.to_i, 1
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_job_checks_if_email_invalid
|
def test_job_checks_if_email_invalid
|
||||||
VerifyEmailsJob.run(@invalid_contact_verification.id)
|
perform_enqueued_jobs do
|
||||||
|
VerifyEmailsJob.perform_now(@invalid_contact_verification.id)
|
||||||
|
end
|
||||||
@contact_verification.reload
|
@contact_verification.reload
|
||||||
|
|
||||||
refute @contact_verification.success
|
refute @contact_verification.success
|
||||||
|
|
|
@ -37,6 +37,8 @@ class RegistrantChangeMailerPreview < ActionMailer::Preview
|
||||||
def expired
|
def expired
|
||||||
RegistrantChangeMailer.expired(domain: @domain,
|
RegistrantChangeMailer.expired(domain: @domain,
|
||||||
registrar: @domain.registrar,
|
registrar: @domain.registrar,
|
||||||
registrant: @domain.registrant)
|
registrant: @domain.registrant,
|
||||||
|
send_to: [@domain.new_registrant_email,
|
||||||
|
@domain.registrant.email])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
class ContactTest < ActiveSupport::TestCase
|
class ContactTest < ActiveJob::TestCase
|
||||||
setup do
|
setup do
|
||||||
@contact = contacts(:john)
|
@contact = contacts(:john)
|
||||||
@old_validation_type = Truemail.configure.default_validation_type
|
@old_validation_type = Truemail.configure.default_validation_type
|
||||||
|
@ -336,7 +336,9 @@ class ContactTest < ActiveSupport::TestCase
|
||||||
@contact.name = 'SomeReallyWeirdRandomTestName'
|
@contact.name = 'SomeReallyWeirdRandomTestName'
|
||||||
domain = @contact.registrant_domains.first
|
domain = @contact.registrant_domains.first
|
||||||
|
|
||||||
@contact.save!
|
perform_enqueued_jobs do
|
||||||
|
@contact.save!
|
||||||
|
end
|
||||||
|
|
||||||
assert_equal domain.whois_record.try(:json).try(:[], 'registrant'), @contact.name
|
assert_equal domain.whois_record.try(:json).try(:[], 'registrant'), @contact.name
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
class DNS::ZoneTest < ActiveSupport::TestCase
|
class DNS::ZoneTest < ActiveJob::TestCase
|
||||||
def test_valid_zone_fixture_is_valid
|
def test_valid_zone_fixture_is_valid
|
||||||
assert valid_zone.valid?, proc { valid_zone.errors.full_messages }
|
assert valid_zone.valid?, proc { valid_zone.errors.full_messages }
|
||||||
end
|
end
|
||||||
|
@ -134,7 +134,9 @@ class DNS::ZoneTest < ActiveSupport::TestCase
|
||||||
subzone = dns_zones(:one).dup
|
subzone = dns_zones(:one).dup
|
||||||
|
|
||||||
subzone.origin = 'sub.zone'
|
subzone.origin = 'sub.zone'
|
||||||
subzone.save
|
perform_enqueued_jobs do
|
||||||
|
subzone.save
|
||||||
|
end
|
||||||
|
|
||||||
whois_record = Whois::Record.find_by(name: subzone.origin)
|
whois_record = Whois::Record.find_by(name: subzone.origin)
|
||||||
assert whois_record.present?
|
assert whois_record.present?
|
||||||
|
@ -144,7 +146,9 @@ class DNS::ZoneTest < ActiveSupport::TestCase
|
||||||
subzone = dns_zones(:one).dup
|
subzone = dns_zones(:one).dup
|
||||||
|
|
||||||
subzone.origin = 'sub.zone'
|
subzone.origin = 'sub.zone'
|
||||||
subzone.save
|
perform_enqueued_jobs do
|
||||||
|
subzone.save
|
||||||
|
end
|
||||||
|
|
||||||
whois_record = Whois::Record.find_by(name: subzone.origin)
|
whois_record = Whois::Record.find_by(name: subzone.origin)
|
||||||
assert whois_record.present?
|
assert whois_record.present?
|
||||||
|
@ -170,11 +174,15 @@ class DNS::ZoneTest < ActiveSupport::TestCase
|
||||||
subzone = dns_zones(:one).dup
|
subzone = dns_zones(:one).dup
|
||||||
|
|
||||||
subzone.origin = 'sub.zone'
|
subzone.origin = 'sub.zone'
|
||||||
subzone.save
|
perform_enqueued_jobs do
|
||||||
|
subzone.save
|
||||||
|
end
|
||||||
|
|
||||||
assert Whois::Record.find_by(name: subzone.origin).present?
|
assert Whois::Record.find_by(name: subzone.origin).present?
|
||||||
|
|
||||||
subzone.destroy
|
perform_enqueued_jobs do
|
||||||
|
subzone.destroy
|
||||||
|
end
|
||||||
assert_nil Whois::Record.find_by(name: subzone.origin)
|
assert_nil Whois::Record.find_by(name: subzone.origin)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
class DomainReleasableAuctionableTest < ActiveSupport::TestCase
|
class DomainReleasableAuctionableTest < ActiveJob::TestCase
|
||||||
# Needed for `test_updates_whois` test because of `after_commit :update_whois_record` in Domain
|
# Needed for `test_updates_whois` test because of `after_commit :update_whois_record` in Domain
|
||||||
self.use_transactional_tests = false
|
self.use_transactional_tests = false
|
||||||
|
|
||||||
|
@ -65,7 +65,9 @@ class DomainReleasableAuctionableTest < ActiveSupport::TestCase
|
||||||
travel_to Time.zone.parse('2010-07-05')
|
travel_to Time.zone.parse('2010-07-05')
|
||||||
old_whois = @domain.whois_record
|
old_whois = @domain.whois_record
|
||||||
|
|
||||||
Domain.release_domains
|
perform_enqueued_jobs do
|
||||||
|
Domain.release_domains
|
||||||
|
end
|
||||||
|
|
||||||
assert_raises ActiveRecord::RecordNotFound do
|
assert_raises ActiveRecord::RecordNotFound do
|
||||||
old_whois.reload
|
old_whois.reload
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
class DomainReleasableDiscardableTest < ActiveSupport::TestCase
|
class DomainReleasableDiscardableTest < ActiveSupport::TestCase
|
||||||
|
include ActiveJob::TestHelper
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
|
ActiveJob::Base.queue_adapter = :test
|
||||||
@domain = domains(:shop)
|
@domain = domains(:shop)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -64,16 +67,18 @@ class DomainReleasableDiscardableTest < ActiveSupport::TestCase
|
||||||
travel_to Time.zone.parse('2010-07-05')
|
travel_to Time.zone.parse('2010-07-05')
|
||||||
|
|
||||||
@domain.update_columns(delete_date: '2010-07-05')
|
@domain.update_columns(delete_date: '2010-07-05')
|
||||||
Domain.release_domains
|
|
||||||
|
assert_enqueued_with(job: DomainDeleteJob) do
|
||||||
|
Domain.release_domains
|
||||||
|
end
|
||||||
|
|
||||||
other_domain = domains(:airport)
|
other_domain = domains(:airport)
|
||||||
other_domain.update_columns(delete_date: '2010-07-05')
|
other_domain.update_columns(delete_date: '2010-07-05')
|
||||||
Domain.release_domains
|
assert_enqueued_with(job: DomainDeleteJob) do
|
||||||
|
Domain.release_domains
|
||||||
|
end
|
||||||
|
|
||||||
background_job = QueJob.find_by("args->>0 = '#{@domain.id}'", job_class: DomainDeleteJob.name)
|
assert_not other_domain.deletion_time == @domain.deletion_time
|
||||||
other_background_job = QueJob.find_by("args->>0 = '#{other_domain.id}'",
|
|
||||||
job_class: DomainDeleteJob.name)
|
|
||||||
assert_not_equal background_job.run_at, other_background_job.run_at
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_discarding_a_domain_bypasses_validation
|
def test_discarding_a_domain_bypasses_validation
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
class RegistrarTest < ActiveSupport::TestCase
|
class RegistrarTest < ActiveJob::TestCase
|
||||||
setup do
|
setup do
|
||||||
@registrar = registrars(:bestnames)
|
@registrar = registrars(:bestnames)
|
||||||
@original_default_language = Setting.default_language
|
@original_default_language = Setting.default_language
|
||||||
|
@ -213,7 +213,9 @@ class RegistrarTest < ActiveSupport::TestCase
|
||||||
def test_issues_e_invoice_along_with_invoice
|
def test_issues_e_invoice_along_with_invoice
|
||||||
EInvoice::Providers::TestProvider.deliveries.clear
|
EInvoice::Providers::TestProvider.deliveries.clear
|
||||||
|
|
||||||
@registrar.issue_prepayment_invoice(100)
|
perform_enqueued_jobs do
|
||||||
|
@registrar.issue_prepayment_invoice(100)
|
||||||
|
end
|
||||||
|
|
||||||
assert_equal 1, EInvoice::Providers::TestProvider.deliveries.count
|
assert_equal 1, EInvoice::Providers::TestProvider.deliveries.count
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
require 'application_system_test_case'
|
||||||
|
|
||||||
|
class DomainDeleteConfirmsTest < ApplicationSystemTestCase
|
||||||
|
include ActionMailer::TestHelper
|
||||||
|
setup do
|
||||||
|
@user = users(:registrant)
|
||||||
|
sign_in @user
|
||||||
|
|
||||||
|
@domain = domains(:shop)
|
||||||
|
@domain.registrant_verification_asked!('<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<epp></epp>', @user.id)
|
||||||
|
@domain.pending_delete!
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_enqueues_approve_job_after_verification
|
||||||
|
visit registrant_domain_delete_confirm_url(@domain.id, token: @domain.registrant_verification_token)
|
||||||
|
|
||||||
|
click_on 'Confirm domain delete'
|
||||||
|
|
||||||
|
assert_text 'Domain registrant change has successfully received.'
|
||||||
|
|
||||||
|
assert_enqueued_jobs 1, only: DomainDeleteConfirmJob
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_enqueues_reject_job_after_verification
|
||||||
|
visit registrant_domain_delete_confirm_url(@domain.id, token: @domain.registrant_verification_token)
|
||||||
|
|
||||||
|
click_on 'Reject domain delete'
|
||||||
|
|
||||||
|
assert_text 'Domain registrant change has been rejected successfully.'
|
||||||
|
|
||||||
|
assert_enqueued_jobs 1, only: DomainDeleteConfirmJob
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_saves_whodunnit_info_after_verifivation
|
||||||
|
visit registrant_domain_delete_confirm_url(@domain.id, token: @domain.registrant_verification_token)
|
||||||
|
token = @domain.registrant_verification_token
|
||||||
|
click_on 'Confirm domain delete'
|
||||||
|
assert_text 'Domain registrant change has successfully received.'
|
||||||
|
|
||||||
|
refute RegistrantVerification.find_by(verification_token:token).updator_str.empty?
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,6 +1,6 @@
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
class VerifyEmailTaskTest < ActiveSupport::TestCase
|
class VerifyEmailTaskTest < ActiveJob::TestCase
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@contact = contacts(:john)
|
@contact = contacts(:john)
|
||||||
|
@ -54,10 +54,14 @@ class VerifyEmailTaskTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def run_task
|
def run_task
|
||||||
Rake::Task['verify_email:all_domains'].execute
|
perform_enqueued_jobs do
|
||||||
|
Rake::Task['verify_email:all_domains'].execute
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def run_single_domain_task(domain)
|
def run_single_domain_task(domain)
|
||||||
Rake::Task["verify_email:domain"].invoke(domain)
|
perform_enqueued_jobs do
|
||||||
|
Rake::Task["verify_email:domain"].invoke(domain)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -27,6 +27,8 @@ require 'rake'
|
||||||
Rake::Task.clear
|
Rake::Task.clear
|
||||||
Rails.application.load_tasks
|
Rails.application.load_tasks
|
||||||
|
|
||||||
|
ActiveJob::Base.queue_adapter = :test
|
||||||
|
|
||||||
class CompanyRegisterClientStub
|
class CompanyRegisterClientStub
|
||||||
Company = Struct.new(:registration_number, :company_name)
|
Company = Struct.new(:registration_number, :company_name)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue