优化手机输入及钓鱼
This commit is contained in:
@@ -5,10 +5,12 @@ namespace Tests\Feature;
|
||||
use App\Models\Room;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Redis;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\URL;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
@@ -195,6 +197,24 @@ class ChatControllerTest extends TestCase
|
||||
Storage::disk('public')->assertExists($payload['image_thumb_path']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试聊天室发送接口在 419 场景下会返回稳定的 JSON 提示。
|
||||
*/
|
||||
public function test_chat_send_http_419_exception_renders_json_response(): void
|
||||
{
|
||||
$request = Request::create('/room/1/send', 'POST', server: [
|
||||
'HTTP_ACCEPT' => 'application/json',
|
||||
]);
|
||||
|
||||
$response = $this->app->make(\Illuminate\Contracts\Debug\ExceptionHandler::class)
|
||||
->render($request, new HttpException(419, 'Page Expired'));
|
||||
|
||||
\Illuminate\Testing\TestResponse::fromBaseResponse($response)->assertStatus(419)->assertJson([
|
||||
'status' => 'error',
|
||||
'message' => '页面已过期,请刷新后重试。',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试超过保留期的聊天图片会被命令清理并改成过期占位消息。
|
||||
*/
|
||||
|
||||
@@ -7,10 +7,12 @@
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Events\MessageSent;
|
||||
use App\Models\ShopItem;
|
||||
use App\Models\User;
|
||||
use App\Models\UserPurchase;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
@@ -214,4 +216,38 @@ class ShopControllerTest extends TestCase
|
||||
'status' => 'used',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试购买自动钓鱼卡时会以钓鱼播报身份广播,便于前端屏蔽规则命中。
|
||||
*/
|
||||
public function test_buy_auto_fishing_card_broadcasts_as_fishing_sender(): void
|
||||
{
|
||||
Event::fake([MessageSent::class]);
|
||||
|
||||
$user = User::factory()->create(['jjb' => 500]);
|
||||
|
||||
$item = ShopItem::create([
|
||||
'name' => '自动钓鱼卡(2小时)',
|
||||
'slug' => 'auto_fishing_test_2h',
|
||||
'type' => 'auto_fishing',
|
||||
'price' => 100,
|
||||
'duration_minutes' => 120,
|
||||
'is_active' => true,
|
||||
]);
|
||||
|
||||
$response = $this->actingAs($user)->postJson(route('shop.buy'), [
|
||||
'item_id' => $item->id,
|
||||
'room_id' => 1,
|
||||
]);
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson(['status' => 'success']);
|
||||
|
||||
Event::assertDispatched(MessageSent::class, function (MessageSent $event) use ($user, $item): bool {
|
||||
return $event->roomId === 1
|
||||
&& ($event->message['from_user'] ?? null) === '钓鱼播报'
|
||||
&& str_contains((string) ($event->message['content'] ?? ''), $user->username)
|
||||
&& str_contains((string) ($event->message['content'] ?? ''), $item->name);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user