Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanTG committed Feb 5, 2025
1 parent eccea54 commit b71fa5f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 28 deletions.
2 changes: 0 additions & 2 deletions lib/tasks/notify_operators.rake
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ task send_daily_digest_operator_email: :environment do

next if machine_comments.empty? && machines_added.empty? && machines_removed.empty?

puts "machine comments #{machine_comments}"

email_to = o.email.to_s

OperatorMailer.with(email_to: email_to, machine_comments: machine_comments, machines_added: machines_added, machines_removed: machines_removed).send_daily_digest_operator_email.deliver_later
Expand Down
2 changes: 1 addition & 1 deletion spec/mailers/operator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 9 additions & 25 deletions spec/models/operator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b71fa5f

Please sign in to comment.