2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
2020-03-31 09:16:14 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2021-03-01 08:18:40 +00:00
|
|
|
RSpec.describe Ticket::Article::EnqueueCommunicateTwitterJob, performs_jobs: true do
|
2020-03-31 09:16:14 +00:00
|
|
|
before { allow(Delayed::Job).to receive(:enqueue).and_call_original }
|
|
|
|
|
|
|
|
let(:article) { create(:ticket_article, **(try(:factory_options) || {})) }
|
|
|
|
|
|
|
|
shared_examples 'for no-op' do
|
|
|
|
it 'is a no-op' do
|
2020-10-27 15:36:38 +00:00
|
|
|
expect { article }.not_to have_enqueued_job(CommunicateTwitterJob)
|
2020-03-31 09:16:14 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'for success' do
|
|
|
|
it 'enqueues the Twitter background job' do
|
2020-10-27 15:36:38 +00:00
|
|
|
expect { article }.to have_enqueued_job(CommunicateTwitterJob)
|
2020-03-31 09:16:14 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-03-01 08:18:40 +00:00
|
|
|
context 'when in Import Mode' do
|
2020-03-31 09:16:14 +00:00
|
|
|
before { Setting.set('import_mode', true) }
|
|
|
|
|
|
|
|
include_examples 'for no-op'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when article is created during Channel::EmailParser#process', application_handle: 'scheduler.postmaster' do
|
|
|
|
include_examples 'for no-op'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when article is from a customer' do
|
|
|
|
let(:factory_options) { { sender_name: 'Customer' } }
|
|
|
|
|
|
|
|
include_examples 'for no-op'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when article is not a tweet' do
|
|
|
|
let(:factory_options) { { sender_name: 'Agent', type_name: 'email' } }
|
|
|
|
|
|
|
|
include_examples 'for no-op'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when article is a tweet' do
|
|
|
|
let(:factory_options) { { sender_name: 'Agent', type_name: 'twitter status' } }
|
|
|
|
|
|
|
|
include_examples 'for success'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when article is a DM' do
|
|
|
|
let(:factory_options) { { sender_name: 'Agent', type_name: 'twitter direct-message' } }
|
|
|
|
|
|
|
|
include_examples 'for success'
|
|
|
|
|
2021-03-01 08:18:40 +00:00
|
|
|
context 'when #to attribute is missing' do
|
2020-03-31 09:16:14 +00:00
|
|
|
let(:factory_options) { { sender_name: 'Agent', type_name: 'twitter direct-message', to: nil } }
|
|
|
|
|
|
|
|
it 'raises an error' do
|
|
|
|
expect { article }.to raise_error(Exceptions::UnprocessableEntity)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|