Prepare FUC-XB web support integration
This commit is contained in:
1 parent
2c92a857e8
commit
fa706edeb6
22 files changed
+1164
-2
No files matched your search
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
namespace Tests\Feature\CustomerService;
|
||||
use Tests\TestCase;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use App\Models\User;
|
||||
use App\Services\CustomerService\Settings;
|
||||
class SettingsTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
protected function beforeRefreshingDatabase(): void {
|
||||
config(['app.env'=>'testing','database.default'=>'sqlite','database.connections.sqlite.database'=>':memory:','cache.default'=>'array','cache.stores.redis'=>['driver'=>'array']]);
|
||||
DB::purge('sqlite');Cache::forgetDriver(['redis','array']);
|
||||
\Illuminate\Support\Facades\Http::preventStrayRequests();\Illuminate\Support\Facades\Queue::fake();\Illuminate\Support\Facades\Mail::fake();
|
||||
}
|
||||
protected function setUp():void{parent::setUp();$this->withoutMiddleware([\App\Http\Middleware\InitializePlugins::class,\App\Http\Middleware\RequestLog::class]);Cache::flush();
|
||||
if(!\Illuminate\Support\Facades\Schema::hasTable('v2_settings'))\Illuminate\Support\Facades\Schema::create('v2_settings',function($t){$t->id();$t->string('name')->unique();$t->text('value')->nullable();$t->timestamps();});
|
||||
app()->forgetInstance(\App\Support\Setting::class);
|
||||
}
|
||||
private function endpoint():string{return '/api/v2/'.admin_setting('secure_path',admin_setting('frontend_admin_path',hash('crc32b',config('app.key')))).'/config/customerService';}
|
||||
private function admin():void{$u=(new User)->forceFill(['id'=>1,'is_admin'=>1,'email'=>'[email protected]']);$this->actingAs($u,'sanctum');}
|
||||
public function test_public_count_is_bounded_and_disabled_service_is_zero():void{
|
||||
admin_setting(['customer_service'=>['enabled'=>true], 'customer_service_display_count'=>3]);
|
||||
$this->getJson('/customer-service/status')->assertOk()->assertExactJson(['online_count'=>3]);
|
||||
admin_setting(['customer_service_display_count'=>99]);
|
||||
$this->assertSame(3,app(Settings::class)->publicConfig()['online_count']);
|
||||
admin_setting(['customer_service'=>['enabled'=>false]]);
|
||||
$this->getJson('/customer-service/status')->assertExactJson(['online_count'=>0]);
|
||||
}
|
||||
public function test_defaults_are_off_and_theme_configuration_does_not_enable_core():void{
|
||||
admin_setting(['theme_Fuc'=>['chatwoot_base_url'=>'http://chatwoot.loc','chatwoot_website_token'=>'old']]);
|
||||
$this->assertFalse(app(Settings::class)->all()['enabled']);
|
||||
$this->assertArrayNotHasKey('telegram_bot_code',app(Settings::class)->publicConfig());
|
||||
}
|
||||
public function test_anonymous_and_non_admin_cannot_save():void{
|
||||
$this->postJson($this->endpoint(),Settings::DEFAULTS)->assertStatus(403);
|
||||
$u=(new User)->forceFill(['id'=>2,'is_admin'=>0,'email'=>'[email protected]']);$this->actingAs($u,'sanctum');
|
||||
$this->postJson($this->endpoint(),Settings::DEFAULTS)->assertStatus(403);
|
||||
}
|
||||
public function test_admin_saves_core_without_changing_theme_settings():void{
|
||||
$this->admin();admin_setting(['theme_Fuc'=>['keep'=>'unchanged']]);
|
||||
$payload=array_replace(Settings::DEFAULTS,['enabled'=>true,'base_url'=>'http://chatwoot.loc','website_token'=>'public-id','working_hours'=>'工作日9点至17点']);
|
||||
$this->postJson($this->endpoint(),$payload)->assertOk();
|
||||
$this->getJson($this->endpoint())->assertOk()->assertJsonPath('data.working_hours','工作日9点至17点');
|
||||
$this->assertSame(['keep'=>'unchanged'],admin_setting('theme_Fuc'));
|
||||
}
|
||||
public function test_unsafe_urls_and_missing_service_are_rejected():void{
|
||||
$this->admin();
|
||||
foreach ([['enabled'=>true],['base_url'=>'http://user:[email protected]'],['base_url'=>'http://chatwoot.loc/path'],['ticket_url'=>'//external.test'],['ticket_url'=>'javascript:alert(1)']] as $bad){
|
||||
$this->postJson($this->endpoint(),array_replace(Settings::DEFAULTS,$bad))->assertStatus(422);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user