Restructure omni services and add Chatwoot research snapshot

This commit is contained in:
Ruslan Bakiev
2026-02-21 11:11:27 +07:00
parent edea7a0034
commit b73babbbf6
7732 changed files with 978203 additions and 32 deletions

View File

@@ -0,0 +1,44 @@
require 'rails_helper'
RSpec.describe Account::ConversationsResolutionSchedulerJob, type: :job do
let(:account) { create(:account) }
let(:assistant) { create(:captain_assistant, account: account) }
describe '#perform - captain resolutions' do
context 'when handling different inbox types' do
let!(:regular_inbox) { create(:inbox, account: account) }
let!(:email_inbox) { create(:inbox, :with_email, account: account) }
before do
create(:captain_inbox, captain_assistant: assistant, inbox: regular_inbox)
create(:captain_inbox, captain_assistant: assistant, inbox: email_inbox)
end
it 'enqueues resolution jobs only for non-email inboxes with captain enabled' do
expect do
described_class.perform_now
end.to have_enqueued_job(Captain::InboxPendingConversationsResolutionJob)
.with(regular_inbox)
.exactly(:once)
end
it 'does not enqueue resolution jobs for email inboxes even with captain enabled' do
expect do
described_class.perform_now
end.not_to have_enqueued_job(Captain::InboxPendingConversationsResolutionJob)
.with(email_inbox)
end
end
context 'when inbox has no captain enabled' do
let!(:inbox_without_captain) { create(:inbox, account: create(:account)) }
it 'does not enqueue resolution jobs' do
expect do
described_class.perform_now
end.not_to have_enqueued_job(Captain::InboxPendingConversationsResolutionJob)
.with(inbox_without_captain)
end
end
end
end

View File

@@ -0,0 +1,47 @@
require 'rails_helper'
RSpec.describe Enterprise::CloudflareVerificationJob do
let(:portal) { create(:portal, custom_domain: 'test.example.com') }
describe '#perform' do
context 'when portal is not found' do
it 'returns early' do
expect(Portal).to receive(:find).with(0).and_return(nil)
expect(Cloudflare::CheckCustomHostnameService).not_to receive(:new)
expect(Cloudflare::CreateCustomHostnameService).not_to receive(:new)
described_class.perform_now(0)
end
end
context 'when portal has no custom domain' do
it 'returns early' do
portal_without_domain = create(:portal, custom_domain: nil)
expect(Cloudflare::CheckCustomHostnameService).not_to receive(:new)
expect(Cloudflare::CreateCustomHostnameService).not_to receive(:new)
described_class.perform_now(portal_without_domain.id)
end
end
context 'when portal exists with custom domain' do
it 'checks hostname status' do
check_service = instance_double(Cloudflare::CheckCustomHostnameService, perform: { data: 'success' })
expect(Cloudflare::CheckCustomHostnameService).to receive(:new).with(portal: portal).and_return(check_service)
expect(Cloudflare::CreateCustomHostnameService).not_to receive(:new)
described_class.perform_now(portal.id)
end
it 'creates hostname when check returns errors' do
check_service = instance_double(Cloudflare::CheckCustomHostnameService, perform: { errors: ['Hostname is missing'] })
create_service = instance_double(Cloudflare::CreateCustomHostnameService, perform: { data: 'success' })
expect(Cloudflare::CheckCustomHostnameService).to receive(:new).with(portal: portal).and_return(check_service)
expect(Cloudflare::CreateCustomHostnameService).to receive(:new).with(portal: portal).and_return(create_service)
described_class.perform_now(portal.id)
end
end
end
end

View File

@@ -0,0 +1,27 @@
require 'rails_helper'
RSpec.describe Enterprise::CreateStripeCustomerJob, type: :job do
include ActiveJob::TestHelper
subject(:job) { described_class.perform_later(account) }
let(:account) { create(:account) }
it 'queues the job' do
expect { job }.to have_enqueued_job(described_class)
.with(account)
.on_queue('default')
end
it 'executes perform' do
create_stripe_customer_service = double
allow(Enterprise::Billing::CreateStripeCustomerService)
.to receive(:new)
.with(account: account)
.and_return(create_stripe_customer_service)
allow(create_stripe_customer_service).to receive(:perform)
perform_enqueued_jobs { job }
expect(Enterprise::Billing::CreateStripeCustomerService).to have_received(:new).with(account: account)
end
end

View File

@@ -0,0 +1,29 @@
require 'rails_helper'
RSpec.describe DeleteObjectJob, type: :job do
include ActiveJob::TestHelper
subject(:job) { described_class.perform_later(account) }
let(:account) { create(:account) }
let(:user) { create(:user) }
let(:team) { create(:team, account: account) }
let(:inbox) { create(:inbox, account: account) }
context 'when an object is passed to the job with arguments' do
it 'creates log with associated data if its an inbox' do
described_class.perform_later(inbox, user, '127.0.0.1')
perform_enqueued_jobs
audit_log = Audited::Audit.where(auditable_type: 'Inbox', action: 'destroy', username: user.uid, remote_address: '127.0.0.1').first
expect(audit_log).to be_present
expect(audit_log.audited_changes.keys).to include('id', 'name', 'account_id')
expect { inbox.reload }.to raise_error(ActiveRecord::RecordNotFound)
end
it 'will not create logs for other objects' do
described_class.perform_later(account, user, '127.0.0.1')
perform_enqueued_jobs
expect(Audited::Audit.where(auditable_type: 'Team', action: 'destroy').count).to eq 0
end
end
end

View File

@@ -0,0 +1,32 @@
require 'rails_helper'
RSpec.describe Internal::CheckNewVersionsJob do
subject(:job) { described_class.perform_now }
let(:reconsile_premium_config_service) { instance_double(Internal::ReconcilePlanConfigService) }
before do
allow(Internal::ReconcilePlanConfigService).to receive(:new).and_return(reconsile_premium_config_service)
allow(reconsile_premium_config_service).to receive(:perform)
allow(Rails.env).to receive(:production?).and_return(true)
end
it 'updates the plan info' do
data = { 'version' => '1.2.3', 'plan' => 'enterprise', 'plan_quantity' => 1, 'chatwoot_support_website_token' => '123',
'chatwoot_support_identifier_hash' => '123', 'chatwoot_support_script_url' => '123' }
allow(ChatwootHub).to receive(:sync_with_hub).and_return(data)
job
expect(InstallationConfig.find_by(name: 'INSTALLATION_PRICING_PLAN').value).to eq 'enterprise'
expect(InstallationConfig.find_by(name: 'INSTALLATION_PRICING_PLAN_QUANTITY').value).to eq 1
expect(InstallationConfig.find_by(name: 'CHATWOOT_SUPPORT_WEBSITE_TOKEN').value).to eq '123'
expect(InstallationConfig.find_by(name: 'CHATWOOT_SUPPORT_IDENTIFIER_HASH').value).to eq '123'
expect(InstallationConfig.find_by(name: 'CHATWOOT_SUPPORT_SCRIPT_URL').value).to eq '123'
end
it 'calls Internal::ReconcilePlanConfigService' do
data = { 'version' => '1.2.3' }
allow(ChatwootHub).to receive(:sync_with_hub).and_return(data)
job
expect(reconsile_premium_config_service).to have_received(:perform)
end
end

View File

@@ -0,0 +1,10 @@
require 'rails_helper'
RSpec.describe TriggerScheduledItemsJob do
subject(:job) { described_class.perform_later }
it 'triggers Sla::TriggerSlasForAccountsJob' do
expect(Sla::TriggerSlasForAccountsJob).to receive(:perform_later).once
described_class.perform_now
end
end