mirror of
https://github.com/chatwoot/chatwoot.git
synced 2026-06-04 21:02:35 +08:00
# Pull Request Template ## Description fixes: https://linear.app/chatwoot/issue/AI-151/captains-super-admin-config-dont-get-applied-into-rails-without ## Type of change - [x] Bug fix (non-breaking change which fixes an issue) ## How Has This Been Tested? Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration. specs and locally To test locally: go to super admin -> settings -> captain -> Change endpoint to something incorrect go to local app -> captain -> playground -> try chatting (should fail due to incorrect endpoint) now in super admin captain settings, set the correct endpoint then chat in playground. Now it should work. Current develop code doesn't reflect the changes in installation config for captain instantly, needs a server restart. ## Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my code - [x] I have commented on my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [x] Any dependent changes have been merged and published in downstream modules
62 lines
2.2 KiB
Ruby
62 lines
2.2 KiB
Ruby
require 'rails_helper'
|
|
|
|
RSpec.describe 'Super Admin Application Config API', type: :request do
|
|
let(:super_admin) { create(:super_admin) }
|
|
|
|
describe 'GET /super_admin/app_config' do
|
|
context 'when it is an unauthenticated super admin' do
|
|
it 'returns unauthorized' do
|
|
get '/super_admin/app_config'
|
|
expect(response).to have_http_status(:redirect)
|
|
end
|
|
end
|
|
|
|
context 'when it is an authenticated super admin' do
|
|
let!(:config) { create(:installation_config, { name: 'FB_APP_ID', value: 'TESTVALUE' }) }
|
|
|
|
it 'shows the app_config page' do
|
|
sign_in(super_admin, scope: :super_admin)
|
|
get '/super_admin/app_config?config=facebook'
|
|
expect(response).to have_http_status(:success)
|
|
expect(response.body).to include(config.value)
|
|
end
|
|
end
|
|
end
|
|
|
|
describe 'POST /super_admin/app_config' do
|
|
context 'when it is an unauthenticated super admin' do
|
|
it 'returns unauthorized' do
|
|
post '/super_admin/app_config', params: { app_config: { TESTKEY: 'TESTVALUE' } }
|
|
expect(response).to have_http_status(:redirect)
|
|
end
|
|
end
|
|
|
|
context 'when it is an aunthenticated super admin' do
|
|
it 'shows the app_config page' do
|
|
sign_in(super_admin, scope: :super_admin)
|
|
post '/super_admin/app_config?config=facebook', params: { app_config: { FB_APP_ID: 'FB_APP_ID' } }
|
|
|
|
expect(response).to have_http_status(:found)
|
|
expect(response).to redirect_to(super_admin_settings_path)
|
|
expect(flash[:notice]).to be_present
|
|
expect(flash[:alert]).to be_blank
|
|
expect(flash[:success]).to be_blank
|
|
|
|
config = GlobalConfig.get('FB_APP_ID')
|
|
expect(config['FB_APP_ID']).to eq('FB_APP_ID')
|
|
end
|
|
|
|
it 'asks admins to restart web and worker processes for runtime config changes' do
|
|
sign_in(super_admin, scope: :super_admin)
|
|
post '/super_admin/app_config?config=captain', params: { app_config: { CAPTAIN_OPEN_AI_ENDPOINT: 'https://api.openai.com' } }
|
|
|
|
expect(response).to have_http_status(:found)
|
|
expect(response).to redirect_to(super_admin_settings_path)
|
|
expect(flash[:success]).to be_present
|
|
expect(flash[:alert]).to be_blank
|
|
expect(flash[:notice]).to be_blank
|
|
end
|
|
end
|
|
end
|
|
end
|