From a332d87df1c1de04ab3117627804b01f75e35955 Mon Sep 17 00:00:00 2001 From: Shana Moore Date: Wed, 29 May 2024 14:14:31 -0700 Subject: [PATCH 01/10] :construction: WIP - Author notifications boilerplate is WIP. template with sample email has been created at this point but needs to be dynamic. TODO: - understand UserStats and replace placeholder data - make email dynamic, including the date, tenant name, link to dashboard, etc - Do we want to make an option for the user to not receive emails? If so - we need UI work and possibly migrations. - specs --- app/mailers/hyku_mailer.rb | 14 ++++++ app/services/create_account.rb | 1 + .../hyku_mailer/depositor_email.html.erb | 33 +++++++++++++ depositor_email_notification_job.rb | 47 +++++++++++++++++++ spec/mailers/previews/hyku_mailer_preview.rb | 21 +++++++++ 5 files changed, 116 insertions(+) create mode 100644 app/views/hyku_mailer/depositor_email.html.erb create mode 100644 depositor_email_notification_job.rb diff --git a/app/mailers/hyku_mailer.rb b/app/mailers/hyku_mailer.rb index cb247e695..4d421fe7b 100644 --- a/app/mailers/hyku_mailer.rb +++ b/app/mailers/hyku_mailer.rb @@ -20,6 +20,20 @@ def summary_email(user, messages, account) template_name: 'summary_email') end + def depositor_email(user, statistics, account) + @user = user + @statistics = statistics + @account = account + @url = notifications_url_for(@account) + @application_name = account.sites.application_name + + mail(to: @user.email, + subject: "Monthly Downloads Summary for #{@application_name}", + from: @account.contact_email, + template_path: 'hyku_mailer', + template_name: 'depositor_email') + end + private def host_for_tenant diff --git a/app/services/create_account.rb b/app/services/create_account.rb index cce893148..498fe8575 100644 --- a/app/services/create_account.rb +++ b/app/services/create_account.rb @@ -87,6 +87,7 @@ def schedule_recurring_jobs EmbargoAutoExpiryJob.perform_later(account) LeaseAutoExpiryJob.perform_later(account) BatchEmailNotificationJob.perform_later(account) + DepositorEmailNotificationJob.perform_later(account) end private diff --git a/app/views/hyku_mailer/depositor_email.html.erb b/app/views/hyku_mailer/depositor_email.html.erb new file mode 100644 index 000000000..5250a4f59 --- /dev/null +++ b/app/views/hyku_mailer/depositor_email.html.erb @@ -0,0 +1,33 @@ + + + + + + +
+

Dear Author,

+

You had <%= @statistics[:new_downloads] %> new download in December 2023 across your <%= @statistics[:papers_count] %> papers in MUShare. Your current readership:

