-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2212 from internetee/added_notifications_for_acc_…
…center added mail contronller and job for notificate registrars and admins about accreditation expire date
- Loading branch information
Showing
10 changed files
with
167 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
app/jobs/notify_accreditation_admins_and_registrars_job.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
class NotifyAccreditationAdminsAndRegistrarsJob < ApplicationJob | ||
MONTH_BEFORE = 5.minutes.freeze | ||
|
||
def perform | ||
notify_month_before | ||
notify_date_is_expired | ||
end | ||
|
||
def notify_month_before | ||
prepare_data_month_before.each do |user| | ||
next if user.registrar.email.nil? | ||
|
||
AccreditationCenterMailer.test_results_will_expired_in_one_month(user.registrar.email).deliver_now | ||
end | ||
end | ||
|
||
def notify_date_is_expired | ||
prepare_data_expired_data.each do |user| | ||
next if user.registrar.email.nil? | ||
|
||
AccreditationCenterMailer.test_results_are_expired(user.registrar.email).deliver_now | ||
end | ||
end | ||
|
||
private | ||
|
||
def prepare_data_month_before | ||
ApiUser.where('accreditation_expire_date > ? AND accreditation_expire_date < ?', | ||
Time.zone.now.beginning_of_day + MONTH_BEFORE, | ||
Time.zone.now.end_of_day + MONTH_BEFORE).includes(:registrar) | ||
end | ||
|
||
def prepare_data_expired_data | ||
ApiUser.where('accreditation_expire_date < ?', Time.zone.now.beginning_of_day).includes(:registrar) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class AccreditationCenterMailer < ApplicationMailer | ||
def test_was_successfully_passed_admin(email) | ||
subject = 'Test passed admin' | ||
mail(to: email, subject: subject) | ||
end | ||
|
||
def test_was_successfully_passed_registrar(email) | ||
subject = 'Test passed registrar' | ||
mail(to: email, subject: subject) | ||
end | ||
|
||
def test_results_will_expired_in_one_month(email) | ||
subject = 'Test will expired in one month' | ||
mail(to: email, subject: subject) | ||
end | ||
|
||
def test_results_are_expired(email) | ||
subject = 'Test are expired' | ||
mail(to: email, subject: subject) | ||
end | ||
end |
1 change: 1 addition & 0 deletions
1
app/views/mailers/accreditation_center_mailer/test_results_are_expired.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<h1>Test result are expired</h1> |
1 change: 1 addition & 0 deletions
1
...views/mailers/accreditation_center_mailer/test_results_will_expired_in_one_month.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<h1>Test result will expired in one month</h1> |
1 change: 1 addition & 0 deletions
1
app/views/mailers/accreditation_center_mailer/test_was_successfully_passed_admin.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<h1>Test was successfully passed (ADMIN)</h1> |
1 change: 1 addition & 0 deletions
1
...views/mailers/accreditation_center_mailer/test_was_successfully_passed_registrar.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<h1>Test was successfully passed (REGISTRAR)</h1> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
test/jobs/notify_accreditation_admins_and_registrars_job_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |