forked from pinballmap/pbm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
10 additions
and
28 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
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 |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
RSpec.describe OperatorMailer, type: :mailer do | ||
describe 'send_daily_digest_operator_email' do | ||
it 'should send email digest with location edits' do | ||
email = OperatorMailer.with(to_email: '[email protected]', machine_comments: [ 'foo' ], machines_added: [ 'Pirates of the Pacific' ], machines_removed: [ 'Battle of Midway' ]).send_daily_digest_operator_email | ||
email = OperatorMailer.with(email_to: '[email protected]', machine_comments: [ 'foo' ], machines_added: [ 'Pirates of the Pacific' ], machines_removed: [ 'Battle of Midway' ]).send_daily_digest_operator_email | ||
|
||
assert_emails 1 do | ||
email.deliver_later | ||
|
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 |
---|---|---|
|
@@ -33,43 +33,27 @@ | |
end | ||
end | ||
|
||
describe '#send_recent_comments' do | ||
describe 'generate_operator_daily_digest' do | ||
it 'Skips operators with no email address set' do | ||
expect { @no_email_operator.send_recent_comments }.to_not have_enqueued_job | ||
expect { @no_email_operator.generate_operator_daily_digest }.to_not have_enqueued_job | ||
end | ||
|
||
it 'Skips operators with no changes to report' do | ||
expect { @no_changes_operator.send_recent_comments }.to_not have_enqueued_job | ||
expect { @no_changes_operator.generate_operator_daily_digest }.to_not have_enqueued_job | ||
end | ||
|
||
it 'Sends emails to operators with recent comments on their machines' do | ||
l = FactoryBot.create(:location, region: @r, operator: @o, name: 'Cleo Corner') | ||
@l = FactoryBot.create(:location, region: @r, operator: @o, name: 'Cleo Corner') | ||
|
||
m1 = FactoryBot.create(:machine, name: 'Sassy') | ||
m2 = FactoryBot.create(:machine, name: 'Cleo') | ||
lmx1 = FactoryBot.create(:location_machine_xref, location: l, machine: m1) | ||
lmx2 = FactoryBot.create(:location_machine_xref, location: l, machine: m2) | ||
FactoryBot.create(:user_submission, created_at: (Time.now - 1.day), location: @l, submission: 'foo', submission_type: UserSubmission::NEW_LMX_TYPE) | ||
|
||
mc1 = FactoryBot.create(:machine_condition, location_machine_xref: lmx1, comment: 'Sassy Comment', created_at: (Time.now - 1.day).beginning_of_day, updated_at: (Time.now - 1.day).beginning_of_day) | ||
mc2 = FactoryBot.create(:machine_condition, location_machine_xref: lmx2, comment: 'Cleo Comment', created_at: (Time.now - 1.day).beginning_of_day, updated_at: (Time.now - 1.day).beginning_of_day) | ||
FactoryBot.create(:machine_condition, location_machine_xref: lmx2, comment: 'Old Cleo Comment', created_at: Date.today - 2.days) | ||
FactoryBot.create(:user_submission, created_at: (Time.now - 1.day).beginning_of_day, location: @l, submission: 'bar', submission_type: UserSubmission::REMOVE_MACHINE_TYPE) | ||
|
||
expect { @o.send_recent_comments }.to have_enqueued_job(ActionMailer::MailDeliveryJob).with('OperatorMailer', 'send_recent_comments', 'deliver_now', { params: { email: '[email protected]', heading: "Here are the comments left on your pinball machines yesterday on Pinball Map. We hope this helps you identify and fix problems. You opted in to receive these, but if you don't want them anymore reply to this message and tell us! Also, see our FAQ: https://pinballmap.com/faq#operators", comments: [ "Comment: Sassy Comment\nLocation: Cleo Corner - 303 Southeast 3rd Avenue, Portland, OR, 97214\nMachine: Sassy\nDate: #{mc1.updated_at.strftime('%b %d, %Y - %I:%M%p %Z')}", "Comment: Cleo Comment\nLocation: Cleo Corner - 303 Southeast 3rd Avenue, Portland, OR, 97214\nMachine: Cleo\nDate: #{mc2.updated_at.strftime('%b %d, %Y - %I:%M%p %Z')}" ] }, args: [] }) | ||
end | ||
|
||
it 'Sends emails to regionless operators with recent comments on their machines' do | ||
l = FactoryBot.create(:location, region: nil, operator: @o, name: 'Cleo Corner') | ||
|
||
m1 = FactoryBot.create(:machine, name: 'Sassy') | ||
m2 = FactoryBot.create(:machine, name: 'Cleo') | ||
lmx1 = FactoryBot.create(:location_machine_xref, location: l, machine: m1) | ||
lmx2 = FactoryBot.create(:location_machine_xref, location: l, machine: m2) | ||
FactoryBot.create(:user_submission, created_at: (Time.now - 1.day).beginning_of_day, location: @l, submission: 'baz', submission_type: UserSubmission::NEW_CONDITION_TYPE) | ||
|
||
mc1 = FactoryBot.create(:machine_condition, location_machine_xref: lmx1, comment: 'Sassy Comment', created_at: (Time.now - 1.day).beginning_of_day) | ||
mc2 = FactoryBot.create(:machine_condition, location_machine_xref: lmx2, comment: 'Cleo Comment', created_at: (Time.now - 1.day).beginning_of_day) | ||
FactoryBot.create(:machine_condition, location_machine_xref: lmx2, comment: 'Old Cleo Comment', created_at: Date.today - 2.days) | ||
FactoryBot.create(:user_submission, created_at: (Time.now - 3.day).beginning_of_day, location: @l, submission: 'bong', submission_type: UserSubmission::NEW_CONDITION_TYPE) | ||
|
||
expect { @o.send_recent_comments }.to have_enqueued_job(ActionMailer::MailDeliveryJob).with('OperatorMailer', 'send_recent_comments', 'deliver_now', { params: { email: '[email protected]', heading: "Here are the comments left on your pinball machines yesterday on Pinball Map. We hope this helps you identify and fix problems. You opted in to receive these, but if you don't want them anymore reply to this message and tell us! Also, see our FAQ: https://pinballmap.com/faq#operators", comments: [ "Comment: Sassy Comment\nLocation: Cleo Corner - 303 Southeast 3rd Avenue, Portland, OR, 97214\nMachine: Sassy\nDate: #{mc1.updated_at.strftime('%b %d, %Y - %I:%M%p %Z')}", "Comment: Cleo Comment\nLocation: Cleo Corner - 303 Southeast 3rd Avenue, Portland, OR, 97214\nMachine: Cleo\nDate: #{mc2.updated_at.strftime('%b %d, %Y - %I:%M%p %Z')}" ] }, args: [] }) | ||
expect(@o.generate_operator_daily_digest[:machine_comments]).to eq(%w[baz]) | ||
end | ||
end | ||
end |