31f813315d
- app/Models/LeadCharge.php — fillable + casts (datetime + integer)
+ tenant() BelongsTo relation
+ deal() BelongsTo relation (по deal_id, без deal_received_at — composite PK
на партиционированной обеспечивается БД-уровнем через FK)
+ accessor priceRubles (kopecks → float)
- database/factories/LeadChargeFactory.php — НЕ создаёт реальный Deal автоматически
(composite FK requires (deal_id, deal_received_at) пары); тесты с FK-целостностью
явно создают Deal::factory() и передают пару в state()
- tests/Feature/Models/LeadChargeTest.php — 4 теста: factory, tenant relation,
deal relation, priceRubles accessor. testing_rls_user setup в beforeEach
для проверки RLS context из не-superuser контекста.
Quirk: SET LOCAL app.current_tenant_id НЕ принимает параметрическое связывание PG —
используем string interpolation с {$tenant->id} как в RlsSmokeTest pattern.
ide-helper:models -W -M -N синхронизировал docblocks (WebhookDedupKey).
Pest: 459 / 457 passed / 2 skipped (453 + 4 новых = 457).
Larastan: 0 errors. Pint passed.
Spec: §7.4
Plan: Task 8
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
34 lines
1.0 KiB
PHP
34 lines
1.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Models\LeadCharge;
|
|
use App\Models\Tenant;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
|
|
/**
|
|
* @extends Factory<LeadCharge>
|
|
*/
|
|
class LeadChargeFactory extends Factory
|
|
{
|
|
protected $model = LeadCharge::class;
|
|
|
|
public function definition(): array
|
|
{
|
|
// Factory НЕ создаёт реальный Deal автоматически — composite FK
|
|
// requires (deal_id, deal_received_at) пары; тесты, требующие FK-целостность,
|
|
// явно создают Deal::factory() и передают пару в state().
|
|
return [
|
|
'tenant_id' => Tenant::factory(),
|
|
'deal_id' => fake()->numberBetween(1, 99999),
|
|
'deal_received_at' => now(),
|
|
'tier_no' => fake()->numberBetween(1, 7),
|
|
'price_per_lead_kopecks' => fake()->numberBetween(2000, 6000),
|
|
'charged_at' => now(),
|
|
'created_at' => now(),
|
|
];
|
|
}
|
|
}
|