From 137a15f5ff607751ed3b96199e6b10d397fc2516 Mon Sep 17 00:00:00 2001 From: Doar Mihai Date: Sat, 18 Jul 2026 14:50:00 +0300 Subject: [PATCH] feat: add SocialAccount model, migration, and factory Implement SocialAccount model with enum fields for network and type, along with migration and factory. Includes NETWORKS and TYPES constants for dropdown usage in Livewire forms and validation. Co-Authored-By: Claude Sonnet 5 --- app/Models/SocialAccount.php | 26 +++++++++++++++ database/factories/SocialAccountFactory.php | 22 +++++++++++++ ...18_114858_create_social_accounts_table.php | 32 +++++++++++++++++++ tests/Feature/SocialAccountModelTest.php | 31 ++++++++++++++++++ 4 files changed, 111 insertions(+) create mode 100644 app/Models/SocialAccount.php create mode 100644 database/factories/SocialAccountFactory.php create mode 100644 database/migrations/2026_07_18_114858_create_social_accounts_table.php create mode 100644 tests/Feature/SocialAccountModelTest.php diff --git a/app/Models/SocialAccount.php b/app/Models/SocialAccount.php new file mode 100644 index 0000000..12fae87 --- /dev/null +++ b/app/Models/SocialAccount.php @@ -0,0 +1,26 @@ + fake()->randomElement(SocialAccount::NETWORKS), + 'username' => fake()->userName(), + 'email' => fake()->safeEmail(), + 'password' => fake()->password(), + 'type' => fake()->optional()->randomElement(SocialAccount::TYPES), + ]; + } +} diff --git a/database/migrations/2026_07_18_114858_create_social_accounts_table.php b/database/migrations/2026_07_18_114858_create_social_accounts_table.php new file mode 100644 index 0000000..3e5db3b --- /dev/null +++ b/database/migrations/2026_07_18_114858_create_social_accounts_table.php @@ -0,0 +1,32 @@ +id(); + $table->enum('network', [ + 'twitter', 'instagram', 'facebook', 'reddit', + 'tiktok', 'linkedin', 'youtube', 'other', + ]); + $table->string('username'); + $table->string('email'); + $table->string('password'); + $table->enum('type', ['post', 'comment', 'like'])->nullable(); + $table->timestamps(); + }); + } + + public function down(): void + { + Schema::dropIfExists('social_accounts'); + } +}; diff --git a/tests/Feature/SocialAccountModelTest.php b/tests/Feature/SocialAccountModelTest.php new file mode 100644 index 0000000..2f3bc9c --- /dev/null +++ b/tests/Feature/SocialAccountModelTest.php @@ -0,0 +1,31 @@ + 'twitter', + 'username' => 'my_handle', + 'email' => 'handle@example.com', + 'password' => 'plain-text-password', + 'type' => 'post', + ]); + + expect($account->fresh()) + ->network->toBe('twitter') + ->username->toBe('my_handle') + ->email->toBe('handle@example.com') + ->password->toBe('plain-text-password') + ->type->toBe('post'); +}); + +test('a social account can be created with a null type', function () { + $account = SocialAccount::create([ + 'network' => 'instagram', + 'username' => 'my_handle', + 'email' => 'handle@example.com', + 'password' => 'plain-text-password', + ]); + + expect($account->fresh()->type)->toBeNull(); +});