优化百家乐提醒

This commit is contained in:
2026-04-14 22:09:03 +08:00
parent 392f46769c
commit a2e51f5668
3 changed files with 236 additions and 1 deletions
@@ -7,9 +7,12 @@
namespace Tests\Feature\Feature;
use App\Jobs\SaveMessageJob;
use App\Models\Room;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Queue;
use Illuminate\Support\Facades\Redis;
use Tests\TestCase;
/**
@@ -45,4 +48,54 @@ class AdminCommandControllerTest extends TestCase
]);
}
}
/**
* 测试管理操作中的奖励金币会给接收方写入带右下角提示的私聊消息。
*/
public function test_reward_gold_message_contains_toast_notification_for_receiver(): void
{
Queue::fake();
// 站长账号要求 id=1,才能走无职务限制的超管奖励路径。
$admin = User::factory()->create([
'id' => 1,
'user_level' => 100,
]);
$target = User::factory()->create([
'jjb' => 50,
]);
$room = Room::create([
'room_name' => '奖励金币房',
]);
$response = $this->actingAs($admin)->postJson(route('command.reward'), [
'username' => $target->username,
'room_id' => $room->id,
'amount' => 66,
]);
$response->assertOk()->assertJson([
'status' => 'success',
'message' => "已向 {$target->username} 发放 66 金币奖励 🎉",
]);
// 奖励金额必须真实到账,不能只有提示没有入账。
$this->assertSame(116, (int) $target->fresh()->jjb);
$messages = Redis::lrange("room:{$room->id}:messages", 0, -1);
$privateMessage = collect($messages)
->map(fn (string $item) => json_decode($item, true))
->first(fn (array $item) => ($item['from_user'] ?? null) === '系统'
&& ($item['to_user'] ?? null) === $target->username
&& str_contains((string) ($item['content'] ?? ''), '向你发放了 <b>66</b> 枚金币奖励'));
$this->assertNotNull($privateMessage);
$this->assertTrue((bool) ($privateMessage['is_secret'] ?? false));
$this->assertSame('💰 奖励金币到账', $privateMessage['toast_notification']['title'] ?? null);
$this->assertSame('💰', $privateMessage['toast_notification']['icon'] ?? null);
$this->assertSame('#f59e0b', $privateMessage['toast_notification']['color'] ?? null);
// 奖励公告和接收者私信都应进入异步落库队列。
Queue::assertPushed(SaveMessageJob::class, 2);
}
}