feat: 在 WalletBalanceController 中集成主站钱包余额获取功能
新增 HttpMainSiteWalletBalanceClient,用于在配置启用时获取主站钱包余额。 更新 WalletBalanceController:根据主站 API 返回结果新增 main_balance 与 main_balance_formatted 字段。 在 lottery.php 中新增钱包余额 API 路径配置项。 增强 WalletBalanceTest,验证在配置主站 API 后可正确获取 main_balance。
This commit is contained in:
@@ -5,11 +5,13 @@ use App\Lottery\ErrorCode;
|
||||
use App\Models\PlayerWallet;
|
||||
use Database\Seeders\CurrencySeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
beforeEach(function (): void {
|
||||
$this->seed(CurrencySeeder::class);
|
||||
config(['lottery.main_site.wallet_api_url' => null]);
|
||||
});
|
||||
|
||||
test('wallet balance creates lottery wallet row and returns zeros', function () {
|
||||
@@ -55,6 +57,38 @@ test('wallet balance rejects illegal currency query', function () {
|
||||
->assertJsonPath('code', ErrorCode::WalletInvalidCurrency->value);
|
||||
});
|
||||
|
||||
test('wallet balance returns main_balance when main site wallet api is configured', function () {
|
||||
config([
|
||||
'lottery.main_site.wallet_api_url' => 'http://fake-main.test',
|
||||
'lottery.main_site.wallet_balance_path' => '/wallet/balance',
|
||||
]);
|
||||
|
||||
Http::preventStrayRequests();
|
||||
Http::fake([
|
||||
'http://fake-main.test/wallet/balance*' => Http::response([
|
||||
'success' => true,
|
||||
'data' => [
|
||||
'main_balance' => 499_900,
|
||||
'currency_code' => 'NPR',
|
||||
],
|
||||
], 200),
|
||||
]);
|
||||
|
||||
$player = Player::query()->create([
|
||||
'site_code' => 'main-site',
|
||||
'site_player_id' => '10003',
|
||||
'username' => null,
|
||||
'nickname' => null,
|
||||
'default_currency' => 'NPR',
|
||||
'status' => 0,
|
||||
]);
|
||||
|
||||
$this->withHeader('Authorization', 'Bearer dev:'.$player->id)
|
||||
->getJson('/api/v1/wallet/balance')
|
||||
->assertOk()
|
||||
->assertJsonPath('data.main_balance', 499_900);
|
||||
});
|
||||
|
||||
test('wallet balance rejects currency that is not configured or disabled', function () {
|
||||
$player = Player::query()->create([
|
||||
'site_code' => 'test',
|
||||
|
||||
Reference in New Issue
Block a user