Files
lotteryLaravel/tests/Feature/AgentSettlementPeriodOpenTest.php
kang 980f3c9593 feat: enhance agent settlement features and improve data access controls
- Added new section in AGENTS.md detailing learned workspace facts for better understanding of settlement processes.
- Updated AgentNodeDestroyController to remove unnecessary checks for admin users.
- Enhanced AgentSettlement controllers to assert permissions for finance adjustments and bill operations.
- Improved query scopes in AgentSettlement services to ensure proper data access based on admin roles.
- Refactored methods in SettlementPartyEnrichment for better bill row enrichment and data handling.
- Introduced new methods in AdminAgentSettlementScope for managing agent node visibility and finance adjustments.
2026-06-12 15:59:05 +08:00

109 lines
3.9 KiB
PHP

<?php
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
uses(RefreshDatabase::class);
beforeEach(function (): void {
$this->artisan('lottery:admin-auth-sync')->assertExitCode(0);
});
test('cannot open duplicate settlement period for same range', function (): void {
$siteId = (int) DB::table('admin_sites')->where('is_default', true)->value('id');
$super = \App\Models\AdminUser::query()->create([
'username' => 'period_dup_super',
'name' => 'Super',
'email' => null,
'password' => \Illuminate\Support\Facades\Hash::make('secret-strong'),
'status' => 0,
]);
grantSuperAdminRole($super);
$token = $super->createToken('test', ['*'], now()->addDay())->plainTextToken;
$body = [
'admin_site_id' => $siteId,
'period_start' => '2026-06-01 00:00:00',
'period_end' => '2026-06-30 23:59:59',
];
$this->withHeader('Authorization', 'Bearer '.$token)
->postJson('/api/v1/admin/settlement-periods', $body)
->assertCreated();
$this->withHeader('Authorization', 'Bearer '.$token)
->postJson('/api/v1/admin/settlement-periods', $body)
->assertStatus(422)
->assertJsonPath(
'data.errors.period_start.0',
trans('validation.business.period_already_open'),
);
});
test('cannot open settlement period overlapping a closed period', function (): void {
$siteId = (int) DB::table('admin_sites')->where('is_default', true)->value('id');
$super = \App\Models\AdminUser::query()->create([
'username' => 'period_overlap_super',
'name' => 'Super',
'email' => null,
'password' => \Illuminate\Support\Facades\Hash::make('secret-strong'),
'status' => 0,
]);
grantSuperAdminRole($super);
$token = $super->createToken('test', ['*'], now()->addDay())->plainTextToken;
DB::table('settlement_periods')->insert([
'admin_site_id' => $siteId,
'period_start' => '2026-05-01 00:00:00',
'period_end' => '2026-05-31 23:59:59',
'status' => 'closed',
'created_at' => now(),
'updated_at' => now(),
]);
$this->withHeader('Authorization', 'Bearer '.$token)
->postJson('/api/v1/admin/settlement-periods', [
'admin_site_id' => $siteId,
'period_start' => '2026-05-15 00:00:00',
'period_end' => '2026-06-15 23:59:59',
])
->assertStatus(422)
->assertJsonPath(
'data.errors.period_start.0',
trans('validation.business.period_overlaps_existing'),
);
});
test('cannot open second settlement period while another is open on same site', function (): void {
$siteId = (int) DB::table('admin_sites')->where('is_default', true)->value('id');
$super = \App\Models\AdminUser::query()->create([
'username' => 'period_one_open_super',
'name' => 'Super',
'email' => null,
'password' => \Illuminate\Support\Facades\Hash::make('secret-strong'),
'status' => 0,
]);
grantSuperAdminRole($super);
$token = $super->createToken('test', ['*'], now()->addDay())->plainTextToken;
$this->withHeader('Authorization', 'Bearer '.$token)
->postJson('/api/v1/admin/settlement-periods', [
'admin_site_id' => $siteId,
'period_start' => '2026-06-01 00:00:00',
'period_end' => '2026-06-07 23:59:59',
])
->assertCreated();
$this->withHeader('Authorization', 'Bearer '.$token)
->postJson('/api/v1/admin/settlement-periods', [
'admin_site_id' => $siteId,
'period_start' => '2026-06-08 00:00:00',
'period_end' => '2026-06-14 23:59:59',
])
->assertStatus(422)
->assertJsonPath(
'data.errors.period_start.0',
trans('validation.business.period_site_has_open'),
);
});