chore: one off SMS campaign APIs (#2589)
This commit is contained in:
23
spec/jobs/campaigns/trigger_oneoff_campaign_job_spec.rb
Normal file
23
spec/jobs/campaigns/trigger_oneoff_campaign_job_spec.rb
Normal file
@@ -0,0 +1,23 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Campaigns::TriggerOneoffCampaignJob, type: :job do
|
||||
let(:account) { create(:account) }
|
||||
let!(:twilio_sms) { create(:channel_twilio_sms) }
|
||||
let!(:twilio_inbox) { create(:inbox, channel: twilio_sms) }
|
||||
let(:label1) { create(:label, account: account) }
|
||||
let(:label2) { create(:label, account: account) }
|
||||
|
||||
let!(:campaign) { create(:campaign, inbox: twilio_inbox, audience: [{ type: 'Label', id: label1.id }, { type: 'Label', id: label2.id }]) }
|
||||
|
||||
it 'enqueues the job' do
|
||||
expect { described_class.perform_later(campaign) }.to have_enqueued_job(described_class)
|
||||
.on_queue('low')
|
||||
end
|
||||
|
||||
context 'when called with a campaign' do
|
||||
it 'triggers the campaign' do
|
||||
expect(campaign).to receive(:trigger!)
|
||||
described_class.perform_now(campaign)
|
||||
end
|
||||
end
|
||||
end
|
||||
24
spec/jobs/trigger_scheduled_items_job_spec.rb
Normal file
24
spec/jobs/trigger_scheduled_items_job_spec.rb
Normal file
@@ -0,0 +1,24 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe TriggerScheduledItemsJob, type: :job do
|
||||
subject(:job) { described_class.perform_later }
|
||||
|
||||
let(:account) { create(:account) }
|
||||
|
||||
it 'enqueues the job' do
|
||||
expect { job }.to have_enqueued_job(described_class)
|
||||
.on_queue('scheduled_jobs')
|
||||
end
|
||||
|
||||
context 'when unexecuted Scheduled campaign jobs' do
|
||||
let!(:twilio_sms) { create(:channel_twilio_sms) }
|
||||
let!(:twilio_inbox) { create(:inbox, channel: twilio_sms) }
|
||||
|
||||
it 'triggers Campaigns::TriggerOneoffCampaignJob' do
|
||||
campaign = create(:campaign, inbox: twilio_inbox)
|
||||
create(:campaign, inbox: twilio_inbox, scheduled_at: 10.days.after)
|
||||
expect(Campaigns::TriggerOneoffCampaignJob).to receive(:perform_later).with(campaign).once
|
||||
described_class.perform_now
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user