[verified] Remove Chatwoot Hub sync paths
This commit is contained in:
@@ -13,10 +13,11 @@ RSpec.describe 'Installation::Onboarding API', type: :request do
|
||||
end
|
||||
|
||||
context 'when CHATWOOT_INSTALLATION_ONBOARDING redis key is set' do
|
||||
it 'returns onboarding page' do
|
||||
it 'returns onboarding page without a subscription checkbox' do
|
||||
Redis::Alfred.set(Redis::Alfred::CHATWOOT_INSTALLATION_ONBOARDING, true)
|
||||
get '/installation/onboarding'
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(response.body).not_to include('subscribe_to_updates')
|
||||
Redis::Alfred.delete(Redis::Alfred::CHATWOOT_INSTALLATION_ONBOARDING)
|
||||
end
|
||||
end
|
||||
@@ -28,7 +29,6 @@ RSpec.describe 'Installation::Onboarding API', type: :request do
|
||||
before do
|
||||
allow(AccountBuilder).to receive(:new).and_return(account_builder)
|
||||
allow(account_builder).to receive(:perform).and_return(true)
|
||||
allow(ChatwootHub).to receive(:register_instance).and_return(true)
|
||||
Redis::Alfred.set(Redis::Alfred::CHATWOOT_INSTALLATION_ONBOARDING, true)
|
||||
end
|
||||
|
||||
@@ -42,14 +42,9 @@ RSpec.describe 'Installation::Onboarding API', type: :request do
|
||||
expect(Redis::Alfred.get(Redis::Alfred::CHATWOOT_INSTALLATION_ONBOARDING)).to be_nil
|
||||
end
|
||||
|
||||
it 'will not call register instance when checkboxes are unchecked' do
|
||||
post '/installation/onboarding', params: { user: {} }
|
||||
expect(ChatwootHub).not_to have_received(:register_instance)
|
||||
end
|
||||
|
||||
it 'will call register instance when checkboxes are checked' do
|
||||
it 'accepts the subscription parameter without remote registration' do
|
||||
post '/installation/onboarding', params: { user: {}, subscribe_to_updates: 1 }
|
||||
expect(ChatwootHub).to have_received(:register_instance)
|
||||
expect(response).to have_http_status(:redirect)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
13
spec/controllers/super_admin/settings_controller_spec.rb
Normal file
13
spec/controllers/super_admin/settings_controller_spec.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe SuperAdmin::SettingsController do
|
||||
it 'does not expose a manual refresh action' do
|
||||
expect(described_class.action_methods).not_to include('refresh')
|
||||
end
|
||||
|
||||
it 'does not leave a manual refresh link in the settings view' do
|
||||
template = Rails.root.join('app/views/super_admin/settings/show.html.erb').read
|
||||
|
||||
expect(template).not_to include('refresh_super_admin_settings_url')
|
||||
end
|
||||
end
|
||||
@@ -8,25 +8,19 @@ RSpec.describe Internal::CheckNewVersionsJob do
|
||||
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)
|
||||
it 'does not reconcile enterprise configuration from a remote response' do
|
||||
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'
|
||||
|
||||
expect(reconsile_premium_config_service).not_to have_received(:perform)
|
||||
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)
|
||||
it 'does not update installation configuration' do
|
||||
expect { job }.not_to(
|
||||
change do
|
||||
InstallationConfig.where(name: %w[INSTALLATION_PRICING_PLAN INSTALLATION_PRICING_PLAN_QUANTITY]).pluck(:name, :serialized_value)
|
||||
end
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,12 +3,11 @@ require 'rails_helper'
|
||||
RSpec.describe Internal::CheckNewVersionsJob do
|
||||
subject(:job) { described_class.perform_now }
|
||||
|
||||
it 'updates the latest chatwoot version in redis' do
|
||||
data = { 'version' => '1.2.3' }
|
||||
allow(Rails.env).to receive(:production?).and_return(true)
|
||||
allow(ChatwootHub).to receive(:sync_with_hub).and_return(data)
|
||||
it 'does not write a remote version result' do
|
||||
allow(Redis::Alfred).to receive(:set)
|
||||
|
||||
job
|
||||
expect(ChatwootHub).to have_received(:sync_with_hub)
|
||||
expect(Redis::Alfred.get(Redis::Alfred::LATEST_CHATWOOT_VERSION)).to eq data['version']
|
||||
|
||||
expect(Redis::Alfred).not_to have_received(:set)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,14 +3,8 @@ require 'rails_helper'
|
||||
RSpec.describe Internal::TriggerDailyScheduledItemsJob do
|
||||
subject(:perform_job) { described_class.perform_now }
|
||||
|
||||
let(:installation_id) { 'test-installation-id' }
|
||||
let(:designated_minute) { Digest::MD5.hexdigest(installation_id).hex % 1440 }
|
||||
let(:scheduled_time) { Time.current.utc.beginning_of_day + designated_minute.minutes }
|
||||
let(:configured_job) { instance_double(ActiveJob::ConfiguredJob, perform_later: true) }
|
||||
|
||||
before do
|
||||
allow(ChatwootHub).to receive(:installation_identifier).and_return(installation_id)
|
||||
allow(Internal::CheckNewVersionsJob).to receive(:set).and_return(configured_job)
|
||||
allow(Internal::CheckNewVersionsJob).to receive(:set)
|
||||
end
|
||||
|
||||
it 'enqueues the job' do
|
||||
@@ -18,20 +12,9 @@ RSpec.describe Internal::TriggerDailyScheduledItemsJob do
|
||||
.on_queue('scheduled_jobs')
|
||||
end
|
||||
|
||||
it 'schedules the version check at a stable minute in production' do
|
||||
it 'does not enqueue the remote version check in production' do
|
||||
allow(Rails.env).to receive(:production?).and_return(true)
|
||||
|
||||
travel_to Time.zone.parse('2026-03-17 08:00:00 UTC') do
|
||||
perform_job
|
||||
|
||||
expect(Internal::CheckNewVersionsJob).to have_received(:set).with(wait_until: scheduled_time)
|
||||
expect(configured_job).to have_received(:perform_later)
|
||||
end
|
||||
end
|
||||
|
||||
it 'does not schedule the version check outside production' do
|
||||
allow(Rails.env).to receive(:production?).and_return(false)
|
||||
|
||||
perform_job
|
||||
|
||||
expect(Internal::CheckNewVersionsJob).not_to have_received(:set)
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe ChatwootHub do
|
||||
it 'does not expose remote sync, registration, or event APIs' do
|
||||
expect(described_class).not_to respond_to(:sync_with_hub)
|
||||
expect(described_class).not_to respond_to(:register_instance)
|
||||
expect(described_class).not_to respond_to(:emit_event)
|
||||
end
|
||||
|
||||
describe '.base_url' do
|
||||
it 'uses the static hub url' do
|
||||
expect(described_class::DEFAULT_BASE_URL).to eq('https://hub.2.chatwoot.com')
|
||||
@@ -13,67 +19,4 @@ describe ChatwootHub do
|
||||
expect(installation_identifier).not_to be_nil
|
||||
expect(described_class.installation_identifier).to eq installation_identifier
|
||||
end
|
||||
|
||||
context 'when fetching sync_with_hub' do
|
||||
it 'get latest version from chatwoot hub' do
|
||||
version = '1.1.1'
|
||||
allow(RestClient).to receive(:post).and_return({ version: version }.to_json)
|
||||
expect(described_class.sync_with_hub['version']).to eq version
|
||||
expect(RestClient).to have_received(:post).with(described_class.ping_url, described_class.instance_config
|
||||
.merge(described_class.instance_metrics).to_json, { content_type: :json, accept: :json })
|
||||
end
|
||||
|
||||
it 'will not send instance metrics when telemetry is disabled' do
|
||||
version = '1.1.1'
|
||||
with_modified_env DISABLE_TELEMETRY: 'true' do
|
||||
allow(RestClient).to receive(:post).and_return({ version: version }.to_json)
|
||||
expect(described_class.sync_with_hub['version']).to eq version
|
||||
expect(RestClient).to have_received(:post).with(described_class.ping_url,
|
||||
described_class.instance_config.to_json, { content_type: :json, accept: :json })
|
||||
end
|
||||
end
|
||||
|
||||
it 'returns nil when chatwoot hub is down' do
|
||||
allow(RestClient).to receive(:post).and_raise(ExceptionList::REST_CLIENT_EXCEPTIONS.sample)
|
||||
expect(described_class.sync_with_hub).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'when register instance' do
|
||||
let(:company_name) { 'test' }
|
||||
let(:owner_name) { 'test' }
|
||||
let(:owner_email) { 'test@test.com' }
|
||||
|
||||
it 'sends info of registration' do
|
||||
info = { company_name: company_name, owner_name: owner_name, owner_email: owner_email, subscribed_to_mailers: true }
|
||||
allow(RestClient).to receive(:post)
|
||||
described_class.register_instance(company_name, owner_name, owner_email)
|
||||
expect(RestClient).to have_received(:post).with(described_class.registration_url,
|
||||
info.merge(described_class.instance_config).to_json, { content_type: :json, accept: :json })
|
||||
end
|
||||
end
|
||||
|
||||
context 'when sending events' do
|
||||
let(:event_name) { 'sample_event' }
|
||||
let(:event_data) { { 'sample_data' => 'sample_data' } }
|
||||
|
||||
it 'will send instance events' do
|
||||
info = { event_name: event_name, event_data: event_data }
|
||||
allow(RestClient).to receive(:post)
|
||||
described_class.emit_event(event_name, event_data)
|
||||
expect(RestClient).to have_received(:post).with(described_class.events_url,
|
||||
info.merge(described_class.instance_config).to_json, { content_type: :json, accept: :json })
|
||||
end
|
||||
|
||||
it 'will not send instance events when telemetry is disabled' do
|
||||
with_modified_env DISABLE_TELEMETRY: 'true' do
|
||||
info = { event_name: event_name, event_data: event_data }
|
||||
allow(RestClient).to receive(:post)
|
||||
described_class.emit_event(event_name, event_data)
|
||||
expect(RestClient).not_to have_received(:post)
|
||||
.with(described_class.events_url,
|
||||
info.merge(described_class.instance_config).to_json, { content_type: :json, accept: :json })
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user