fix: 增强配置发布校验与关闭玩法清理提示
1. 发布赔率、玩法配置和风控封顶草稿前校验空配置、重复项、金额范围和合法性 2. 限制赔率返水与佣金比例在 0 到 1 之间 3. 投注预览和下单遇到已关闭玩法时返回需清理注项明细
This commit is contained in:
@@ -9,6 +9,7 @@ use App\Lottery\ConfigVersionStatus;
|
||||
use App\Lottery\ErrorCode;
|
||||
use Database\Seeders\CurrencySeeder;
|
||||
use Database\Seeders\PlayTypeSeeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Database\Seeders\OperationalConfigV1Seeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
@@ -35,6 +36,19 @@ function mintConfigAdminToken(): string
|
||||
return $admin->createToken('test', ['*'], now()->addDay())->plainTextToken;
|
||||
}
|
||||
|
||||
function oddsPutPayloadFromDetail(array $items): array
|
||||
{
|
||||
return collect($items)->map(fn (array $r) => [
|
||||
'play_code' => $r['play_code'],
|
||||
'prize_scope' => $r['prize_scope'],
|
||||
'odds_value' => (int) $r['odds_value'],
|
||||
'rebate_rate' => (float) $r['rebate_rate'],
|
||||
'commission_rate' => (float) $r['commission_rate'],
|
||||
'currency_code' => $r['currency_code'],
|
||||
'extra_config_json' => $r['extra_config_json'] ?? null,
|
||||
])->all();
|
||||
}
|
||||
|
||||
test('play effective catalog is public and merged', function (): void {
|
||||
$resp = $this->getJson('/api/v1/play/effective?currency=NPR');
|
||||
$resp->assertOk()->assertJsonPath('data.currency_code', 'NPR');
|
||||
@@ -86,6 +100,23 @@ test('admin play config draft publish flow', function (): void {
|
||||
expect(PlayConfigVersion::query()->where('status', ConfigVersionStatus::Active->value)->count())->toBe(1);
|
||||
});
|
||||
|
||||
test('admin play config publish rejects empty draft items', function (): void {
|
||||
$token = mintConfigAdminToken();
|
||||
$create = $this->postJson('/api/v1/admin/config/play-versions', [
|
||||
'reason' => 'empty draft',
|
||||
], ['Authorization' => 'Bearer '.$token]);
|
||||
$create->assertOk();
|
||||
$draftId = (int) $create->json('data.id');
|
||||
|
||||
DB::table('play_config_items')->where('version_id', $draftId)->delete();
|
||||
|
||||
$this->postJson(
|
||||
'/api/v1/admin/config/play-versions/'.$draftId.'/publish',
|
||||
[],
|
||||
['Authorization' => 'Bearer '.$token],
|
||||
)->assertStatus(422);
|
||||
});
|
||||
|
||||
test('admin play-types requires authentication', function (): void {
|
||||
$this->getJson('/api/v1/admin/play-types')->assertUnauthorized();
|
||||
});
|
||||
@@ -151,3 +182,24 @@ test('admin can delete draft risk cap version', function (): void {
|
||||
|
||||
expect(RiskCapVersion::query()->whereKey($draftId)->exists())->toBeFalse();
|
||||
});
|
||||
|
||||
test('admin odds config rejects out of range rebate rate', function (): void {
|
||||
$token = mintConfigAdminToken();
|
||||
$create = $this->postJson('/api/v1/admin/config/odds-versions', [
|
||||
'reason' => 'rate bound',
|
||||
], ['Authorization' => 'Bearer '.$token]);
|
||||
$create->assertOk();
|
||||
$draftId = (int) $create->json('data.id');
|
||||
|
||||
$detail = $this->getJson('/api/v1/admin/config/odds-versions/'.$draftId, [
|
||||
'Authorization' => 'Bearer '.$token,
|
||||
])->assertOk()->json('data.items');
|
||||
$payload = oddsPutPayloadFromDetail($detail);
|
||||
$payload[0]['rebate_rate'] = 1.2;
|
||||
|
||||
$this->putJson(
|
||||
'/api/v1/admin/config/odds-versions/'.$draftId.'/items',
|
||||
['items' => $payload],
|
||||
['Authorization' => 'Bearer '.$token],
|
||||
)->assertStatus(422);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user