<?php

use App\Lottery\ErrorCode;
use Illuminate\Support\Facades\Route;

test('api internal exception response includes structured details in testing', function (): void {
    Route::get('/api/v1/test-error-detail', function (): void {
        throw new RuntimeException('测试异常明细');
    });

    $response = $this->getJson('/api/v1/test-error-detail');

    $response
        ->assertStatus(500)
        ->assertJsonPath('code', ErrorCode::InternalError->value)
        ->assertJsonPath('msg', '测试异常明细')
        ->assertJsonPath('data.exception', RuntimeException::class)
        ->assertJsonPath('data.message', '测试异常明细');

    expect($response->json('data.error_id'))->not->toBeEmpty()
        ->and($response->json('data.file'))->toContain('ApiExceptionResponseTest.php')
        ->and($response->json('data.line'))->toBeInt()
        ->and($response->getContent())->toContain('测试异常明细')
        ->and($response->getContent())->not->toContain('\u6d4b\u8bd5\u5f02\u5e38\u660e\u7ec6');
});
