56 lines
1.5 KiB
PHP
56 lines
1.5 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
namespace Database\Factories;
|
||
|
|
|
||
|
|
use App\Models\Reminder;
|
||
|
|
use App\Models\Tenant;
|
||
|
|
use App\Models\User;
|
||
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||
|
|
use Illuminate\Support\Carbon;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @extends Factory<Reminder>
|
||
|
|
*/
|
||
|
|
class ReminderFactory extends Factory
|
||
|
|
{
|
||
|
|
public function definition(): array
|
||
|
|
{
|
||
|
|
// remind_at +1 час по умолчанию (in future, неотправлено).
|
||
|
|
// Тесты для overdue/completed-flow явно ставят remind_at и completed_at.
|
||
|
|
$tenant = Tenant::factory();
|
||
|
|
|
||
|
|
return [
|
||
|
|
'tenant_id' => $tenant,
|
||
|
|
'deal_id' => fake()->numberBetween(1, 999999), // deal_id без FK
|
||
|
|
'text' => fake()->sentence(),
|
||
|
|
'remind_at' => Carbon::now()->addHour(),
|
||
|
|
'created_by' => User::factory()->state(fn (array $attrs, Reminder $r) => ['tenant_id' => $r->tenant_id]),
|
||
|
|
'assignee_id' => null,
|
||
|
|
'is_sent' => false,
|
||
|
|
];
|
||
|
|
}
|
||
|
|
|
||
|
|
public function overdue(): static
|
||
|
|
{
|
||
|
|
return $this->state(['remind_at' => Carbon::now()->subHours(2)]);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function completed(): static
|
||
|
|
{
|
||
|
|
return $this->state([
|
||
|
|
'completed_at' => Carbon::now()->subMinutes(10),
|
||
|
|
'remind_at' => Carbon::now()->subHour(),
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function sent(): static
|
||
|
|
{
|
||
|
|
return $this->state([
|
||
|
|
'is_sent' => true,
|
||
|
|
'sent_at' => Carbon::now()->subMinute(),
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
}
|