feat: 添加新的错误码以支持配置版本管理,更新彩票配置以启用手动审核,增强 API 路由以支持玩法和赔率版本化管理
This commit is contained in:
87
tests/Feature/OperationalConfigApiTest.php
Normal file
87
tests/Feature/OperationalConfigApiTest.php
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
use App\Lottery\ConfigVersionStatus;
|
||||
use App\Models\AdminUser;
|
||||
use App\Models\PlayConfigVersion;
|
||||
use App\Models\PlayType;
|
||||
use Database\Seeders\CurrencySeeder;
|
||||
use Database\Seeders\OperationalConfigV1Seeder;
|
||||
use Database\Seeders\PlayTypeSeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
beforeEach(function (): void {
|
||||
$this->seed(CurrencySeeder::class);
|
||||
$this->seed(PlayTypeSeeder::class);
|
||||
$this->seed(OperationalConfigV1Seeder::class);
|
||||
});
|
||||
|
||||
function mintConfigAdminToken(): string
|
||||
{
|
||||
$admin = AdminUser::query()->create([
|
||||
'username' => 'config_admin',
|
||||
'name' => 'Config QA',
|
||||
'email' => null,
|
||||
'password' => Hash::make('secret-strong'),
|
||||
'status' => 0,
|
||||
]);
|
||||
|
||||
return $admin->createToken('test', ['*'], now()->addDay())->plainTextToken;
|
||||
}
|
||||
|
||||
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');
|
||||
|
||||
$plays = $resp->json('data.plays');
|
||||
expect($plays)->toBeArray()->not->toBeEmpty();
|
||||
expect($plays[0])->toHaveKeys(['play_code', 'config', 'odds', 'master_enabled']);
|
||||
});
|
||||
|
||||
test('admin play config draft publish flow', function (): void {
|
||||
$token = mintConfigAdminToken();
|
||||
$active = PlayConfigVersion::query()->where('status', ConfigVersionStatus::Active->value)->firstOrFail();
|
||||
|
||||
$create = $this->postJson('/api/v1/admin/config/play-versions', [
|
||||
'reason' => 'test draft',
|
||||
], ['Authorization' => 'Bearer '.$token]);
|
||||
$create->assertOk();
|
||||
$draftId = (int) $create->json('data.id');
|
||||
expect($draftId)->toBeGreaterThan(0);
|
||||
expect($create->json('data.status'))->toBe(ConfigVersionStatus::Draft->value);
|
||||
|
||||
$types = PlayType::query()->orderBy('play_code')->get();
|
||||
$itemPayload = [];
|
||||
foreach ($types as $t) {
|
||||
$itemPayload[] = [
|
||||
'play_code' => $t->play_code,
|
||||
'is_enabled' => true,
|
||||
'min_bet_amount' => 200,
|
||||
'max_bet_amount' => 400_000_000,
|
||||
'display_order' => (int) $t->sort_order,
|
||||
];
|
||||
}
|
||||
|
||||
$this->putJson(
|
||||
'/api/v1/admin/config/play-versions/'.$draftId.'/items',
|
||||
['items' => $itemPayload],
|
||||
['Authorization' => 'Bearer '.$token],
|
||||
)->assertOk()->assertJsonPath('data.items.0.min_bet_amount', 200);
|
||||
|
||||
$this->postJson(
|
||||
'/api/v1/admin/config/play-versions/'.$draftId.'/publish',
|
||||
[],
|
||||
['Authorization' => 'Bearer '.$token],
|
||||
)->assertOk()->assertJsonPath('data.status', ConfigVersionStatus::Active->value);
|
||||
|
||||
$active->refresh();
|
||||
expect($active->status)->toBe(ConfigVersionStatus::Archived->value);
|
||||
|
||||
expect(PlayConfigVersion::query()->where('status', ConfigVersionStatus::Active->value)->count())->toBe(1);
|
||||
});
|
||||
|
||||
test('admin play-types requires authentication', function (): void {
|
||||
$this->getJson('/api/v1/admin/play-types')->assertUnauthorized();
|
||||
});
|
||||
Reference in New Issue
Block a user