优化游戏通知
This commit is contained in:
@@ -27,6 +27,9 @@ class BaccaratControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* 方法功能:初始化百家乐默认配置。
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
@@ -46,7 +49,10 @@ class BaccaratControllerTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function test_can_get_current_round()
|
||||
/**
|
||||
* 方法功能:验证可以获取当前百家乐局次。
|
||||
*/
|
||||
public function test_can_get_current_round(): void
|
||||
{
|
||||
/** @var \App\Models\User $user */
|
||||
$user = User::factory()->create(['jjb' => 3456]);
|
||||
@@ -73,7 +79,10 @@ class BaccaratControllerTest extends TestCase
|
||||
$this->assertSame(3456, $response->json('jjb'));
|
||||
}
|
||||
|
||||
public function test_can_bet()
|
||||
/**
|
||||
* 方法功能:验证可以下注并给房间在线用户广播右下角通知。
|
||||
*/
|
||||
public function test_can_bet(): void
|
||||
{
|
||||
Event::fake();
|
||||
|
||||
@@ -112,9 +121,24 @@ class BaccaratControllerTest extends TestCase
|
||||
]);
|
||||
|
||||
Event::assertDispatched(\App\Events\BaccaratPoolUpdated::class);
|
||||
|
||||
$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_cannot_bet_out_of_range()
|
||||
/**
|
||||
* 方法功能:验证超出配置范围的下注会被拦截。
|
||||
*/
|
||||
public function test_cannot_bet_out_of_range(): void
|
||||
{
|
||||
/** @var \App\Models\User $user */
|
||||
$user = User::factory()->create(['jjb' => 200]);
|
||||
@@ -143,7 +167,10 @@ class BaccaratControllerTest extends TestCase
|
||||
$response->assertJson(['ok' => false]);
|
||||
}
|
||||
|
||||
public function test_cannot_bet_twice_in_same_round()
|
||||
/**
|
||||
* 方法功能:验证同一用户同一局不能重复下注。
|
||||
*/
|
||||
public function test_cannot_bet_twice_in_same_round(): void
|
||||
{
|
||||
/** @var \App\Models\User $user */
|
||||
$user = User::factory()->create(['jjb' => 200]);
|
||||
@@ -180,7 +207,10 @@ class BaccaratControllerTest extends TestCase
|
||||
$response->assertJson(['ok' => false]);
|
||||
}
|
||||
|
||||
public function test_can_get_history()
|
||||
/**
|
||||
* 方法功能:验证可以获取最近已结算百家乐历史。
|
||||
*/
|
||||
public function test_can_get_history(): void
|
||||
{
|
||||
/** @var \App\Models\User $user */
|
||||
$user = User::factory()->create();
|
||||
|
||||
@@ -60,7 +60,7 @@ class HorseRaceControllerTest extends TestCase
|
||||
/**
|
||||
* 方法功能:验证可获取当前进行中的场次。
|
||||
*/
|
||||
public function test_can_get_current_race()
|
||||
public function test_can_get_current_race(): void
|
||||
{
|
||||
/** @var \App\Models\User $user */
|
||||
$user = User::factory()->create(['jjb' => 4567]);
|
||||
@@ -214,7 +214,7 @@ class HorseRaceControllerTest extends TestCase
|
||||
/**
|
||||
* 方法功能:验证用户可以成功下注。
|
||||
*/
|
||||
public function test_can_bet()
|
||||
public function test_can_bet(): void
|
||||
{
|
||||
Event::fake();
|
||||
|
||||
@@ -249,12 +249,24 @@ class HorseRaceControllerTest extends TestCase
|
||||
'horse_id' => 1,
|
||||
'amount' => 100,
|
||||
]);
|
||||
|
||||
$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_cannot_bet_out_of_range()
|
||||
public function test_cannot_bet_out_of_range(): void
|
||||
{
|
||||
/** @var \App\Models\User $user */
|
||||
$user = User::factory()->create(['jjb' => 500]);
|
||||
@@ -284,7 +296,7 @@ class HorseRaceControllerTest extends TestCase
|
||||
/**
|
||||
* 方法功能:验证同一用户同一场只能下注一次。
|
||||
*/
|
||||
public function test_cannot_bet_twice_in_same_race()
|
||||
public function test_cannot_bet_twice_in_same_race(): void
|
||||
{
|
||||
/** @var \App\Models\User $user */
|
||||
$user = User::factory()->create(['jjb' => 500]);
|
||||
@@ -322,7 +334,7 @@ class HorseRaceControllerTest extends TestCase
|
||||
/**
|
||||
* 方法功能:验证可读取最近的赛马历史记录。
|
||||
*/
|
||||
public function test_can_get_history()
|
||||
public function test_can_get_history(): void
|
||||
{
|
||||
/** @var \App\Models\User $user */
|
||||
$user = User::factory()->create();
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user