Skip to content
This repository has been archived by the owner on Nov 18, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1574 from psu-stewardship/i#1520a-email-stats
Browse files Browse the repository at this point in the history
Verify that emails are sent for monthly stats
  • Loading branch information
Michael Tribone authored May 3, 2019
2 parents 1b51b95 + 5874d27 commit 9b80aa1
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/jobs/user_stats_notification_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def perform(id:, start_date:, end_date:)
return unless PsuDir::LdapUser.check_ldap_exist!(user.login)

UserMailer.user_stats_email(
user_email: user.email,
user: user,
start_date: start_date,
end_date: end_date
).deliver_now
Expand Down
6 changes: 3 additions & 3 deletions config/sample/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ development:
service_instance: "localhost"
virtual_host: "http://localhost:3000/"
stats_email: "ScholarSphere Stats <[email protected]>"
no_reply_email: "no_repy@scholarsphere.psu.edu"
no_reply_email: "no_reply@scholarsphere.psu.edu"
google_analytics_id: "test-id"
read_only: "false"
EZID_USER: 'ezid_user'
Expand All @@ -30,7 +30,7 @@ test:
service_instance: "example-test"
virtual_host: "http://test.com/"
stats_email: "Test email"
no_reply_email: "no_repy@scholarsphere.psu.edu"
no_reply_email: "no_reply@scholarsphere.psu.edu"
google_analytics_id: "test-id"
read_only: "false"
RECAPTCHA_SITE_KEY: 'site-key'
Expand All @@ -48,7 +48,7 @@ production:
service_instance: "example-prod"
virtual_host: "http://test.com/"
stats_email: "Test email"
no_reply_email: "no_repy@scholarsphere.psu.edu"
no_reply_email: "no_reply@scholarsphere.psu.edu"
google_analytics_id: "test-id"
derivatives_path: "path"
read_only: "false"
Expand Down
6 changes: 3 additions & 3 deletions config/travis/application_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ development:
service_instance: "localhost"
virtual_host: "http://localhost:3000/"
stats_email: "ScholarSphere Stats <[email protected]>"
no_reply_email: "no_repy@scholarsphere.psu.edu"
no_reply_email: "no_reply@scholarsphere.psu.edu"
google_analytics_id: "test-id"
read_only: "false"
EZID_USER: 'ezid_user'
Expand All @@ -30,7 +30,7 @@ test:
service_instance: "example-test"
virtual_host: "http://test.com/"
stats_email: "Test email"
no_reply_email: "no_repy@scholarsphere.psu.edu"
no_reply_email: "no_reply@scholarsphere.psu.edu"
google_analytics_id: "test-id"
read_only: "false"
RECAPTCHA_SITE_KEY: 'site-key'
Expand All @@ -48,7 +48,7 @@ production:
service_instance: "example-prod"
virtual_host: "http://test.com/"
stats_email: "Test email"
no_reply_email: "no_repy@scholarsphere.psu.edu"
no_reply_email: "no_reply@scholarsphere.psu.edu"
google_analytics_id: "test-id"
derivatives_path: "path"
read_only: "false"
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/scholarsphere/stats.rake
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace :scholarsphere do
start_date = Date.today.last_month.beginning_of_month
end_date = Date.today.last_month.end_of_month
UserStat.where(date: start_date..end_date).map(&:user_id).uniq.map do |id|
UserStatsNotificationJob.perform_later(id: id, start_date: start_date, end_date: end_date)
UserStatsNotificationJob.perform_later(id: id, start_date: start_date.to_s, end_date: end_date.to_s)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/jobs/user_stats_notification_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

it 'sends the email to the user' do
expect(UserMailer).to receive(:user_stats_email)
.with(user_email: user.email, start_date: start_date, end_date: end_date)
.with(user: user, start_date: start_date, end_date: end_date)
.and_return(mock_mailer)
expect(mock_mailer).to receive(:deliver_now)
described_class.perform_now(id: user.id, start_date: start_date, end_date: end_date)
Expand Down
8 changes: 6 additions & 2 deletions spec/rake/scholarsphere/stats_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,19 @@
end

context 'when a user has stats' do
let(:user) { create(:user) }
let(:user) { create(:user, email: '[email protected]') }
let(:message) { ActionMailer::Base.deliveries.first }

before do
allow(PsuDir::LdapUser).to receive(:check_ldap_exist!).with(user.login).and_return(true)
UserStat.create(user_id: user.id, date: (Date.today.last_month.beginning_of_month + 10), file_downloads: 5)
end

it 'sends an email to the user' do
expect(UserStatsNotificationJob).to receive(:perform_later)
run_task('scholarsphere:stats:notify')
expect(message.to).to contain_exactly('[email protected]')
expect(message.from).to contain_exactly(ENV['no_reply_email'])
expect(message.subject).to eq('ScholarSphere - Reporting Monthly Downloads and Views')
end
end
end
Expand Down

0 comments on commit 9b80aa1

Please sign in to comment.