mirror of
https://github.com/internetee/registry.git
synced 2025-06-08 13:44:47 +02:00
added tests
This commit is contained in:
parent
e74cf2bc7f
commit
d6824bf46c
5 changed files with 94 additions and 5 deletions
|
@ -45,7 +45,8 @@ module Repp
|
||||||
end
|
end
|
||||||
|
|
||||||
def notify_admins
|
def notify_admins
|
||||||
admin_users_emails = User.all.reject { |u| u.roles.nil? }.select { |u| u.roles.include? "admin" }.pluck(:email)
|
admin_users_emails = User.all.reject { |u| u.roles.nil? }.
|
||||||
|
select { |u| u.roles.include? 'admin' }.pluck(:email)
|
||||||
|
|
||||||
return if admin_users_emails.empty?
|
return if admin_users_emails.empty?
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,20 @@
|
||||||
class NotifyAccreditationAdminsAndRegistrarsJob < ApplicationJob
|
class NotifyAccreditationAdminsAndRegistrarsJob < ApplicationJob
|
||||||
MONTH_BEFORE = 5.minute.freeze
|
MONTH_BEFORE = 5.minutes.freeze
|
||||||
|
|
||||||
def perform
|
def perform
|
||||||
|
notify_month_before
|
||||||
|
notify_date_is_expired
|
||||||
|
end
|
||||||
|
|
||||||
|
def notify_month_before
|
||||||
prepare_data_month_before.each do |user|
|
prepare_data_month_before.each do |user|
|
||||||
next if user.registrar.email.nil?
|
next if user.registrar.email.nil?
|
||||||
|
|
||||||
AccreditationCenterMailer.test_results_will_expired_in_one_month(user.registrar.email).deliver_now
|
AccreditationCenterMailer.test_results_will_expired_in_one_month(user.registrar.email).deliver_now
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def notify_date_is_expired
|
||||||
prepare_data_expired_data.each do |user|
|
prepare_data_expired_data.each do |user|
|
||||||
next if user.registrar.email.nil?
|
next if user.registrar.email.nil?
|
||||||
|
|
||||||
|
@ -19,11 +26,11 @@ class NotifyAccreditationAdminsAndRegistrarsJob < ApplicationJob
|
||||||
|
|
||||||
def prepare_data_month_before
|
def prepare_data_month_before
|
||||||
ApiUser.where("accreditation_expire_date > ? AND accreditation_expire_date < ?",
|
ApiUser.where("accreditation_expire_date > ? AND accreditation_expire_date < ?",
|
||||||
Time.now.beginning_of_day + MONTH_BEFORE,
|
Time.zone.now.beginning_of_day + MONTH_BEFORE,
|
||||||
Time.now.end_of_day + MONTH_BEFORE).includes(:registrar)
|
Time.zone.now.end_of_day + MONTH_BEFORE).includes(:registrar)
|
||||||
end
|
end
|
||||||
|
|
||||||
def prepare_data_expired_data
|
def prepare_data_expired_data
|
||||||
ApiUser.where("accreditation_expire_date < ?", Time.now.beginning_of_day).includes(:registrar)
|
ApiUser.where("accreditation_expire_date < ?", Time.zone.now.beginning_of_day).includes(:registrar)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,6 +18,7 @@ class ReppV1AccreditationResultsTest < ActionDispatch::IntegrationTest
|
||||||
json = JSON.parse(response.body, symbolize_names: true)
|
json = JSON.parse(response.body, symbolize_names: true)
|
||||||
|
|
||||||
assert_response :ok
|
assert_response :ok
|
||||||
|
assert_emails 2
|
||||||
assert_equal json[:data][:user][:username], @user.username
|
assert_equal json[:data][:user][:username], @user.username
|
||||||
assert_equal json[:data][:result], "true"
|
assert_equal json[:data][:result], "true"
|
||||||
assert_equal json[:data][:message], "Accreditation info successfully added"
|
assert_equal json[:data][:message], "Accreditation info successfully added"
|
||||||
|
@ -31,6 +32,7 @@ class ReppV1AccreditationResultsTest < ActionDispatch::IntegrationTest
|
||||||
|
|
||||||
assert_response :unauthorized
|
assert_response :unauthorized
|
||||||
|
|
||||||
|
assert_emails 0
|
||||||
assert_equal json[:code], 2202
|
assert_equal json[:code], 2202
|
||||||
assert_equal json[:message], 'Invalid authorization information'
|
assert_equal json[:message], 'Invalid authorization information'
|
||||||
end
|
end
|
||||||
|
@ -43,6 +45,7 @@ class ReppV1AccreditationResultsTest < ActionDispatch::IntegrationTest
|
||||||
|
|
||||||
assert_response :ok
|
assert_response :ok
|
||||||
|
|
||||||
|
assert_emails 0
|
||||||
assert_equal json[:code], 2303
|
assert_equal json[:code], 2303
|
||||||
assert_equal json[:message], "Object 'chungachanga' does not exist"
|
assert_equal json[:message], "Object 'chungachanga' does not exist"
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class NotifyAccreditationAdminsAndRegistrarsJobTest < ActiveJob::TestCase
|
||||||
|
include ActionMailer::TestHelper
|
||||||
|
|
||||||
|
setup do
|
||||||
|
ActionMailer::Base.deliveries.clear
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_inform_registrars_if_accredation_date_is_expires
|
||||||
|
api_user = users(:api_bestnames)
|
||||||
|
api_user.accreditation_date = Time.now - 2.year - 1.day
|
||||||
|
api_user.accreditation_expire_date = Time.now - 1.day
|
||||||
|
api_user.save
|
||||||
|
api_user.reload
|
||||||
|
|
||||||
|
perform_enqueued_jobs do
|
||||||
|
NotifyAccreditationAdminsAndRegistrarsJob.perform_now
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_emails 1
|
||||||
|
end
|
||||||
|
|
||||||
|
# def test_inform_registrars_if_deadline_date_in_one_month
|
||||||
|
# api_user = users(:api_bestnames)
|
||||||
|
# api_user.accreditation_date = Time.now - 2.year - 1.day
|
||||||
|
# api_user.accreditation_expire_date = Time.now + 1.month - 1.day
|
||||||
|
# api_user.save
|
||||||
|
# api_user.reload
|
||||||
|
#
|
||||||
|
# perform_enqueued_jobs do
|
||||||
|
# NotifyAccreditationAdminsAndRegistrarsJob.perform_now
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
# assert_emails 1
|
||||||
|
# end
|
||||||
|
|
||||||
|
end
|
40
test/mailers/accrediation_center_mailer_test.rb
Normal file
40
test/mailers/accrediation_center_mailer_test.rb
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class AccreditationCenterMailerTest < ActionMailer::TestCase
|
||||||
|
setup do
|
||||||
|
@admin = users(:admin)
|
||||||
|
@registrar = registrars(:bestnames)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_send_mails_for_admins
|
||||||
|
email = AccreditationCenterMailer.test_was_successfully_passed_admin(@admin.email)
|
||||||
|
.deliver_now
|
||||||
|
|
||||||
|
assert_emails 1
|
||||||
|
assert_equal [@admin.email], email.to
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_send_mails_for_registrar
|
||||||
|
email = AccreditationCenterMailer.test_was_successfully_passed_registrar(@registrar.email)
|
||||||
|
.deliver_now
|
||||||
|
|
||||||
|
assert_emails 1
|
||||||
|
assert_equal [@registrar.email], email.to
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_send_mails_month_before
|
||||||
|
email = AccreditationCenterMailer.test_results_will_expired_in_one_month(@registrar.email)
|
||||||
|
.deliver_now
|
||||||
|
|
||||||
|
assert_emails 1
|
||||||
|
assert_equal [@registrar.email], email.to
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_send_mails_if_accredation_date_is_expired
|
||||||
|
email = AccreditationCenterMailer.test_results_are_expired(@registrar.email)
|
||||||
|
.deliver_now
|
||||||
|
|
||||||
|
assert_emails 1
|
||||||
|
assert_equal [@registrar.email], email.to
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Add a link
Reference in a new issue