diff --git a/config/environments/test.rb b/config/environments/test.rb index 115c658..5ab5c83 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -52,4 +52,6 @@ config.action_controller.raise_on_missing_callback_actions = true config.assets.css_compressor = nil + + config.active_job.queue_adapter = :test end diff --git a/lib/tasks/scheduler.rake b/lib/tasks/scheduler.rake index 9d9e577..6a3e22d 100644 --- a/lib/tasks/scheduler.rake +++ b/lib/tasks/scheduler.rake @@ -4,7 +4,7 @@ namespace :scheduler do (next unless Date.today.wday == ENV.fetch("WEEKLY_MESSAGE_DAY").to_i) if ENV.fetch("SET_WEEKLY") == "true" User.contactable.wants_morning_message.find_in_batches do |users| - SendBulkMessageJob.perform_now(users.to_a) + SendBulkMessageJob.perform_later(users.to_a) end end @@ -13,7 +13,7 @@ namespace :scheduler do (next unless Date.today.wday == ENV.fetch("WEEKLY_MESSAGE_DAY").to_i) if ENV.fetch("SET_WEEKLY") == "true" User.contactable.wants_afternoon_message.find_in_batches do |users| - SendBulkMessageJob.perform_now(users.to_a) + SendBulkMessageJob.perform_later(users.to_a) end end @@ -22,7 +22,7 @@ namespace :scheduler do (next unless Date.today.wday == ENV.fetch("WEEKLY_MESSAGE_DAY").to_i) if ENV.fetch("SET_WEEKLY") == "true" User.contactable.wants_evening_message.find_in_batches do |users| - SendBulkMessageJob.perform_now(users.to_a) + SendBulkMessageJob.perform_later(users.to_a) end end @@ -31,7 +31,7 @@ namespace :scheduler do (next unless Date.today.wday == ENV.fetch("WEEKLY_MESSAGE_DAY").to_i) if ENV.fetch("SET_WEEKLY") == "true" User.contactable.no_preference_message.find_in_batches do |users| - SendBulkMessageJob.perform_now(users.to_a) + SendBulkMessageJob.perform_later(users.to_a) end end @@ -39,7 +39,7 @@ namespace :scheduler do task restart_users: :environment do User.opted_out.where("restart_at < ?", Time.now).each do |user| user.update(contactable: true, restart_at: nil) - RestartMessagesJob.perform_now(user) + RestartMessagesJob.perform_later(user) end end @@ -49,7 +49,7 @@ namespace :scheduler do User.contactable.not_nudged.not_clicked_last_two_messages.each do |user| message = Message.create(user:, body: "You've not interacted with any videos lately. Want to continue receiving them? You can text 'PAUSE' for a break, 'ADJUST' for different content, or 'STOP' to stop them entirely.") - SendCustomMessageJob.perform_now(message) + SendCustomMessageJob.perform_later(message) user.update(nudged_at: Time.now) end end diff --git a/test/lib/scheduler_test.rb b/test/lib/scheduler_test.rb index eb0f30b..f547917 100644 --- a/test/lib/scheduler_test.rb +++ b/test/lib/scheduler_test.rb @@ -2,7 +2,7 @@ require "rake" class SchedulerTest < ActiveSupport::TestCase - # include ActiveJob::QueueAdapters::DelayedJobAdapter + include ActiveJob::TestHelper setup do ENV["WEEKLY_MESSAGE_DAY"] = "1" @@ -17,7 +17,7 @@ class SchedulerTest < ActiveSupport::TestCase create(:content) create(:user, timing: "morning") - assert_enqueued_with(job: SendMessageJob) do + assert_enqueued_with(job: SendBulkMessageJob) do Rake::Task["scheduler:send_morning_message"].execute end end @@ -26,7 +26,7 @@ class SchedulerTest < ActiveSupport::TestCase create(:content) create(:user, timing: "afternoon") - assert_enqueued_with(job: SendMessageJob) do + assert_enqueued_with(job: SendBulkMessageJob) do Rake::Task["scheduler:send_afternoon_message"].execute end end @@ -35,7 +35,7 @@ class SchedulerTest < ActiveSupport::TestCase create(:content) create(:user, timing: "evening") - assert_enqueued_with(job: SendMessageJob) do + assert_enqueued_with(job: SendBulkMessageJob) do Rake::Task["scheduler:send_evening_message"].execute end end @@ -44,7 +44,7 @@ class SchedulerTest < ActiveSupport::TestCase create(:content) create(:user, timing: "no_preference") - assert_enqueued_with(job: SendMessageJob) do + assert_enqueued_with(job: SendBulkMessageJob) do Rake::Task["scheduler:send_no_timing_preference_message"].execute end end @@ -53,7 +53,7 @@ class SchedulerTest < ActiveSupport::TestCase create(:content) create(:user, timing: nil) - assert_enqueued_with(job: SendMessageJob) do + assert_enqueued_with(job: SendBulkMessageJob) do Rake::Task["scheduler:send_no_timing_preference_message"].execute end end @@ -71,12 +71,9 @@ class SchedulerTest < ActiveSupport::TestCase user2 = create(:user, contactable: false, restart_at: Time.now + 1.day) user3 = create(:user, contactable: true) - stub_successful_twilio_call( - "Welcome back to Tiny Happy People! Text 'stop' to unsubscribe at any time.", - user - ) - - Rake::Task["scheduler:restart_users"].execute + assert_enqueued_with(job: RestartMessagesJob) do + Rake::Task["scheduler:restart_users"].execute + end user.reload assert user.contactable @@ -105,12 +102,9 @@ class SchedulerTest < ActiveSupport::TestCase create(:message, user: user3, clicked_at: nil, content:) create(:message, user: user3, clicked_at: nil, content:) - stub_successful_twilio_call( - "You've not interacted with any videos lately. Want to continue receiving them? You can text 'PAUSE' for a break, 'ADJUST' for different content, or 'STOP' to stop them entirely.", - user1 - ) - - Rake::Task["scheduler:check_for_disengaged_users"].execute + assert_enqueued_with(job: SendCustomMessageJob) do + Rake::Task["scheduler:check_for_disengaged_users"].execute + end assert_equal 1, Message.where(body: "You've not interacted with any videos lately. Want to continue receiving them? You can text 'PAUSE' for a break, 'ADJUST' for different content, or 'STOP' to stop them entirely.").count end @@ -133,7 +127,7 @@ class SchedulerTest < ActiveSupport::TestCase create(:content) create(:user, timing: "morning") - assert_enqueued_with(job: SendMessageJob) do + assert_enqueued_with(job: SendBulkMessageJob) do Rake::Task["scheduler:send_morning_message"].execute end end