|
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
namespace Tests\Feature;
|
|
|
|
|
|
|
|
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
|
|
|
|
|
|
|
|
class SimpleApiTest extends TestCase
|
|
|
|
|
|
{
|
|
|
|
|
|
use RefreshDatabase;
|
|
|
|
|
|
|
|
|
|
|
|
/** @test */
|
|
|
|
|
|
public function test_gate_visits_endpoint_exists()
|
|
|
|
|
|
{
|
|
|
|
|
|
$response = $this->getJson('/api/gate/visits');
|
|
|
|
|
|
|
|
|
|
|
|
// 即使没有数据,接口也应该返回200状态码
|
|
|
|
|
|
$response->assertStatus(200);
|
|
|
|
|
|
|
|
|
|
|
|
// 验证响应结构(ApiResponse trait格式)
|
|
|
|
|
|
$data = $response->json();
|
|
|
|
|
|
$this->assertIsArray($data);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** @test */
|
|
|
|
|
|
public function test_gate_visits_detail_endpoint_exists()
|
|
|
|
|
|
{
|
|
|
|
|
|
$response = $this->getJson('/api/gate/visits/1');
|
|
|
|
|
|
|
|
|
|
|
|
// 应该返回404或200,不应该返回500
|
|
|
|
|
|
$this->assertContains($response->status(), [200, 404]);
|
|
|
|
|
|
|
|
|
|
|
|
// 验证响应结构(ApiResponse trait格式)
|
|
|
|
|
|
$data = $response->json();
|
|
|
|
|
|
$this->assertIsArray($data);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** @test */
|
|
|
|
|
|
public function test_gate_visits_update_endpoint_exists()
|
|
|
|
|
|
{
|
|
|
|
|
|
$response = $this->postJson('/api/gate/visits/1/update', [
|
|
|
|
|
|
'action' => 'enter'
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
// 应该返回200或404,不应该返回500
|
|
|
|
|
|
$this->assertContains($response->status(), [200, 404]);
|
|
|
|
|
|
|
|
|
|
|
|
// 验证响应结构(ApiResponse trait格式)
|
|
|
|
|
|
$data = $response->json();
|
|
|
|
|
|
$this->assertIsArray($data);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** @test */
|
|
|
|
|
|
public function test_admin_routes_require_authentication()
|
|
|
|
|
|
{
|
|
|
|
|
|
$response = $this->getJson('/api/admin/visits/index');
|
|
|
|
|
|
$response->assertStatus(401);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** @test */
|
|
|
|
|
|
public function test_multilingual_support()
|
|
|
|
|
|
{
|
|
|
|
|
|
// 测试中文响应
|
|
|
|
|
|
$response = $this->withHeaders(['Accept-Language' => 'zh-CN'])
|
|
|
|
|
|
->getJson('/api/gate/visits');
|
|
|
|
|
|
$response->assertStatus(200);
|
|
|
|
|
|
|
|
|
|
|
|
// 测试英文响应
|
|
|
|
|
|
$response = $this->withHeaders(['Accept-Language' => 'en'])
|
|
|
|
|
|
->getJson('/api/gate/visits');
|
|
|
|
|
|
$response->assertStatus(200);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** @test */
|
|
|
|
|
|
public function test_api_response_format()
|
|
|
|
|
|
{
|
|
|
|
|
|
$response = $this->getJson('/api/gate/visits');
|
|
|
|
|
|
|
|
|
|
|
|
$response->assertStatus(200);
|
|
|
|
|
|
|
|
|
|
|
|
$data = $response->json();
|
|
|
|
|
|
|
|
|
|
|
|
// 验证响应格式(ApiResponse trait格式)
|
|
|
|
|
|
$this->assertIsArray($data);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** @test */
|
|
|
|
|
|
public function test_route_list()
|
|
|
|
|
|
{
|
|
|
|
|
|
// 测试路由是否存在(通过访问路由来验证)
|
|
|
|
|
|
$response = $this->get('/api/gate/visits');
|
|
|
|
|
|
$this->assertNotEquals(404, $response->status());
|
|
|
|
|
|
|
|
|
|
|
|
$response = $this->get('/api/gate/visits/1');
|
|
|
|
|
|
$this->assertNotEquals(404, $response->status());
|
|
|
|
|
|
|
|
|
|
|
|
$response = $this->post('/api/gate/visits/1/update');
|
|
|
|
|
|
$this->assertNotEquals(404, $response->status());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|