51 lines
1.6 KiB
PHP
51 lines
1.6 KiB
PHP
<?php
|
|
|
|
use App\Lottery\ErrorCode;
|
|
use App\Models\Player;
|
|
use App\Models\PlayerWallet;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
test('wallet balance creates lottery wallet row and returns zeros', function () {
|
|
$player = Player::query()->create([
|
|
'site_code' => 'test',
|
|
'site_player_id' => 'p1',
|
|
'username' => null,
|
|
'nickname' => null,
|
|
'default_currency' => 'NPR',
|
|
'status' => 0,
|
|
]);
|
|
|
|
$response = $this->withHeaders([
|
|
'Authorization' => 'Bearer dev:'.$player->id,
|
|
'X-Locale' => 'zh',
|
|
])->getJson('/api/v1/wallet/balance');
|
|
|
|
$response->assertOk()
|
|
->assertJsonPath('code', ErrorCode::Success->value)
|
|
->assertJsonPath('data.balance', 0)
|
|
->assertJsonPath('data.frozen_balance', 0)
|
|
->assertJsonPath('data.currency_code', 'NPR')
|
|
->assertJsonPath('data.wallet_type', 'lottery')
|
|
->assertJsonPath('data.main_balance', null);
|
|
|
|
expect(PlayerWallet::query()->where('player_id', $player->id)->count())->toBe(1);
|
|
});
|
|
|
|
test('wallet balance rejects illegal currency query', function () {
|
|
$player = Player::query()->create([
|
|
'site_code' => 'test',
|
|
'site_player_id' => 'p2',
|
|
'username' => null,
|
|
'nickname' => null,
|
|
'default_currency' => 'NPR',
|
|
'status' => 0,
|
|
]);
|
|
|
|
$this->withHeader('Authorization', 'Bearer dev:'.$player->id)
|
|
->getJson('/api/v1/wallet/balance?currency=!!')
|
|
->assertStatus(400)
|
|
->assertJsonPath('code', ErrorCode::WalletInvalidCurrency->value);
|
|
});
|