diff --git a/spec/jobs/automation_rules/process_pending_execution_job_spec.rb b/spec/jobs/automation_rules/process_pending_execution_job_spec.rb index 72f755a8a..fbde4fd01 100644 --- a/spec/jobs/automation_rules/process_pending_execution_job_spec.rb +++ b/spec/jobs/automation_rules/process_pending_execution_job_spec.rb @@ -103,7 +103,9 @@ RSpec.describe AutomationRules::ProcessPendingExecutionJob do end it 'leaves the row processing and reports the error when an action blows up' do - allow(AutomationRules::ActionService).to receive(:new).and_raise(StandardError, 'boom') + action_service = instance_double(AutomationRules::ActionService) + allow(AutomationRules::ActionService).to receive(:new).and_return(action_service) + allow(action_service).to receive(:perform).and_raise(StandardError, 'boom') allow(ChatwootExceptionTracker).to receive(:new).and_call_original job.perform(pending_execution.reload) @@ -124,7 +126,7 @@ RSpec.describe AutomationRules::ProcessPendingExecutionJob do job.perform(row.reload) expect(row.reload).to be_executed - expect(conversation.messages.outgoing.pluck(:content)).to include('Just checking in') + expect(conversation.messages.outgoing.where(content: 'Just checking in').count).to eq(1) end it 'cancels the follow-up when the customer replied before it was due' do diff --git a/spec/jobs/automation_rules/trigger_pending_executions_job_spec.rb b/spec/jobs/automation_rules/trigger_pending_executions_job_spec.rb index d365f512d..4bcf8dad5 100644 --- a/spec/jobs/automation_rules/trigger_pending_executions_job_spec.rb +++ b/spec/jobs/automation_rules/trigger_pending_executions_job_spec.rb @@ -10,9 +10,11 @@ RSpec.describe AutomationRules::TriggerPendingExecutionsJob do it 'enqueues a per-row job for due pending rows but not future ones' do due_row = create(:automation_rule_pending_execution, account: account, conversation: conversation, due_at: 1.minute.ago) - create(:automation_rule_pending_execution, account: account, due_at: 1.hour.from_now) + future_row = create(:automation_rule_pending_execution, account: account, due_at: 1.hour.from_now) - expect { job.perform }.to have_enqueued_job(AutomationRules::ProcessPendingExecutionJob).exactly(:once).with(due_row) + expect { job.perform }.to have_enqueued_job(AutomationRules::ProcessPendingExecutionJob).exactly(:once) + expect(AutomationRules::ProcessPendingExecutionJob).to have_been_enqueued.with(due_row) + expect(AutomationRules::ProcessPendingExecutionJob).not_to have_been_enqueued.with(future_row) end it 're-enqueues stale processing rows so they get retried' do diff --git a/spec/models/automation_rule_pending_execution_spec.rb b/spec/models/automation_rule_pending_execution_spec.rb index 31dd2e642..d76296e65 100644 --- a/spec/models/automation_rule_pending_execution_spec.rb +++ b/spec/models/automation_rule_pending_execution_spec.rb @@ -20,7 +20,7 @@ RSpec.describe AutomationRulePendingExecution do it 'derives awaiting_agent episodes from waiting_since (sub-second) for incoming messages' do message = create(:message, conversation: conversation, account: account, message_type: :incoming) - expect(described_class.episode_key_for(conversation.reload, message)).to eq("awaiting_agent:#{conversation.waiting_since.to_f}") + expect(described_class.episode_key_for(conversation.reload, message)).to eq("awaiting_agent:#{conversation.waiting_since.strftime('%s%6N')}") end it 'distinguishes two waiting periods that fall within the same second' do @@ -40,7 +40,7 @@ RSpec.describe AutomationRulePendingExecution do # Once waiting_since settles to the message's created_at, the strict fire-time key matches. conversation.update!(waiting_since: message.created_at) - expect(armed_key).to eq("awaiting_agent:#{message.created_at.to_f}") + expect(armed_key).to eq("awaiting_agent:#{message.created_at.strftime('%s%6N')}") expect(armed_key).to eq(described_class.episode_key_for(conversation.reload, message)) end