+ + VISIT MY DASHBOARD + +
+ + diff --git a/depositor_email_notification_job.rb b/depositor_email_notification_job.rb new file mode 100644 index 000000000..9b157f6d2 --- /dev/null +++ b/depositor_email_notification_job.rb @@ -0,0 +1,47 @@ +# frozen_literal: true + +class DepositorEmailNotificationJob < ApplicationJob + non_tenant_job + + after_perform do |job| + reenqueue(job.arguments.first) + end + + def perform(account) + Apartment::Tenant.switch(account.tenant) do + stats_period = (Date.today - 1.month).beginning_of_month..(Date.today - 1.month).end_of_month + users = User.all + + users.each do |user| + statistics = gather_statistics_for(user, stats_period) + next if statistics.nil? + + HykuMailer.depositor_email(user, statistics, account).deliver_now + end + end + end + + private + + def reenqueue(account) + DepositorEmailNotificationJob.set(wait_until: Date.next_month.beginning_of_month).perform_later(account) + end + + def gather_statistics_for(user, stats_period) + # Dummy statistics - replace with actual logic to calculate view and download counts. + # users.stats could be useful: https://github.com/samvera/hyrax/blob/4d2c654a8b9f144b35a6e013b31f80cb4cf47aeb/app/models/concerns/hyrax/user_usage_stats.rb#L3 + # there's also this: https://github.com/samvera/hyrax/blob/main/app/presenters/hyrax/file_usage.rb + # Fetching statistics for the previous month + last_month_stats = user.stats.where(date: stats_period) + + return nil if last_month_stats.empty? + + { + new_file_downloads: last_month_stats.sum(:file_downloads), + new_work_views: last_month_stats.sum(:work_views), + total_file_views: user.total_file_views, + total_file_downloads: user.total_file_downloads, + total_work_views: user.total_work_views + } + end +end diff --git a/spec/mailers/previews/hyku_mailer_preview.rb b/spec/mailers/previews/hyku_mailer_preview.rb index dd14edf55..4266c3c83 100644 --- a/spec/mailers/previews/hyku_mailer_preview.rb +++ b/spec/mailers/previews/hyku_mailer_preview.rb @@ -21,4 +21,25 @@ def summary_email HykuMailer.new.summary_email(user, messages, account) end + + def depositor_email + # Creating mock statistics + statistics = { + new_downloads: 1, + total_downloads: 26, + papers_count: 2 + } + + # Mock user + user = Struct.new(:email, :name).new('depositor@example.com', 'Depositor Name') + + # Mock site and account setup + site = Struct.new(:application_name) + sites = site.new('MUShare') + + account = Struct.new(:cname, :contact_email, :sites).new('mushare.local', 'admin@mushare.com', sites) + + # Calling the depositor_email method of the HykuMailer with mock data + HykuMailer.new.depositor_email(user, statistics, account) + end end From 0bffe8e590c103748761a1294d4b93a9b44ee40e Mon Sep 17 00:00:00 2001 From: Shana Moore Date: Wed, 29 May 2024 15:45:26 -0700 Subject: [PATCH 02/10] =?UTF-8?q?=F0=9F=A7=B9=20make=20depositor=20email?= =?UTF-8?q?=20dynamic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit TODO: make stats dynamic --- app/mailers/hyku_mailer.rb | 6 +++++- app/views/hyku_mailer/depositor_email.html.erb | 9 +++++---- spec/mailers/previews/hyku_mailer_preview.rb | 12 +++++++----- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/app/mailers/hyku_mailer.rb b/app/mailers/hyku_mailer.rb index 4d421fe7b..1d45b439f 100644 --- a/app/mailers/hyku_mailer.rb +++ b/app/mailers/hyku_mailer.rb @@ -24,7 +24,7 @@ def depositor_email(user, statistics, account) @user = user @statistics = statistics @account = account - @url = notifications_url_for(@account) + @url = dashboard_url_for(@account) @application_name = account.sites.application_name mail(to: @user.email, @@ -43,4 +43,8 @@ def host_for_tenant def notifications_url_for(account) "https://#{account.cname}/notifications" end + + def dashboard_url_for(account) + "https://#{account.cname}/dashboard" + end end diff --git a/app/views/hyku_mailer/depositor_email.html.erb b/app/views/hyku_mailer/depositor_email.html.erb index 5250a4f59..51954f719 100644 --- a/app/views/hyku_mailer/depositor_email.html.erb +++ b/app/views/hyku_mailer/depositor_email.html.erb @@ -20,13 +20,14 @@ diff --git a/spec/mailers/previews/hyku_mailer_preview.rb b/spec/mailers/previews/hyku_mailer_preview.rb index 4266c3c83..2723451f9 100644 --- a/spec/mailers/previews/hyku_mailer_preview.rb +++ b/spec/mailers/previews/hyku_mailer_preview.rb @@ -25,10 +25,12 @@ def summary_email def depositor_email # Creating mock statistics statistics = { - new_downloads: 1, - total_downloads: 26, - papers_count: 2 - } + new_file_downloads: 1, + new_work_views: 6, + total_file_views: 20, + total_file_downloads: 20, + total_work_views: 100 + } # Mock user user = Struct.new(:email, :name).new('depositor@example.com', 'Depositor Name') @@ -37,7 +39,7 @@ def depositor_email site = Struct.new(:application_name) sites = site.new('MUShare') - account = Struct.new(:cname, :contact_email, :sites).new('mushare.local', 'admin@mushare.com', sites) + account = Struct.new(:cname, :contact_email, :sites).new('acme.pals.test', 'admin@mushare.com', sites) # Calling the depositor_email method of the HykuMailer with mock data HykuMailer.new.depositor_email(user, statistics, account) From 693d467a27552cf960b264c24f4eb1a8e3d65ebc Mon Sep 17 00:00:00 2001 From: Shana Moore Date: Thu, 30 May 2024 08:34:48 -0700 Subject: [PATCH 03/10] Add TODO comments --- depositor_email_notification_job.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/depositor_email_notification_job.rb b/depositor_email_notification_job.rb index 9b157f6d2..d81db14e1 100644 --- a/depositor_email_notification_job.rb +++ b/depositor_email_notification_job.rb @@ -1,5 +1,11 @@ # frozen_literal: true +# TODO +# How do we collect all of the counts for the past month only? +# Do we expect user.stats to return multiple UserStat objects. How does this work? +# How often Hyrax::UserStatImporter job run? - Is Rob setting up a job to run +# the rake task. Task needs to work for all tenants. +# Specs class DepositorEmailNotificationJob < ApplicationJob non_tenant_job From 5666485a712a83c172fd648e7ec5094541efc1bd Mon Sep 17 00:00:00 2001 From: LaRita Robinson Date: Fri, 31 May 2024 12:31:13 -0400 Subject: [PATCH 04/10] Move depositor_email_notification_job Job was in the wrong directory so create_account fails. --- .../jobs/depositor_email_notification_job.rb | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename depositor_email_notification_job.rb => app/jobs/depositor_email_notification_job.rb (100%) diff --git a/depositor_email_notification_job.rb b/app/jobs/depositor_email_notification_job.rb similarity index 100% rename from depositor_email_notification_job.rb rename to app/jobs/depositor_email_notification_job.rb From 50659bc67a3137a88d285c6ad97b713fac75f614 Mon Sep 17 00:00:00 2001 From: LaRita Robinson Date: Fri, 31 May 2024 13:27:12 -0400 Subject: [PATCH 05/10] Move statistics gathering to User class --- app/jobs/depositor_email_notification_job.rb | 29 ++------------------ app/models/user.rb | 16 +++++++++++ 2 files changed, 18 insertions(+), 27 deletions(-) diff --git a/app/jobs/depositor_email_notification_job.rb b/app/jobs/depositor_email_notification_job.rb index d81db14e1..fbdf58e55 100644 --- a/app/jobs/depositor_email_notification_job.rb +++ b/app/jobs/depositor_email_notification_job.rb @@ -1,11 +1,5 @@ # frozen_literal: true -# TODO -# How do we collect all of the counts for the past month only? -# Do we expect user.stats to return multiple UserStat objects. How does this work? -# How often Hyrax::UserStatImporter job run? - Is Rob setting up a job to run -# the rake task. Task needs to work for all tenants. -# Specs class DepositorEmailNotificationJob < ApplicationJob non_tenant_job @@ -15,11 +9,10 @@ class DepositorEmailNotificationJob < ApplicationJob def perform(account) Apartment::Tenant.switch(account.tenant) do - stats_period = (Date.today - 1.month).beginning_of_month..(Date.today - 1.month).end_of_month users = User.all users.each do |user| - statistics = gather_statistics_for(user, stats_period) + statistics = user.statistics_for next if statistics.nil? HykuMailer.depositor_email(user, statistics, account).deliver_now @@ -27,27 +20,9 @@ def perform(account) end end - private + # private def reenqueue(account) DepositorEmailNotificationJob.set(wait_until: Date.next_month.beginning_of_month).perform_later(account) end - - def gather_statistics_for(user, stats_period) - # Dummy statistics - replace with actual logic to calculate view and download counts. - # users.stats could be useful: https://github.com/samvera/hyrax/blob/4d2c654a8b9f144b35a6e013b31f80cb4cf47aeb/app/models/concerns/hyrax/user_usage_stats.rb#L3 - # there's also this: https://github.com/samvera/hyrax/blob/main/app/presenters/hyrax/file_usage.rb - # Fetching statistics for the previous month - last_month_stats = user.stats.where(date: stats_period) - - return nil if last_month_stats.empty? - - { - new_file_downloads: last_month_stats.sum(:file_downloads), - new_work_views: last_month_stats.sum(:work_views), - total_file_views: user.total_file_views, - total_file_downloads: user.total_file_downloads, - total_work_views: user.total_work_views - } - end end diff --git a/app/models/user.rb b/app/models/user.rb index 06ec4c8b7..88fd6438a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -172,4 +172,20 @@ def mark_all_undelivered_messages_as_delivered! receipt.update(is_delivered: true) end end + + # Returns hash summary of user statistics for a date range... uses the prior month by default + def statistics_for(start_date: (Date.today - 1.month).beginning_of_month, end_date: (Date.today - 1.month).end_of_month) + stats_period = start_date..end_date + last_month_stats = stats.where(date: stats_period) + + return nil if last_month_stats.empty? + + { + new_file_downloads: last_month_stats.sum(:file_downloads), + new_work_views: last_month_stats.sum(:work_views), + total_file_views: total_file_views, + total_file_downloads: total_file_downloads, + total_work_views: total_work_views + } + end end From fff40c2daef426d727b0691477b1c891742adbd5 Mon Sep 17 00:00:00 2001 From: LaRita Robinson Date: Fri, 31 May 2024 15:42:05 -0400 Subject: [PATCH 06/10] Specs --- app/jobs/depositor_email_notification_job.rb | 2 +- app/models/user.rb | 2 +- .../depositor_email_notification_job_spec.rb | 44 +++++++++++++++++++ spec/models/user_spec.rb | 41 +++++++++++++++++ 4 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 spec/jobs/depositor_email_notification_job_spec.rb diff --git a/app/jobs/depositor_email_notification_job.rb b/app/jobs/depositor_email_notification_job.rb index fbdf58e55..962306b0e 100644 --- a/app/jobs/depositor_email_notification_job.rb +++ b/app/jobs/depositor_email_notification_job.rb @@ -23,6 +23,6 @@ def perform(account) # private def reenqueue(account) - DepositorEmailNotificationJob.set(wait_until: Date.next_month.beginning_of_month).perform_later(account) + DepositorEmailNotificationJob.set(wait_until: ((Time.now+1.month).beginning_of_month)).perform_later(account) end end diff --git a/app/models/user.rb b/app/models/user.rb index 88fd6438a..411c998e0 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -174,7 +174,7 @@ def mark_all_undelivered_messages_as_delivered! end # Returns hash summary of user statistics for a date range... uses the prior month by default - def statistics_for(start_date: (Date.today - 1.month).beginning_of_month, end_date: (Date.today - 1.month).end_of_month) + def statistics_for(start_date: (Time.now - 1.month).beginning_of_month, end_date: (Time.now - 1.month).end_of_month) stats_period = start_date..end_date last_month_stats = stats.where(date: stats_period) diff --git a/spec/jobs/depositor_email_notification_job_spec.rb b/spec/jobs/depositor_email_notification_job_spec.rb new file mode 100644 index 000000000..8821427d2 --- /dev/null +++ b/spec/jobs/depositor_email_notification_job_spec.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +RSpec.describe DepositorEmailNotificationJob do + let(:account) { FactoryBot.create(:account) } + let(:receipt) { FactoryBot.create(:mailboxer_receipt, receiver: user) } + let!(:message) { receipt.notification } + let!(:user) { FactoryBot.create(:user) } + + before do + allow(Apartment::Tenant).to receive(:switch).and_yield + ActionMailer::Base.deliveries.clear + end + + after do + clear_enqueued_jobs + end + + describe '#perform' do + it 're-enqueues the job' do + expect { DepositorEmailNotificationJob.perform_now(account) }.to have_enqueued_job(DepositorEmailNotificationJob).with(account) + end + + context 'when the user has new statistics' do + let(:statistics) { {:new_file_downloads=>2, :new_work_views=>3, :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 'sends email to users' do + expect { described_class.perform_now(account) }.to change { ActionMailer::Base.deliveries.count }.by(1) + end + end + + context 'when the user has no new statistics' do + let(:statistics) { nil } + + it 'sends does not send email to user' do + expect { DepositorEmailNotificationJob.perform_now(account) }.to_not change { ActionMailer::Base.deliveries.count } + end + end + end +end \ No newline at end of file diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 10ae8629c..73a44fb3a 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -8,6 +8,47 @@ is_expected.to validate_presence_of(:password) end + context '#stistics_for' do + let(:account) { FactoryBot.create(:account) } + + before do + allow(Apartment::Tenant).to receive(:switch).and_yield + end + + describe 'no statistics' do + it 'returns nil' do + expect(subject.statistics_for).to be nil + end + end + + describe 'with user statistics' do + let!(:stat_1_prior_month) { UserStat.create!(user_id: subject.id, date: 1.month.ago, file_views: 3, file_downloads: 2, work_views: 5) } + let!(:stat_2_prior_month) { UserStat.create!(user_id: subject.id, date: 1.month.ago, file_views: 2, file_downloads: 1, work_views: 7) } + let!(:stat_2_months_ago) { UserStat.create!(user_id: subject.id, date: 2.months.ago, file_views: 1, file_downloads: 1, work_views: 1) } + let!(:stat_yesterday) { UserStat.create!(user_id: subject.id, date: 1.day.ago, file_views: 1, file_downloads: 2, work_views: 3) } + let!(:someone_elses_user_id) { subject.id + 1 } + let!(:not_my_stat) { UserStat.create!(user_id: someone_elses_user_id, date: 1.month.ago, file_views: 10, file_downloads: 11) } + let(:user_stats) { {:new_file_downloads=>3, :new_work_views=>12, :total_file_downloads=>6, :total_file_views=>7, :total_work_views=>16} } + let(:yesterday_stats) { {:new_file_downloads=>2, :new_work_views=>3, :total_file_downloads=>6, :total_file_views=>7, :total_work_views=>16} } + + it 'returns a summary hash of prior months stats' do + expect(subject.statistics_for).to eq(user_stats) + end + + it 'summarizes stats for specified date range' do + expect(subject.statistics_for(start_date: Time.now-2.days, end_date: Time.now)).to eq(yesterday_stats) + end + + it 'returns nil if no statistics in specified date range' do + expect(subject.statistics_for(start_date: Time.now-4.months, end_date: Time.now-5.months)).to be nil + end + + it 'returns nil if start and end dates the same' do + expect(subject.statistics_for(start_date: Time.now-5.months, end_date: Time.now-5.months)).to be nil + end + end + end + context 'the first created user in global tenant' do before do allow(Account).to receive(:global_tenant?).and_return true From 59131c89318294cad7dc3346c7f2976db91939f8 Mon Sep 17 00:00:00 2001 From: LaRita Robinson Date: Fri, 31 May 2024 15:52:49 -0400 Subject: [PATCH 07/10] Rubocop appeasement --- app/jobs/depositor_email_notification_job.rb | 4 ++-- app/models/user.rb | 10 ++++++---- spec/jobs/depositor_email_notification_job_spec.rb | 4 ++-- spec/mailers/previews/hyku_mailer_preview.rb | 14 +++++++------- spec/models/user_spec.rb | 10 +++++----- 5 files changed, 22 insertions(+), 20 deletions(-) diff --git a/app/jobs/depositor_email_notification_job.rb b/app/jobs/depositor_email_notification_job.rb index 962306b0e..c55ff2e19 100644 --- a/app/jobs/depositor_email_notification_job.rb +++ b/app/jobs/depositor_email_notification_job.rb @@ -1,4 +1,4 @@ -# frozen_literal: true +# frozen_string_literal: true class DepositorEmailNotificationJob < ApplicationJob non_tenant_job @@ -23,6 +23,6 @@ def perform(account) # private def reenqueue(account) - DepositorEmailNotificationJob.set(wait_until: ((Time.now+1.month).beginning_of_month)).perform_later(account) + DepositorEmailNotificationJob.set(wait_until: (Time.zone.now + 1.month).beginning_of_month).perform_later(account) end end diff --git a/app/models/user.rb b/app/models/user.rb index 411c998e0..a4a623c98 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true +# rubocop:disable Metrics/ClassLength class User < ApplicationRecord # Includes lib/rolify from the rolify gem rolify @@ -174,7 +175,7 @@ def mark_all_undelivered_messages_as_delivered! end # Returns hash summary of user statistics for a date range... uses the prior month by default - def statistics_for(start_date: (Time.now - 1.month).beginning_of_month, end_date: (Time.now - 1.month).end_of_month) + def statistics_for(start_date: (Time.zone.now - 1.month).beginning_of_month, end_date: (Time.zone.now - 1.month).end_of_month) stats_period = start_date..end_date last_month_stats = stats.where(date: stats_period) @@ -183,9 +184,10 @@ def statistics_for(start_date: (Time.now - 1.month).beginning_of_month, end_date { new_file_downloads: last_month_stats.sum(:file_downloads), new_work_views: last_month_stats.sum(:work_views), - total_file_views: total_file_views, - total_file_downloads: total_file_downloads, - total_work_views: total_work_views + total_file_views:, + total_file_downloads:, + total_work_views: } end end +# rubocop:enable Metrics/ClassLength diff --git a/spec/jobs/depositor_email_notification_job_spec.rb b/spec/jobs/depositor_email_notification_job_spec.rb index 8821427d2..9aee28b54 100644 --- a/spec/jobs/depositor_email_notification_job_spec.rb +++ b/spec/jobs/depositor_email_notification_job_spec.rb @@ -21,7 +21,7 @@ end context 'when the user has new statistics' do - let(:statistics) { {:new_file_downloads=>2, :new_work_views=>3, :total_file_downloads=>6, :total_file_views=>7, :total_work_views=>16} } + let(:statistics) { { new_file_downloads: 2, new_work_views: 3, total_file_downloads: 6, total_file_views: 7, total_work_views: 16 } } before do allow(User).to receive(:all).and_return([user]) @@ -41,4 +41,4 @@ end end end -end \ No newline at end of file +end diff --git a/spec/mailers/previews/hyku_mailer_preview.rb b/spec/mailers/previews/hyku_mailer_preview.rb index 2723451f9..a1455fb0e 100644 --- a/spec/mailers/previews/hyku_mailer_preview.rb +++ b/spec/mailers/previews/hyku_mailer_preview.rb @@ -25,12 +25,12 @@ def summary_email def depositor_email # Creating mock statistics statistics = { - new_file_downloads: 1, - new_work_views: 6, - total_file_views: 20, - total_file_downloads: 20, - total_work_views: 100 - } + new_file_downloads: 1, + new_work_views: 6, + total_file_views: 20, + total_file_downloads: 20, + total_work_views: 100 + } # Mock user user = Struct.new(:email, :name).new('depositor@example.com', 'Depositor Name') @@ -43,5 +43,5 @@ def depositor_email # Calling the depositor_email method of the HykuMailer with mock data HykuMailer.new.depositor_email(user, statistics, account) - end + end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 73a44fb3a..26b27234b 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -28,23 +28,23 @@ let!(:stat_yesterday) { UserStat.create!(user_id: subject.id, date: 1.day.ago, file_views: 1, file_downloads: 2, work_views: 3) } let!(:someone_elses_user_id) { subject.id + 1 } let!(:not_my_stat) { UserStat.create!(user_id: someone_elses_user_id, date: 1.month.ago, file_views: 10, file_downloads: 11) } - let(:user_stats) { {:new_file_downloads=>3, :new_work_views=>12, :total_file_downloads=>6, :total_file_views=>7, :total_work_views=>16} } - let(:yesterday_stats) { {:new_file_downloads=>2, :new_work_views=>3, :total_file_downloads=>6, :total_file_views=>7, :total_work_views=>16} } + let(:user_stats) { { new_file_downloads: 3, new_work_views: 12, total_file_downloads: 6, total_file_views: 7, total_work_views: 16 } } + let(:yesterday_stats) { { new_file_downloads: 2, new_work_views: 3, total_file_downloads: 6, total_file_views: 7, total_work_views: 16 } } it 'returns a summary hash of prior months stats' do expect(subject.statistics_for).to eq(user_stats) end it 'summarizes stats for specified date range' do - expect(subject.statistics_for(start_date: Time.now-2.days, end_date: Time.now)).to eq(yesterday_stats) + expect(subject.statistics_for(start_date: Time.zone.now - 2.days, end_date: Time.zone.now)).to eq(yesterday_stats) end it 'returns nil if no statistics in specified date range' do - expect(subject.statistics_for(start_date: Time.now-4.months, end_date: Time.now-5.months)).to be nil + expect(subject.statistics_for(start_date: Time.zone.now - 4.months, end_date: Time.zone.now - 5.months)).to be nil end it 'returns nil if start and end dates the same' do - expect(subject.statistics_for(start_date: Time.now-5.months, end_date: Time.now-5.months)).to be nil + expect(subject.statistics_for(start_date: Time.zone.now - 5.months, end_date: Time.zone.now - 5.months)).to be nil end end end From 2580f605d77129af16c440a91f75adb4ac45ddc4 Mon Sep 17 00:00:00 2001 From: LaRita Robinson Date: Fri, 31 May 2024 16:04:22 -0400 Subject: [PATCH 08/10] Restore "private" in job --- app/jobs/depositor_email_notification_job.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/jobs/depositor_email_notification_job.rb b/app/jobs/depositor_email_notification_job.rb index c55ff2e19..bd707ee6b 100644 --- a/app/jobs/depositor_email_notification_job.rb +++ b/app/jobs/depositor_email_notification_job.rb @@ -20,7 +20,7 @@ def perform(account) end end - # private + private def reenqueue(account) DepositorEmailNotificationJob.set(wait_until: (Time.zone.now + 1.month).beginning_of_month).perform_later(account) From 3d5d9dd9efe177ff4363f47d8254acbd114643f9 Mon Sep 17 00:00:00 2001 From: LaRita Robinson Date: Fri, 31 May 2024 16:18:44 -0400 Subject: [PATCH 09/10] Create Account Spec for recurring jobs --- spec/services/create_account_spec.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/services/create_account_spec.rb b/spec/services/create_account_spec.rb index b6191446f..bf0a19051 100644 --- a/spec/services/create_account_spec.rb +++ b/spec/services/create_account_spec.rb @@ -113,10 +113,11 @@ end describe '#schedule_recurring_jobs' do - it "Enqueues Embargo and Lease Expiry jobs" do + it "Enqueues Recurring jobs" do expect(EmbargoAutoExpiryJob).to receive(:perform_later).with(account) expect(LeaseAutoExpiryJob).to receive(:perform_later).with(account) expect(BatchEmailNotificationJob).to receive(:perform_later).with(account) + expect(DepositorEmailNotificationJob).to receive(:perform_later).with(account) subject.schedule_recurring_jobs end end From 1282e1b2bc28c86cb621df8a3b108d31b31b83ba Mon Sep 17 00:00:00 2001 From: LaRita Robinson Date: Fri, 31 May 2024 16:37:28 -0400 Subject: [PATCH 10/10] Remove bepress --- app/views/hyku_mailer/depositor_email.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/hyku_mailer/depositor_email.html.erb b/app/views/hyku_mailer/depositor_email.html.erb index 51954f719..edb6cc4a4 100644 --- a/app/views/hyku_mailer/depositor_email.html.erb +++ b/app/views/hyku_mailer/depositor_email.html.erb @@ -27,7 +27,7 @@ VISIT MY DASHBOARD