Initial project
This commit is contained in:
52
database/factories/ConversationFactory.php
Normal file
52
database/factories/ConversationFactory.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Conversation;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<Conversation>
|
||||
*/
|
||||
class ConversationFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'created_by_id' => User::factory(),
|
||||
'type' => Conversation::TypeDirect,
|
||||
'name' => null,
|
||||
'description' => null,
|
||||
];
|
||||
}
|
||||
|
||||
public function direct(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'type' => Conversation::TypeDirect,
|
||||
'name' => null,
|
||||
'description' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
public function group(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'type' => Conversation::TypeGroup,
|
||||
'name' => fake()->randomElement([
|
||||
'Design Partners',
|
||||
'Product Launch',
|
||||
'Customer Success',
|
||||
'Engineering Standup',
|
||||
'Growth Studio',
|
||||
]),
|
||||
'description' => fake()->sentence(8),
|
||||
]);
|
||||
}
|
||||
}
|
||||
38
database/factories/ConversationParticipantFactory.php
Normal file
38
database/factories/ConversationParticipantFactory.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Conversation;
|
||||
use App\Models\ConversationParticipant;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<ConversationParticipant>
|
||||
*/
|
||||
class ConversationParticipantFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'conversation_id' => Conversation::factory(),
|
||||
'user_id' => User::factory(),
|
||||
'role' => ConversationParticipant::RoleMember,
|
||||
'joined_at' => fake()->dateTimeBetween('-2 months', 'now'),
|
||||
'last_read_at' => fake()->optional(0.85)->dateTimeBetween('-2 weeks', 'now'),
|
||||
'muted_until' => null,
|
||||
];
|
||||
}
|
||||
|
||||
public function admin(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'role' => ConversationParticipant::RoleAdmin,
|
||||
]);
|
||||
}
|
||||
}
|
||||
38
database/factories/MessageFactory.php
Normal file
38
database/factories/MessageFactory.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Conversation;
|
||||
use App\Models\Message;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<Message>
|
||||
*/
|
||||
class MessageFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'conversation_id' => Conversation::factory(),
|
||||
'user_id' => User::factory(),
|
||||
'type' => Message::TypeText,
|
||||
'body' => fake()->randomElement([
|
||||
fake()->sentence(8),
|
||||
fake()->sentence(12),
|
||||
fake()->paragraph(2),
|
||||
'I pushed a cleaner version. Can you take a look?',
|
||||
'This is ready from my side.',
|
||||
'Let me know what you think about the latest update.',
|
||||
]),
|
||||
'metadata' => null,
|
||||
'edited_at' => null,
|
||||
];
|
||||
}
|
||||
}
|
||||
60
database/factories/UserFactory.php
Normal file
60
database/factories/UserFactory.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* @extends Factory<User>
|
||||
*/
|
||||
class UserFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The current password being used by the factory.
|
||||
*/
|
||||
protected static ?string $password;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'name' => fake()->name(),
|
||||
'email' => fake()->unique()->safeEmail(),
|
||||
'email_verified_at' => now(),
|
||||
'password' => static::$password ??= Hash::make('password'),
|
||||
'remember_token' => Str::random(10),
|
||||
'two_factor_secret' => null,
|
||||
'two_factor_recovery_codes' => null,
|
||||
'two_factor_confirmed_at' => null,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the model's email address should be unverified.
|
||||
*/
|
||||
public function unverified(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'email_verified_at' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the model has two-factor authentication configured.
|
||||
*/
|
||||
public function withTwoFactor(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'two_factor_secret' => encrypt('secret'),
|
||||
'two_factor_recovery_codes' => encrypt(json_encode(['recovery-code-1'])),
|
||||
'two_factor_confirmed_at' => now(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user