Skip to content

Commit

Permalink
Skip if new_work_views or new_file_downloads is 0
Browse files Browse the repository at this point in the history
  • Loading branch information
ShanaLMoore committed Sep 3, 2024
1 parent fd8bdb7 commit 608faf9
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 30 deletions.
3 changes: 3 additions & 0 deletions app/jobs/depositor_email_notification_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ def perform
statistics = user.statistics_for
next if statistics.nil?

# Skip if new_work_views or new_file_downloads is 0
next if statistics[:new_work_views].zero? || statistics[:new_file_downloads].zero?

This comment has been minimized.

Copy link
@laritakr

laritakr Sep 4, 2024

Collaborator

Shouldn't this be and rather than or? I think we'd want to send as long as anything is non-zero.


HykuMailer.depositor_email(user, statistics, current_account).deliver_now
end
DepositorEmailNotificationJob.set(wait_until: (Time.zone.now + 1.month).beginning_of_month).perform_later
Expand Down
60 changes: 30 additions & 30 deletions app/views/hyku_mailer/depositor_email.html.erb
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
<!DOCTYPE html>
<html>
<head>
<style>
body { font-family: Arial, sans-serif; line-height: 1.6; }
.email-container { max-width: 600px; margin: auto; padding: 20px; border: 1px solid #ccc; }
.footer { font-size: 12px; color: #666; margin-top: 20px; }
.highlight { color: #0056b3; }
.button {
display: inline-block;
padding: 10px 20px;
margin: 10px 0;
background-color: #0056b3;
color: white;
text-decoration: none;
border-radius: 5px;
}
</style>
</head>
<body>
<div class="email-container">
<p>Dear Author,</p>
<p>You had <%= pluralize(@statistics[:new_file_downloads], 'download') %> in <%= Date.today.prev_month.strftime("%B %Y") %> across your <%= pluralize(@statistics[:new_work_views], 'work') %> in <%= @application_name %>. Your current readership:</p>
<ul>
<li><%= pluralize(@statistics[:total_file_downloads], 'Total File Download') %></li>
<li><%= pluralize(@statistics[:total_work_views], 'Total Work View') %></li>
</ul>
<a href="<%= @url %>" class="button">VISIT MY DASHBOARD</a>
<div class="footer">
<p>These monthly reports are provided to you on behalf of <%= @application_name %>. For questions, comments, or to add more content and increase your readership and visibility as an author, please contact your repository administrator.</p>
<head>
<style>
body { font-family: Arial, sans-serif; line-height: 1.6; }
.email-container { max-width: 600px; margin: auto; padding: 20px; border: 1px solid #ccc; }
.footer { font-size: 12px; color: #666; margin-top: 20px; }
.highlight { color: #0056b3; }
.button {
display: inline-block;
padding: 10px 20px;
margin: 10px 0;
background-color: #0056b3;
color: white;
text-decoration: none;
border-radius: 5px;
}
</style>
</head>
<body>
<div class="email-container">
<p>Dear Author,</p>
<p>You had <%= pluralize(@statistics[:new_file_downloads], 'new download') %> in <%= Date.today.prev_month.strftime("%B %Y") %> across your <%= pluralize(@statistics[:new_work_views], 'new work') %> in <%= @application_name %>. Your current readership:</p>
<ul>
<li><%= pluralize(@statistics[:total_file_downloads], 'Total File Download') %></li>
<li><%= pluralize(@statistics[:total_work_views], 'Total Work View') %></li>
</ul>
<a href="<%= @url %>" class="button">VISIT MY DASHBOARD</a>
<div class="footer">
<p>These monthly reports are provided to you on behalf of <%= @application_name %>. For questions, comments, or to add more content and increase your readership and visibility as an author, please contact your repository administrator.</p>
</div>
</div>
</div>
</body>
</body>
</html>
15 changes: 15 additions & 0 deletions spec/jobs/depositor_email_notification_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,21 @@
end
end

context 'when the user has zero new counts in statistics' do
let(:statistics) { { new_file_downloads: 0, new_work_views: 0, total_file_downloads: 6, total_file_views: 7, total_work_views: 16 } }

before do
allow(User).to receive(:all).and_return([user])
allow(user).to receive(:statistics_for).and_return(statistics)
end

it 'does not send emails to users' do
switch!(account)
described_class.perform_now
expect(ActionMailer::Base.deliveries.count).to eq(0)
end
end

context 'when the user has no new statistics' do
let(:statistics) { nil }

Expand Down

0 comments on commit 608faf9

Please sign in to comment.