优化游戏通知

This commit is contained in:
pllx
2026-04-30 15:41:50 +08:00
parent 4af4468fc4
commit 9764961519
8 changed files with 225 additions and 65 deletions
+49 -6
View File
@@ -1,5 +1,11 @@
<?php
/**
* 文件功能:双色球彩票前台接口测试
*
* 覆盖当前期查询、机选、购票、历史和我的购票记录。
*/
namespace Tests\Feature;
use App\Models\GameConfig;
@@ -7,12 +13,19 @@ use App\Models\LotteryIssue;
use App\Models\LotteryTicket;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Redis;
use Tests\TestCase;
/**
* 类功能:验证双色球彩票控制器的核心前台行为。
*/
class LotteryControllerTest extends TestCase
{
use RefreshDatabase;
/**
* 方法功能:初始化双色球默认配置。
*/
protected function setUp(): void
{
parent::setUp();
@@ -31,7 +44,10 @@ class LotteryControllerTest extends TestCase
);
}
public function test_can_get_current()
/**
* 方法功能:验证可以获取当前彩票期次。
*/
public function test_can_get_current(): void
{
/** @var \App\Models\User $user */
$user = User::factory()->create();
@@ -60,7 +76,10 @@ class LotteryControllerTest extends TestCase
$this->assertEquals($issue->id, $response->json('issue.id'));
}
public function test_can_quick_pick()
/**
* 方法功能:验证可以生成机选号码。
*/
public function test_can_quick_pick(): void
{
/** @var \App\Models\User $user */
$user = User::factory()->create();
@@ -72,7 +91,10 @@ class LotteryControllerTest extends TestCase
$this->assertCount(2, $response->json('numbers'));
}
public function test_cannot_buy_without_enough_gold()
/**
* 方法功能:验证金币不足时无法购票。
*/
public function test_cannot_buy_without_enough_gold(): void
{
/** @var \App\Models\User $user */
$user = User::factory()->create(['jjb' => 50]);
@@ -107,7 +129,10 @@ class LotteryControllerTest extends TestCase
$response->assertStatus(422); // Exception thrown with 422
}
public function test_can_buy_with_enough_gold()
/**
* 方法功能:验证金币充足时可以购票并广播右下角通知。
*/
public function test_can_buy_with_enough_gold(): void
{
/** @var \App\Models\User $user */
$user = User::factory()->create(['jjb' => 200]);
@@ -143,9 +168,24 @@ class LotteryControllerTest extends TestCase
$response->assertJson(['status' => 'success']);
$this->assertEquals(100, $user->fresh()->jjb); // cost is 100 per ticket
$messages = Redis::lrange('room:1:messages', 0, -1);
$publicMessage = collect($messages)
->map(fn (string $item) => json_decode($item, true))
->first(fn (array $item) => ($item['to_user'] ?? null) === '大家'
&& ($item['toast_notification']['title'] ?? null) === '🎟️ 有人购买双色球'
&& str_contains((string) ($item['toast_notification']['message'] ?? ''), $user->username));
$this->assertNotNull($publicMessage);
$this->assertFalse((bool) ($publicMessage['is_secret'] ?? true));
$this->assertStringContainsString($user->username, (string) ($publicMessage['toast_notification']['message'] ?? ''));
$this->assertSame('🎟️', $publicMessage['toast_notification']['icon'] ?? null);
}
public function test_can_get_history()
/**
* 方法功能:验证可以查询历史期次。
*/
public function test_can_get_history(): void
{
/** @var \App\Models\User $user */
$user = User::factory()->create();
@@ -173,7 +213,10 @@ class LotteryControllerTest extends TestCase
$this->assertCount(1, $response->json('issues'));
}
public function test_can_get_my_tickets()
/**
* 方法功能:验证可以查询我的购票记录。
*/
public function test_can_get_my_tickets(): void
{
/** @var \App\Models\User $user */
$user = User::factory()->create();