This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Plan;
|
||||
use App\WorkspaceType;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* @extends Factory<Plan>
|
||||
*/
|
||||
class PlanFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* A default plan is unlimited and not purchasable, matching the most
|
||||
* permissive tier so tests can opt into limits explicitly.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'key' => fake()->unique()->slug(2),
|
||||
'name' => fake()->words(2, true),
|
||||
'workspace_type' => WorkspaceType::Personal,
|
||||
'stripe_price' => null,
|
||||
'interval' => 'month',
|
||||
'amount' => 0,
|
||||
'seat_limit' => null,
|
||||
'max_folders' => null,
|
||||
'max_folder_depth' => null,
|
||||
'max_notes_per_folder' => null,
|
||||
'note_chars' => null,
|
||||
'sort_order' => 0,
|
||||
'is_active' => true,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the plan is sold through Stripe at the given price.
|
||||
*/
|
||||
public function purchasable(?string $price = null): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'stripe_price' => $price ?? 'price_'.Str::random(12),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the plan caps the given limits.
|
||||
*/
|
||||
public function limited(int $maxFolders, int $maxFolderDepth, int $maxNotesPerFolder, int $noteChars): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'max_folders' => $maxFolders,
|
||||
'max_folder_depth' => $maxFolderDepth,
|
||||
'max_notes_per_folder' => $maxNotesPerFolder,
|
||||
'note_chars' => $noteChars,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user