fedi-feed-router/database/factories/PlatformAccountFactory.php

55 lines
1.4 KiB
PHP
Raw Permalink Normal View History

2025-07-06 01:35:59 +02:00
<?php
namespace Database\Factories;
use App\Enums\AccountStatusEnum;
2025-07-06 01:35:59 +02:00
use App\Enums\PlatformEnum;
use App\Models\PlatformAccount;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends Factory<PlatformAccount>
*/
class PlatformAccountFactory extends Factory
{
protected $model = PlatformAccount::class;
public function definition(): array
{
return [
'platform' => PlatformEnum::LEMMY,
'instance_url' => 'https://lemmy.'.$this->faker->domainName(),
'username' => $this->faker->unique()->userName(),
2025-07-06 01:35:59 +02:00
'password' => 'test-password',
'settings' => [],
'is_active' => true,
'last_tested_at' => null,
'status' => AccountStatusEnum::UNTESTED,
2025-07-06 01:35:59 +02:00
];
}
public function inactive(): static
{
return $this->state(fn (array $attributes) => [
'is_active' => false,
]);
}
public function tested(): static
{
return $this->state(fn (array $attributes) => [
'last_tested_at' => now()->subHours(2),
'status' => AccountStatusEnum::HEALTHY,
2025-07-06 01:35:59 +02:00
]);
}
public function failed(): static
{
return $this->state(fn (array $attributes) => [
'last_tested_at' => now()->subHours(2),
'status' => AccountStatusEnum::UNHEALTHY,
'consecutive_failures' => PlatformAccount::FAILURES_BEFORE_UNHEALTHY,
2025-07-06 01:35:59 +02:00
]);
}
}