优化手机输入及钓鱼

This commit is contained in:
2026-04-19 12:14:10 +08:00
parent c710d585da
commit b98ae7f94e
6 changed files with 273 additions and 41 deletions
+36
View File
@@ -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);
});
}
}