89 lines
3.0 KiB
PHP
89 lines
3.0 KiB
PHP
<?php
|
|
|
|
use App\Models\PlayType;
|
|
use App\Models\AdminUser;
|
|
use App\Models\PlayConfigVersion;
|
|
use App\Lottery\ConfigVersionStatus;
|
|
use Database\Seeders\CurrencySeeder;
|
|
use Database\Seeders\PlayTypeSeeder;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use Database\Seeders\OperationalConfigV1Seeder;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
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,
|
|
]);
|
|
grantSuperAdminRole($admin);
|
|
|
|
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();
|
|
});
|