99 lines
2.6 KiB
PHP
99 lines
2.6 KiB
PHP
<?php
|
||
|
||
namespace Tests\Feature;
|
||
|
||
use Tests\TestCase;
|
||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||
|
||
class MessageSyncTest extends TestCase
|
||
{
|
||
/**
|
||
* 测试admin框架页面是否可以访问
|
||
*/
|
||
public function test_admin_page_accessible(): void
|
||
{
|
||
$response = $this->get('/');
|
||
$response->assertStatus(200);
|
||
$response->assertViewIs('admin.index');
|
||
}
|
||
|
||
/**
|
||
* 测试查询消息API端点
|
||
*/
|
||
public function test_query_messages_api_validation(): void
|
||
{
|
||
// 测试空请求
|
||
$response = $this->postJson('/api/message-sync/query', []);
|
||
$response->assertStatus(422);
|
||
$response->assertJsonStructure([
|
||
'success',
|
||
'message',
|
||
'errors'
|
||
]);
|
||
|
||
// 测试无效的消息ID格式
|
||
$response = $this->postJson('/api/message-sync/query', [
|
||
'message_ids' => ['']
|
||
]);
|
||
$response->assertStatus(422);
|
||
$response->assertJson([
|
||
'success' => false
|
||
]);
|
||
}
|
||
|
||
/**
|
||
* 测试同步消息API端点
|
||
*/
|
||
public function test_sync_messages_api_validation(): void
|
||
{
|
||
// 测试空请求
|
||
$response = $this->postJson('/api/message-sync/sync', []);
|
||
$response->assertStatus(422);
|
||
$response->assertJsonStructure([
|
||
'success',
|
||
'message',
|
||
'errors'
|
||
]);
|
||
|
||
// 测试无效的消息ID格式
|
||
$response = $this->postJson('/api/message-sync/sync', [
|
||
'message_ids' => ['']
|
||
]);
|
||
$response->assertStatus(422);
|
||
$response->assertJson([
|
||
'success' => false
|
||
]);
|
||
}
|
||
|
||
/**
|
||
* 测试获取agent配置API端点
|
||
*/
|
||
public function test_get_agent_config_api(): void
|
||
{
|
||
$response = $this->getJson('/api/message-sync/config');
|
||
$response->assertStatus(200);
|
||
$response->assertJsonStructure([
|
||
'success',
|
||
'data' => [
|
||
'agent_url',
|
||
'timeout'
|
||
]
|
||
]);
|
||
}
|
||
|
||
/**
|
||
* 测试数据库连接测试API端点
|
||
*/
|
||
public function test_database_connection_test_api(): void
|
||
{
|
||
$response = $this->getJson('/api/message-sync/test-connection');
|
||
|
||
// 由于测试环境可能没有配置crmslave数据库,这里测试端点是否存在
|
||
// 可能返回200(连接成功)或500(连接失败),都是正常的
|
||
$this->assertContains($response->status(), [200, 500]);
|
||
$response->assertJsonStructure([
|
||
'success'
|
||
]);
|
||
}
|
||
}
|