- 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.
102 lines
3.5 KiB
PHP
102 lines
3.5 KiB
PHP
<?php
|
|
|
|
use App\Models\AdminUser;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Hash;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
beforeEach(function (): void {
|
|
$this->artisan('lottery:admin-auth-sync')->assertExitCode(0);
|
|
});
|
|
|
|
test('settlement payments and adjustments index return items', function (): void {
|
|
$siteId = (int) DB::table('admin_sites')->where('is_default', true)->value('id');
|
|
$rootId = (int) DB::table('agent_nodes')->where('admin_site_id', $siteId)->where('depth', 0)->value('id');
|
|
$playerId = (int) DB::table('players')->insertGetId([
|
|
'site_code' => (string) DB::table('admin_sites')->where('id', $siteId)->value('code'),
|
|
'site_player_id' => 'lists-player',
|
|
'auth_source' => 'lottery_native',
|
|
'funding_mode' => 'credit',
|
|
'username' => 'lists_player',
|
|
'default_currency' => 'NPR',
|
|
'status' => 0,
|
|
'agent_node_id' => $rootId,
|
|
'created_at' => now(),
|
|
'updated_at' => now(),
|
|
]);
|
|
$periodId = (int) DB::table('settlement_periods')->insertGetId([
|
|
'admin_site_id' => $siteId,
|
|
'period_start' => now()->subWeek(),
|
|
'period_end' => now(),
|
|
'status' => 'closed',
|
|
'created_at' => now(),
|
|
'updated_at' => now(),
|
|
]);
|
|
|
|
$billId = (int) DB::table('settlement_bills')->insertGetId([
|
|
'settlement_period_id' => $periodId,
|
|
'bill_type' => 'player',
|
|
'owner_type' => 'player',
|
|
'owner_id' => $playerId,
|
|
'counterparty_type' => 'agent',
|
|
'counterparty_id' => $rootId,
|
|
'net_amount' => 1000,
|
|
'unpaid_amount' => 0,
|
|
'paid_amount' => 1000,
|
|
'status' => 'settled',
|
|
'created_at' => now(),
|
|
'updated_at' => now(),
|
|
]);
|
|
|
|
DB::table('payment_records')->insert([
|
|
'settlement_bill_id' => $billId,
|
|
'payer_type' => 'player',
|
|
'payer_id' => $playerId,
|
|
'payee_type' => 'agent',
|
|
'payee_id' => $rootId,
|
|
'amount' => 1000,
|
|
'method' => 'cash',
|
|
'status' => 'confirmed',
|
|
'confirmed_at' => now(),
|
|
'created_at' => now(),
|
|
'updated_at' => now(),
|
|
]);
|
|
|
|
DB::table('settlement_adjustments')->insert([
|
|
'settlement_period_id' => $periodId,
|
|
'original_bill_id' => $billId,
|
|
'adjustment_type' => 'adjustment',
|
|
'amount' => 100,
|
|
'reason' => 'test',
|
|
'created_at' => now(),
|
|
'updated_at' => now(),
|
|
]);
|
|
|
|
$admin = AdminUser::query()->create([
|
|
'username' => 'lists_super',
|
|
'name' => 'Lists',
|
|
'email' => null,
|
|
'password' => Hash::make('secret-strong'),
|
|
'status' => 0,
|
|
]);
|
|
grantSuperAdminRole($admin);
|
|
$token = $admin->createToken('test', ['*'], now()->addDay())->plainTextToken;
|
|
|
|
$this->withHeader('Authorization', 'Bearer '.$token)
|
|
->getJson('/api/v1/admin/settlement-payments?admin_site_id='.$siteId)
|
|
->assertOk()
|
|
->assertJsonPath('data.items.0.settlement_bill_id', $billId);
|
|
|
|
$this->withHeader('Authorization', 'Bearer '.$token)
|
|
->getJson('/api/v1/admin/settlement-adjustments?admin_site_id='.$siteId)
|
|
->assertOk()
|
|
->assertJsonPath('data.items.0.original_bill_id', $billId);
|
|
|
|
$this->withHeader('Authorization', 'Bearer '.$token)
|
|
->getJson('/api/v1/admin/settlement-bills?admin_site_id='.$siteId.'&bill_type=player')
|
|
->assertOk()
|
|
->assertJsonPath('data.items.0.bill_type', 'player');
|
|
});
|