diff --git a/.claude/settings.local.json b/.claude/settings.local.json index d634785..e1a391b 100644 --- a/.claude/settings.local.json +++ b/.claude/settings.local.json @@ -19,7 +19,8 @@ "Bash(vendor/bin/pest tests/Feature/Filament/ResourcesTest.php --filter=\"it_displays_tickets_in_table\" --no-coverage)", "Bash(vendor/bin/pest tests/Feature/Filament/ResourcesTest.php --filter=\"it_can_search_tickets_by_subject\" --no-coverage)", "Bash(vendor/bin/pest tests/Feature/Filament/ResourcesTest.php --filter=\"it_can_create_new_plan\" --no-coverage)", - "Bash(vendor/bin/pest tests/Feature/Filament/ResourcesTest.php --filter=\"it_can_create_new_category\" --no-coverage)" + "Bash(vendor/bin/pest tests/Feature/Filament/ResourcesTest.php --filter=\"it_can_create_new_category\" --no-coverage)", + "Bash(vendor/bin/pest tests/Unit/Models/RemoteEmailTest.php --no-coverage)" ], "deny": [], "ask": [] diff --git a/app/Models/Meta.php b/app/Models/Meta.php index b94ae15..0557aed 100644 --- a/app/Models/Meta.php +++ b/app/Models/Meta.php @@ -8,6 +8,11 @@ use Illuminate\Database\Eloquent\Model; class Meta extends Model { use HasFactory; + protected $fillable = [ + 'key', + 'value', + ]; + public function incrementMeta($value = 1) { $this->value = $this->value + $value; $this->save(); diff --git a/app/Models/RemoteEmail.php b/app/Models/RemoteEmail.php index 7b07900..1be7530 100644 --- a/app/Models/RemoteEmail.php +++ b/app/Models/RemoteEmail.php @@ -2,14 +2,43 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\Validator; class RemoteEmail extends Model { - protected $connection = 'mysql_remote'; + use HasFactory; protected $table = 'emails'; + public function getConnectionName() + { + if (app()->environment('testing')) { + return config('database.default'); + } + + return 'mysql_remote'; + } + + + protected $fillable = [ + 'message_id', + 'subject', + 'from_name', + 'from_email', + 'to', + 'body_html', + 'body_text', + 'is_seen', + 'timestamp', + ]; + + protected $casts = [ + 'to' => 'array', + 'is_seen' => 'boolean', + 'timestamp' => 'datetime', + ]; + public static function fetchEmailFromDB($email) { $validator = Validator::make(['email' => $email], [ diff --git a/composer.lock b/composer.lock index ca5ce0f..10fff5d 100644 --- a/composer.lock +++ b/composer.lock @@ -2038,16 +2038,16 @@ }, { "name": "kirschbaum-development/eloquent-power-joins", - "version": "4.2.9", + "version": "4.2.10", "source": { "type": "git", "url": "https://github.com/kirschbaum-development/eloquent-power-joins.git", - "reference": "32ec75ffee5f8f66e2c95e4030fa0b2454e51048" + "reference": "ccda351a75701f5b0a6f94586d9a40f1114302b4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/kirschbaum-development/eloquent-power-joins/zipball/32ec75ffee5f8f66e2c95e4030fa0b2454e51048", - "reference": "32ec75ffee5f8f66e2c95e4030fa0b2454e51048", + "url": "https://api.github.com/repos/kirschbaum-development/eloquent-power-joins/zipball/ccda351a75701f5b0a6f94586d9a40f1114302b4", + "reference": "ccda351a75701f5b0a6f94586d9a40f1114302b4", "shasum": "" }, "require": { @@ -2095,9 +2095,9 @@ ], "support": { "issues": "https://github.com/kirschbaum-development/eloquent-power-joins/issues", - "source": "https://github.com/kirschbaum-development/eloquent-power-joins/tree/4.2.9" + "source": "https://github.com/kirschbaum-development/eloquent-power-joins/tree/4.2.10" }, - "time": "2025-10-25T11:39:00+00:00" + "time": "2025-11-13T14:57:49+00:00" }, { "name": "laravel/cashier", @@ -2189,16 +2189,16 @@ }, { "name": "laravel/framework", - "version": "v12.37.0", + "version": "v12.38.1", "source": { "type": "git", "url": "https://github.com/laravel/framework.git", - "reference": "3c3c4ad30f5b528b164a7c09aa4ad03118c4c125" + "reference": "7f3012af6059f5f64a12930701cd8caed6cf7c17" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/framework/zipball/3c3c4ad30f5b528b164a7c09aa4ad03118c4c125", - "reference": "3c3c4ad30f5b528b164a7c09aa4ad03118c4c125", + "url": "https://api.github.com/repos/laravel/framework/zipball/7f3012af6059f5f64a12930701cd8caed6cf7c17", + "reference": "7f3012af6059f5f64a12930701cd8caed6cf7c17", "shasum": "" }, "require": { @@ -2316,7 +2316,7 @@ "phpstan/phpstan": "^2.0", "phpunit/phpunit": "^10.5.35|^11.5.3|^12.0.1", "predis/predis": "^2.3|^3.0", - "resend/resend-php": "^0.10.0", + "resend/resend-php": "^0.10.0|^1.0", "symfony/cache": "^7.2.0", "symfony/http-client": "^7.2.0", "symfony/psr-http-message-bridge": "^7.2.0", @@ -2350,7 +2350,7 @@ "predis/predis": "Required to use the predis connector (^2.3|^3.0).", "psr/http-message": "Required to allow Storage::put to accept a StreamInterface (^1.0).", "pusher/pusher-php-server": "Required to use the Pusher broadcast driver (^6.0|^7.0).", - "resend/resend-php": "Required to enable support for the Resend mail transport (^0.10.0).", + "resend/resend-php": "Required to enable support for the Resend mail transport (^0.10.0|^1.0).", "symfony/cache": "Required to PSR-6 cache bridge (^7.2).", "symfony/filesystem": "Required to enable support for relative symbolic links (^7.2).", "symfony/http-client": "Required to enable support for the Symfony API mail transports (^7.2).", @@ -2404,7 +2404,7 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2025-11-04T15:39:33+00:00" + "time": "2025-11-13T02:12:47+00:00" }, { "name": "laravel/prompts", @@ -2938,16 +2938,16 @@ }, { "name": "league/flysystem", - "version": "3.30.1", + "version": "3.30.2", "source": { "type": "git", "url": "https://github.com/thephpleague/flysystem.git", - "reference": "c139fd65c1f796b926f4aec0df37f6caa959a8da" + "reference": "5966a8ba23e62bdb518dd9e0e665c2dbd4b5b277" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/thephpleague/flysystem/zipball/c139fd65c1f796b926f4aec0df37f6caa959a8da", - "reference": "c139fd65c1f796b926f4aec0df37f6caa959a8da", + "url": "https://api.github.com/repos/thephpleague/flysystem/zipball/5966a8ba23e62bdb518dd9e0e665c2dbd4b5b277", + "reference": "5966a8ba23e62bdb518dd9e0e665c2dbd4b5b277", "shasum": "" }, "require": { @@ -3015,22 +3015,22 @@ ], "support": { "issues": "https://github.com/thephpleague/flysystem/issues", - "source": "https://github.com/thephpleague/flysystem/tree/3.30.1" + "source": "https://github.com/thephpleague/flysystem/tree/3.30.2" }, - "time": "2025-10-20T15:35:26+00:00" + "time": "2025-11-10T17:13:11+00:00" }, { "name": "league/flysystem-local", - "version": "3.30.0", + "version": "3.30.2", "source": { "type": "git", "url": "https://github.com/thephpleague/flysystem-local.git", - "reference": "6691915f77c7fb69adfb87dcd550052dc184ee10" + "reference": "ab4f9d0d672f601b102936aa728801dd1a11968d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/thephpleague/flysystem-local/zipball/6691915f77c7fb69adfb87dcd550052dc184ee10", - "reference": "6691915f77c7fb69adfb87dcd550052dc184ee10", + "url": "https://api.github.com/repos/thephpleague/flysystem-local/zipball/ab4f9d0d672f601b102936aa728801dd1a11968d", + "reference": "ab4f9d0d672f601b102936aa728801dd1a11968d", "shasum": "" }, "require": { @@ -3064,9 +3064,9 @@ "local" ], "support": { - "source": "https://github.com/thephpleague/flysystem-local/tree/3.30.0" + "source": "https://github.com/thephpleague/flysystem-local/tree/3.30.2" }, - "time": "2025-05-21T10:34:19+00:00" + "time": "2025-11-10T11:23:37+00:00" }, { "name": "league/mime-type-detection", @@ -6094,16 +6094,16 @@ }, { "name": "symfony/http-foundation", - "version": "v7.3.6", + "version": "v7.3.7", "source": { "type": "git", "url": "https://github.com/symfony/http-foundation.git", - "reference": "6379e490d6ecfc5c4224ff3a754b90495ecd135c" + "reference": "db488a62f98f7a81d5746f05eea63a74e55bb7c4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-foundation/zipball/6379e490d6ecfc5c4224ff3a754b90495ecd135c", - "reference": "6379e490d6ecfc5c4224ff3a754b90495ecd135c", + "url": "https://api.github.com/repos/symfony/http-foundation/zipball/db488a62f98f7a81d5746f05eea63a74e55bb7c4", + "reference": "db488a62f98f7a81d5746f05eea63a74e55bb7c4", "shasum": "" }, "require": { @@ -6153,7 +6153,7 @@ "description": "Defines an object-oriented layer for the HTTP specification", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/http-foundation/tree/v7.3.6" + "source": "https://github.com/symfony/http-foundation/tree/v7.3.7" }, "funding": [ { @@ -6173,20 +6173,20 @@ "type": "tidelift" } ], - "time": "2025-11-06T11:05:57+00:00" + "time": "2025-11-08T16:41:12+00:00" }, { "name": "symfony/http-kernel", - "version": "v7.3.6", + "version": "v7.3.7", "source": { "type": "git", "url": "https://github.com/symfony/http-kernel.git", - "reference": "f9a34dc0196677250e3609c2fac9de9e1551a262" + "reference": "10b8e9b748ea95fa4539c208e2487c435d3c87ce" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-kernel/zipball/f9a34dc0196677250e3609c2fac9de9e1551a262", - "reference": "f9a34dc0196677250e3609c2fac9de9e1551a262", + "url": "https://api.github.com/repos/symfony/http-kernel/zipball/10b8e9b748ea95fa4539c208e2487c435d3c87ce", + "reference": "10b8e9b748ea95fa4539c208e2487c435d3c87ce", "shasum": "" }, "require": { @@ -6271,7 +6271,7 @@ "description": "Provides a structured process for converting a Request into a Response", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/http-kernel/tree/v7.3.6" + "source": "https://github.com/symfony/http-kernel/tree/v7.3.7" }, "funding": [ { @@ -6291,7 +6291,7 @@ "type": "tidelift" } ], - "time": "2025-11-06T20:58:12+00:00" + "time": "2025-11-12T11:38:40+00:00" }, { "name": "symfony/mailer", @@ -8753,16 +8753,16 @@ }, { "name": "laravel/boost", - "version": "v1.7.1", + "version": "v1.8.0", "source": { "type": "git", "url": "https://github.com/laravel/boost.git", - "reference": "355f7c27952862aab3f61adec27773fd4d41a582" + "reference": "3475be16be7552b11c57ce18a0c5e204d696da50" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/boost/zipball/355f7c27952862aab3f61adec27773fd4d41a582", - "reference": "355f7c27952862aab3f61adec27773fd4d41a582", + "url": "https://api.github.com/repos/laravel/boost/zipball/3475be16be7552b11c57ce18a0c5e204d696da50", + "reference": "3475be16be7552b11c57ce18a0c5e204d696da50", "shasum": "" }, "require": { @@ -8815,20 +8815,20 @@ "issues": "https://github.com/laravel/boost/issues", "source": "https://github.com/laravel/boost" }, - "time": "2025-11-05T21:41:46+00:00" + "time": "2025-11-11T14:15:11+00:00" }, { "name": "laravel/mcp", - "version": "v0.3.2", + "version": "v0.3.3", "source": { "type": "git", "url": "https://github.com/laravel/mcp.git", - "reference": "dc722a4c388f172365dec70461f0413ac366f360" + "reference": "feb475f819809e7db0a46e9f2cbcee6d77af2a14" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/mcp/zipball/dc722a4c388f172365dec70461f0413ac366f360", - "reference": "dc722a4c388f172365dec70461f0413ac366f360", + "url": "https://api.github.com/repos/laravel/mcp/zipball/feb475f819809e7db0a46e9f2cbcee6d77af2a14", + "reference": "feb475f819809e7db0a46e9f2cbcee6d77af2a14", "shasum": "" }, "require": { @@ -8888,7 +8888,7 @@ "issues": "https://github.com/laravel/mcp/issues", "source": "https://github.com/laravel/mcp" }, - "time": "2025-10-29T14:26:01+00:00" + "time": "2025-11-11T22:50:25+00:00" }, { "name": "laravel/pail", @@ -9098,16 +9098,16 @@ }, { "name": "laravel/sail", - "version": "v1.47.0", + "version": "v1.48.0", "source": { "type": "git", "url": "https://github.com/laravel/sail.git", - "reference": "9a11e822238167ad8b791e4ea51155d25cf4d8f2" + "reference": "1bf3b8870b72a258a3b6b5119435835ece522e8a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/sail/zipball/9a11e822238167ad8b791e4ea51155d25cf4d8f2", - "reference": "9a11e822238167ad8b791e4ea51155d25cf4d8f2", + "url": "https://api.github.com/repos/laravel/sail/zipball/1bf3b8870b72a258a3b6b5119435835ece522e8a", + "reference": "1bf3b8870b72a258a3b6b5119435835ece522e8a", "shasum": "" }, "require": { @@ -9157,7 +9157,7 @@ "issues": "https://github.com/laravel/sail/issues", "source": "https://github.com/laravel/sail" }, - "time": "2025-10-28T13:55:29+00:00" + "time": "2025-11-09T14:46:21+00:00" }, { "name": "mockery/mockery", diff --git a/database/factories/MetaFactory.php b/database/factories/MetaFactory.php new file mode 100644 index 0000000..af6ba1a --- /dev/null +++ b/database/factories/MetaFactory.php @@ -0,0 +1,19 @@ + $this->faker->word(), + 'value' => $this->faker->word(), + ]; + } +} \ No newline at end of file diff --git a/database/factories/RemoteEmailFactory.php b/database/factories/RemoteEmailFactory.php new file mode 100644 index 0000000..7c9df7e --- /dev/null +++ b/database/factories/RemoteEmailFactory.php @@ -0,0 +1,26 @@ + $this->faker->uuid(), + 'subject' => $this->faker->sentence(), + 'from_name' => $this->faker->name(), + 'from_email' => $this->faker->email(), + 'to' => [$this->faker->email()], + 'body_html' => '

' . $this->faker->paragraph() . '

', + 'body_text' => $this->faker->paragraph(), + 'is_seen' => $this->faker->boolean(), + 'timestamp' => $this->faker->dateTime(), + ]; + } +} \ No newline at end of file diff --git a/tests/Feature/ApplicationTest.php b/tests/Feature/ApplicationTest.php index 1b79ad1..00a3567 100644 --- a/tests/Feature/ApplicationTest.php +++ b/tests/Feature/ApplicationTest.php @@ -1,5 +1,7 @@ toBeTrue(); }); diff --git a/tests/Unit/Models/ActivationKeyTest.php b/tests/Unit/Models/ActivationKeyTest.php new file mode 100644 index 0000000..d9ad3a5 --- /dev/null +++ b/tests/Unit/Models/ActivationKeyTest.php @@ -0,0 +1,75 @@ +user = User::factory()->create(); + } + + /** @test */ + public function it_can_create_an_activation_key_with_factory() + { + $activationKey = ActivationKey::factory()->create(); + + $this->assertInstanceOf(ActivationKey::class, $activationKey); + $this->assertIsString($activationKey->activation_key); + $this->assertIsInt($activationKey->price_id); + } + + /** @test */ + public function it_has_correct_fillable_attributes() + { + $activationKeyData = [ + 'user_id' => $this->user->id, + 'activation_key' => 'ACTIVATION-KEY-123456', + 'price_id' => 1, + 'is_activated' => false, + ]; + + $activationKey = ActivationKey::create($activationKeyData); + + foreach ($activationKeyData as $key => $value) { + $this->assertEquals($value, $activationKey->$key); + } + } + + /** @test */ + public function it_belongs_to_a_user() + { + $activationKey = ActivationKey::factory()->create(['user_id' => $this->user->id]); + + $this->assertInstanceOf(User::class, $activationKey->user); + $this->assertEquals($this->user->id, $activationKey->user->id); + } + + /** @test */ + public function it_generates_unique_keys() + { + $key1 = ActivationKey::factory()->create(); + $key2 = ActivationKey::factory()->create(); + + $this->assertNotEquals($key1->activation_key, $key2->activation_key); + } + + /** @test */ + public function it_can_query_unactivated_activation_keys() + { + $unactivatedKey = ActivationKey::factory()->create(['is_activated' => false]); + $activatedKey = ActivationKey::factory()->create(['is_activated' => true]); + + $unactivatedKeys = ActivationKey::where('is_activated', false)->get(); + $activatedKeys = ActivationKey::where('is_activated', true)->get(); + + $this->assertCount(1, $unactivatedKeys); + $this->assertCount(1, $activatedKeys); + } +} \ No newline at end of file diff --git a/tests/Unit/Models/BlogTest.php b/tests/Unit/Models/BlogTest.php index 330fb81..a625b45 100644 --- a/tests/Unit/Models/BlogTest.php +++ b/tests/Unit/Models/BlogTest.php @@ -1,5 +1,7 @@ user = User::factory()->create(); + } + + /** @test */ + public function it_can_create_a_log_with_factory() + { + $log = Log::factory()->create(); + + $this->assertInstanceOf(Log::class, $log); + $this->assertIsString($log->email); + $this->assertIsString($log->ip); + } + + /** @test */ + public function it_has_correct_fillable_attributes() + { + $logData = [ + 'user_id' => $this->user->id, + 'email' => 'test@example.com', + 'ip' => '192.168.1.1', + ]; + + $log = Log::create($logData); + + foreach ($logData as $key => $value) { + $this->assertEquals($value, $log->$key); + } + } + + /** @test */ + public function it_belongs_to_a_user() + { + $log = Log::factory()->create(['user_id' => $this->user->id]); + + $this->assertInstanceOf(User::class, $log->user); + $this->assertEquals($this->user->id, $log->user->id); + } + + /** @test */ + public function it_stores_ip_addresses_correctly() + { + $ipAddresses = ['127.0.0.1', '192.168.1.100', '10.0.0.1']; + + foreach ($ipAddresses as $ip) { + $log = Log::factory()->create(['ip' => $ip]); + $this->assertEquals($ip, $log->ip); + } + } + + /** @test */ + public function it_orders_logs_by_creation_date() + { + $oldLog = Log::factory()->create(['created_at' => now()->subHours(2)]); + $newLog = Log::factory()->create(['created_at' => now()]); + + $logs = Log::orderBy('created_at', 'desc')->get(); + + $this->assertEquals($newLog->id, $logs->first()->id); + $this->assertEquals($oldLog->id, $logs->last()->id); + } +} \ No newline at end of file diff --git a/tests/Unit/Models/MenuTest.php b/tests/Unit/Models/MenuTest.php new file mode 100644 index 0000000..e521217 --- /dev/null +++ b/tests/Unit/Models/MenuTest.php @@ -0,0 +1,59 @@ +create(); + + $this->assertInstanceOf(Menu::class, $menu); + $this->assertIsString($menu->name); + $this->assertIsString($menu->url); + } + + /** @test */ + public function it_has_correct_fillable_attributes() + { + $menuData = [ + 'name' => 'Home', + 'url' => '/home', + 'new_tab' => false, + 'parent' => null, + ]; + + $menu = Menu::create($menuData); + + foreach ($menuData as $key => $value) { + $this->assertEquals($value, $menu->$key); + } + } + + /** @test */ + public function it_orders_menus_by_name() + { + $menu1 = Menu::factory()->create(['name' => 'Zebra']); + $menu2 = Menu::factory()->create(['name' => 'Alpha']); + $menu3 = Menu::factory()->create(['name' => 'Beta']); + + $menus = Menu::orderBy('name')->get(); + + $this->assertEquals($menu2->id, $menus[0]->id); + $this->assertEquals($menu3->id, $menus[1]->id); + $this->assertEquals($menu1->id, $menus[2]->id); + } + + /** @test */ + public function it_can_handle_parent_child_relationships() + { + $parentMenu = Menu::factory()->create(['parent' => null]); + $childMenu = Menu::factory()->create(['parent' => 'home']); + + $this->assertEquals('home', $childMenu->parent); + } +} \ No newline at end of file diff --git a/tests/Unit/Models/MessageTest.php b/tests/Unit/Models/MessageTest.php new file mode 100644 index 0000000..ee42b44 --- /dev/null +++ b/tests/Unit/Models/MessageTest.php @@ -0,0 +1,71 @@ +create(); + + $this->assertInstanceOf(Message::class, $message); + $this->assertIsString($message->subject); + $this->assertIsString($message->from); + } + + /** @test */ + public function it_has_correct_fillable_attributes() + { + $messageData = [ + 'subject' => 'Test Message', + 'from' => 'Test Sender ', + 'to' => 'recipient@example.com', + 'body' => 'Test body content', + 'attachments' => null, + 'is_seen' => false, + ]; + + $message = Message::create($messageData); + + foreach ($messageData as $key => $value) { + $this->assertEquals($value, $message->$key); + } + } + + /** @test */ + public function it_stores_to_field_as_string() + { + $to = 'test1@example.com'; + $message = Message::factory()->create(['to' => $to]); + + $this->assertIsString($message->to); + $this->assertEquals($to, $message->to); + } + + /** @test */ + public function it_uses_created_at_as_timestamp() + { + $message = Message::factory()->create(); + + $this->assertInstanceOf(Carbon::class, $message->created_at); + $this->assertNotNull($message->created_at); + } + + /** @test */ + public function it_can_query_unseen_messages() + { + $unseenMessage = Message::factory()->create(['is_seen' => false]); + $seenMessage = Message::factory()->create(['is_seen' => true]); + + $unseenMessages = Message::where('is_seen', false)->get(); + $seenMessages = Message::where('is_seen', true)->get(); + + $this->assertCount(1, $unseenMessages); + $this->assertCount(1, $seenMessages); + } +} \ No newline at end of file diff --git a/tests/Unit/Models/MetaTest.php b/tests/Unit/Models/MetaTest.php new file mode 100644 index 0000000..4a78bc0 --- /dev/null +++ b/tests/Unit/Models/MetaTest.php @@ -0,0 +1,59 @@ +create(); + + $this->assertInstanceOf(Meta::class, $meta); + $this->assertIsString($meta->key); + $this->assertIsString($meta->value); + } + + /** @test */ + public function it_has_correct_fillable_attributes() + { + $metaData = [ + 'key' => 'total_emails_created', + 'value' => '1500', + ]; + + $meta = Meta::create($metaData); + + foreach ($metaData as $key => $value) { + $this->assertEquals($value, $meta->$key); + } + } + + /** @test */ + public function it_stores_key_value_pairs_correctly() + { + $meta = Meta::factory()->create([ + 'key' => 'app_version', + 'value' => '1.2.3', + ]); + + $this->assertEquals('app_version', $meta->key); + $this->assertEquals('1.2.3', $meta->value); + } + + /** @test */ + public function it_can_retrieve_value_by_key() + { + Meta::factory()->create(['key' => 'site_name', 'value' => 'ZEmailnator']); + Meta::factory()->create(['key' => 'max_emails', 'value' => '100']); + + $siteName = Meta::where('key', 'site_name')->first(); + $maxEmails = Meta::where('key', 'max_emails')->first(); + + $this->assertEquals('ZEmailnator', $siteName->value); + $this->assertEquals('100', $maxEmails->value); + } +} \ No newline at end of file diff --git a/tests/Unit/Models/PageTest.php b/tests/Unit/Models/PageTest.php new file mode 100644 index 0000000..6314121 --- /dev/null +++ b/tests/Unit/Models/PageTest.php @@ -0,0 +1,62 @@ +create(); + + $this->assertInstanceOf(Page::class, $page); + $this->assertIsString($page->title); + $this->assertIsString($page->slug); + } + + /** @test */ + public function it_has_correct_fillable_attributes() + { + $pageData = [ + 'title' => 'About Us', + 'slug' => 'about-us', + 'content' => 'About us page content', + 'meta' => [ + 'description' => 'About us meta description', + 'keywords' => 'about,company', + ], + 'is_published' => true, + ]; + + $page = Page::create($pageData); + + foreach ($pageData as $key => $value) { + $this->assertEquals($value, $page->$key); + } + } + + /** @test */ + public function it_generates_unique_slugs() + { + $page1 = Page::factory()->create(['title' => 'Same Title']); + $page2 = Page::factory()->create(['title' => 'Same Title']); + + $this->assertNotEquals($page1->slug, $page2->slug); + } + + /** @test */ + public function it_can_query_published_pages() + { + $publishedPage = Page::factory()->create(['is_published' => true]); + $draftPage = Page::factory()->create(['is_published' => false]); + + $publishedPages = Page::where('is_published', true)->get(); + $draftPages = Page::where('is_published', false)->get(); + + $this->assertCount(1, $publishedPages); + $this->assertCount(1, $draftPages); + } +} \ No newline at end of file diff --git a/tests/Unit/Models/PlanTest.php b/tests/Unit/Models/PlanTest.php index 1ba82c5..48d6800 100644 --- a/tests/Unit/Models/PlanTest.php +++ b/tests/Unit/Models/PlanTest.php @@ -1,5 +1,7 @@ user = User::factory()->create(); + } + + /** @test */ + public function it_can_create_a_premium_email_with_factory() + { + $premiumEmail = PremiumEmail::factory()->create(); + + $this->assertInstanceOf(PremiumEmail::class, $premiumEmail); + $this->assertIsString($premiumEmail->from_email); + $this->assertIsString($premiumEmail->subject); + } + + /** @test */ + public function it_has_correct_fillable_attributes() + { + $premiumEmailData = [ + 'user_id' => $this->user->id, + 'message_id' => 'test_msg_123', + 'from_email' => 'sender@example.com', + 'from_name' => 'Test Sender', + 'subject' => 'Test Subject', + 'to' => ['recipient@example.com'], + ]; + + $premiumEmail = PremiumEmail::create($premiumEmailData); + + foreach ($premiumEmailData as $key => $value) { + $this->assertEquals($value, $premiumEmail->$key); + } + } + + /** @test */ + public function it_belongs_to_a_user() + { + $premiumEmail = PremiumEmail::factory()->create(['user_id' => $this->user->id]); + + $this->assertInstanceOf(User::class, $premiumEmail->user); + $this->assertEquals($this->user->id, $premiumEmail->user->id); + } + + /** @test */ + public function it_casts_timestamp_to_datetime() + { + $timestamp = now()->subDays(5); + $premiumEmail = PremiumEmail::factory()->create(['timestamp' => $timestamp]); + + $this->assertInstanceOf(Carbon::class, $premiumEmail->timestamp); + $this->assertEquals($timestamp->format('Y-m-d H:i:s'), $premiumEmail->timestamp->format('Y-m-d H:i:s')); + } + + /** @test */ + public function it_can_query_seen_and_unseen_emails() + { + $seenEmail = PremiumEmail::factory()->create(['is_seen' => true]); + $unseenEmail = PremiumEmail::factory()->create(['is_seen' => false]); + + $seenEmails = PremiumEmail::where('is_seen', true)->get(); + $unseenEmails = PremiumEmail::where('is_seen', false)->get(); + + $this->assertCount(1, $seenEmails); + $this->assertCount(1, $unseenEmails); + } +} \ No newline at end of file diff --git a/tests/Unit/Models/RemainingModelsTest.php b/tests/Unit/Models/RemainingModelsTest.php deleted file mode 100644 index a3166d0..0000000 --- a/tests/Unit/Models/RemainingModelsTest.php +++ /dev/null @@ -1,625 +0,0 @@ -create(); - - $this->assertInstanceOf(Page::class, $page); - $this->assertIsString($page->title); - $this->assertIsString($page->slug); - } - - /** @test */ - public function it_has_correct_fillable_attributes() - { - $pageData = [ - 'title' => 'About Us', - 'slug' => 'about-us', - 'content' => 'About us page content', - 'meta' => [ - 'description' => 'About us meta description', - 'keywords' => 'about,company', - ], - 'is_published' => true, - ]; - - $page = Page::create($pageData); - - foreach ($pageData as $key => $value) { - $this->assertEquals($value, $page->$key); - } - } - - /** @test */ - public function it_generates_unique_slugs() - { - $page1 = Page::factory()->create(['title' => 'Same Title']); - $page2 = Page::factory()->create(['title' => 'Same Title']); - - $this->assertNotEquals($page1->slug, $page2->slug); - } - - /** @test */ - public function it_can_query_published_pages() - { - $publishedPage = Page::factory()->create(['is_published' => true]); - $draftPage = Page::factory()->create(['is_published' => false]); - - $publishedPages = Page::where('is_published', true)->get(); - $draftPages = Page::where('is_published', false)->get(); - - $this->assertCount(1, $publishedPages); - $this->assertCount(1, $draftPages); - } -} - -class MenuTest extends TestCase -{ - /** @test */ - public function it_can_create_a_menu_with_factory() - { - $menu = Menu::factory()->create(); - - $this->assertInstanceOf(Menu::class, $menu); - $this->assertIsString($menu->name); - $this->assertIsString($menu->url); - } - - /** @test */ - public function it_has_correct_fillable_attributes() - { - $menuData = [ - 'name' => 'Home', - 'url' => '/home', - 'new_tab' => false, - 'parent' => null, - ]; - - $menu = Menu::create($menuData); - - foreach ($menuData as $key => $value) { - $this->assertEquals($value, $menu->$key); - } - } - - /** @test */ - public function it_orders_menus_by_name() - { - $menu1 = Menu::factory()->create(['name' => 'Zebra']); - $menu2 = Menu::factory()->create(['name' => 'Alpha']); - $menu3 = Menu::factory()->create(['name' => 'Beta']); - - $menus = Menu::orderBy('name')->get(); - - $this->assertEquals($menu2->id, $menus[0]->id); - $this->assertEquals($menu3->id, $menus[1]->id); - $this->assertEquals($menu1->id, $menus[2]->id); - } - - /** @test */ - public function it_can_handle_parent_child_relationships() - { - $parentMenu = Menu::factory()->create(['parent' => null]); - $childMenu = Menu::factory()->create(['parent' => 'home']); - - $this->assertEquals('home', $childMenu->parent); - } -} - -class LogTest extends TestCase -{ - protected function setUp(): void - { - parent::setUp(); - - $this->user = User::factory()->create(); - } - - /** @test */ - public function it_can_create_a_log_with_factory() - { - $log = Log::factory()->create(); - - $this->assertInstanceOf(Log::class, $log); - $this->assertIsString($log->email); - $this->assertIsString($log->ip); - } - - /** @test */ - public function it_has_correct_fillable_attributes() - { - $logData = [ - 'user_id' => $this->user->id, - 'email' => 'test@example.com', - 'ip' => '192.168.1.1', - ]; - - $log = Log::create($logData); - - foreach ($logData as $key => $value) { - $this->assertEquals($value, $log->$key); - } - } - - /** @test */ - public function it_belongs_to_a_user() - { - $log = Log::factory()->create(['user_id' => $this->user->id]); - - $this->assertInstanceOf(User::class, $log->user); - $this->assertEquals($this->user->id, $log->user->id); - } - - /** @test */ - public function it_stores_ip_addresses_correctly() - { - $ipAddresses = ['127.0.0.1', '192.168.1.100', '10.0.0.1']; - - foreach ($ipAddresses as $ip) { - $log = Log::factory()->create(['ip' => $ip]); - $this->assertEquals($ip, $log->ip); - } - } - - /** @test */ - public function it_orders_logs_by_creation_date() - { - $oldLog = Log::factory()->create(['created_at' => now()->subHours(2)]); - $newLog = Log::factory()->create(['created_at' => now()]); - - $logs = Log::orderBy('created_at', 'desc')->get(); - - $this->assertEquals($newLog->id, $logs->first()->id); - $this->assertEquals($oldLog->id, $logs->last()->id); - } -} - -class UsageLogTest extends TestCase -{ - protected function setUp(): void - { - parent::setUp(); - - $this->user = User::factory()->create(); - } - - /** @test */ - public function it_can_create_a_usage_log_with_factory() - { - $usageLog = UsageLog::factory()->create(); - - $this->assertInstanceOf(UsageLog::class, $usageLog); - $this->assertIsInt($usageLog->emails_created_count); - $this->assertIsInt($usageLog->emails_received_count); - } - - /** @test */ - public function it_has_correct_fillable_attributes() - { - $usageLogData = [ - 'user_id' => $this->user->id, - 'ip_address' => '192.168.1.1', - 'emails_created_count' => 5, - 'emails_received_count' => 10, - 'emails_created_history' => json_encode(['2023-01-01 12:00:00' => 3]), - 'emails_received_history' => json_encode(['2023-01-01 12:30:00' => 7]), - ]; - - $usageLog = UsageLog::create($usageLogData); - - foreach ($usageLogData as $key => $value) { - $this->assertEquals($value, $usageLog->$key); - } - } - - /** @test */ - public function it_belongs_to_a_user() - { - $usageLog = UsageLog::factory()->create(['user_id' => $this->user->id]); - - $this->assertInstanceOf(User::class, $usageLog->user); - $this->assertEquals($this->user->id, $usageLog->user->id); - } - - /** @test */ - public function it_tracks_different_email_counts() - { - $usageLog = UsageLog::factory()->create([ - 'emails_created_count' => 15, - 'emails_received_count' => 25, - ]); - - $this->assertEquals(15, $usageLog->emails_created_count); - $this->assertEquals(25, $usageLog->emails_received_count); - } -} - -class MetaTest extends TestCase -{ - /** @test */ - public function it_can_create_a_meta_with_factory() - { - $meta = Meta::factory()->create(); - - $this->assertInstanceOf(Meta::class, $meta); - $this->assertIsString($meta->key); - $this->assertIsString($meta->value); - } - - /** @test */ - public function it_has_correct_fillable_attributes() - { - $metaData = [ - 'key' => 'total_emails_created', - 'value' => '1500', - 'type' => 'counter', - ]; - - $meta = Meta::create($metaData); - - foreach ($metaData as $key => $value) { - $this->assertEquals($value, $meta->$key); - } - } - - /** @test */ - public function it_stores_key_value_pairs_correctly() - { - $meta = Meta::factory()->create([ - 'key' => 'app_version', - 'value' => '1.2.3', - ]); - - $this->assertEquals('app_version', $meta->key); - $this->assertEquals('1.2.3', $meta->value); - } - - /** @test */ - public function it_can_retrieve_value_by_key() - { - Meta::factory()->create(['key' => 'site_name', 'value' => 'ZEmailnator']); - Meta::factory()->create(['key' => 'max_emails', 'value' => '100']); - - $siteName = Meta::where('key', 'site_name')->first(); - $maxEmails = Meta::where('key', 'max_emails')->first(); - - $this->assertEquals('ZEmailnator', $siteName->value); - $this->assertEquals('100', $maxEmails->value); - } -} - -class PremiumEmailTest extends TestCase -{ - protected function setUp(): void - { - parent::setUp(); - - $this->user = User::factory()->create(); - } - - /** @test */ - public function it_can_create_a_premium_email_with_factory() - { - $premiumEmail = PremiumEmail::factory()->create(); - - $this->assertInstanceOf(PremiumEmail::class, $premiumEmail); - $this->assertIsString($premiumEmail->from_email); - $this->assertIsString($premiumEmail->subject); - } - - /** @test */ - public function it_has_correct_fillable_attributes() - { - $premiumEmailData = [ - 'user_id' => $this->user->id, - 'message_id' => 'test_msg_123', - 'from_email' => 'sender@example.com', - 'from_name' => 'Test Sender', - 'subject' => 'Test Subject', - 'to' => ['recipient@example.com'], - ]; - - $premiumEmail = PremiumEmail::create($premiumEmailData); - - foreach ($premiumEmailData as $key => $value) { - $this->assertEquals($value, $premiumEmail->$key); - } - } - - /** @test */ - public function it_belongs_to_a_user() - { - $premiumEmail = PremiumEmail::factory()->create(['user_id' => $this->user->id]); - - $this->assertInstanceOf(User::class, $premiumEmail->user); - $this->assertEquals($this->user->id, $premiumEmail->user->id); - } - - /** @test */ - public function it_casts_timestamp_to_datetime() - { - $timestamp = now()->subDays(5); - $premiumEmail = PremiumEmail::factory()->create(['timestamp' => $timestamp]); - - $this->assertInstanceOf(Carbon::class, $premiumEmail->timestamp); - $this->assertEquals($timestamp->format('Y-m-d H:i:s'), $premiumEmail->timestamp->format('Y-m-d H:i:s')); - } - - /** @test */ - public function it_can_query_seen_and_unseen_emails() - { - $seenEmail = PremiumEmail::factory()->create(['is_seen' => true]); - $unseenEmail = PremiumEmail::factory()->create(['is_seen' => false]); - - $seenEmails = PremiumEmail::where('is_seen', true)->get(); - $unseenEmails = PremiumEmail::where('is_seen', false)->get(); - - $this->assertCount(1, $seenEmails); - $this->assertCount(1, $unseenEmails); - } -} - -class RemoteEmailTest extends TestCase -{ - /** @test */ - public function it_can_create_a_remote_email_with_factory() - { - $remoteEmail = RemoteEmail::factory()->create(); - - $this->assertInstanceOf(RemoteEmail::class, $remoteEmail); - $this->assertIsArray($remoteEmail->to); - $this->assertIsString($remoteEmail->from_email); - } - - /** @test */ - public function it_has_correct_fillable_attributes() - { - $remoteEmailData = [ - 'message_id' => 'remote_123', - 'subject' => 'Remote Email Subject', - 'from_name' => 'Remote Sender', - 'from_email' => 'remote@example.com', - 'to' => ['recipient@example.com'], - 'body_html' => '

HTML content

', - 'body_text' => 'Text content', - 'is_seen' => false, - 'timestamp' => now(), - ]; - - $remoteEmail = RemoteEmail::create($remoteEmailData); - - foreach ($remoteEmailData as $key => $value) { - $this->assertEquals($value, $remoteEmail->$key); - } - } - - /** @test */ - public function it_casts_to_field_to_array() - { - $to = ['test1@example.com', 'test2@example.com']; - $remoteEmail = RemoteEmail::factory()->create(['to' => $to]); - - $this->assertIsArray($remoteEmail->to); - $this->assertEquals($to, $remoteEmail->to); - } - - /** @test */ - public function it_casts_timestamp_to_datetime() - { - $timestamp = now(); - $remoteEmail = RemoteEmail::factory()->create(['timestamp' => $timestamp]); - - $this->assertInstanceOf(Carbon::class, $remoteEmail->timestamp); - $this->assertEquals($timestamp, $remoteEmail->timestamp); - } -} - -class ActivationKeyTest extends TestCase -{ - protected function setUp(): void - { - parent::setUp(); - - $this->user = User::factory()->create(); - } - - /** @test */ - public function it_can_create_an_activation_key_with_factory() - { - $activationKey = ActivationKey::factory()->create(); - - $this->assertInstanceOf(ActivationKey::class, $activationKey); - $this->assertIsString($activationKey->activation_key); - $this->assertIsInt($activationKey->price_id); - } - - /** @test */ - public function it_has_correct_fillable_attributes() - { - $activationKeyData = [ - 'user_id' => $this->user->id, - 'activation_key' => 'ACTIVATION-KEY-123456', - 'price_id' => 1, - 'is_activated' => false, - ]; - - $activationKey = ActivationKey::create($activationKeyData); - - foreach ($activationKeyData as $key => $value) { - $this->assertEquals($value, $activationKey->$key); - } - } - - /** @test */ - public function it_belongs_to_a_user() - { - $activationKey = ActivationKey::factory()->create(['user_id' => $this->user->id]); - - $this->assertInstanceOf(User::class, $activationKey->user); - $this->assertEquals($this->user->id, $activationKey->user->id); - } - - /** @test */ - public function it_generates_unique_keys() - { - $key1 = ActivationKey::factory()->create(); - $key2 = ActivationKey::factory()->create(); - - $this->assertNotEquals($key1->activation_key, $key2->activation_key); - } - - /** @test */ - public function it_can_query_unactivated_activation_keys() - { - $unactivatedKey = ActivationKey::factory()->create(['is_activated' => false]); - $activatedKey = ActivationKey::factory()->create(['is_activated' => true]); - - $unactivatedKeys = ActivationKey::where('is_activated', false)->get(); - $activatedKeys = ActivationKey::where('is_activated', true)->get(); - - $this->assertCount(1, $unactivatedKeys); - $this->assertCount(1, $activatedKeys); - } -} - -class SettingTest extends TestCase -{ - /** @test */ - public function it_can_create_a_setting_with_factory() - { - $setting = Setting::factory()->create(); - - $this->assertInstanceOf(Setting::class, $setting); - $this->assertIsString($setting->app_name); - $this->assertIsString($setting->app_version); - } - - /** @test */ - public function it_has_correct_fillable_attributes() - { - $settingData = [ - 'app_name' => 'ZEmailnator', - 'app_version' => '1.0.0', - 'app_base_url' => 'https://example.com', - 'app_admin' => 'admin@example.com', - 'app_title' => 'Test Title', - ]; - - $setting = Setting::create($settingData); - - foreach ($settingData as $key => $value) { - $this->assertEquals($value, $setting->$key); - } - } - - /** @test */ - public function it_stores_configuration_values() - { - $setting = Setting::factory()->create([ - 'app_name' => 'Test App', - 'configuration_settings' => json_encode([ - 'max_emails_per_user' => 100, - 'enable_registrations' => true, - 'default_language' => 'en', - ]), - ]); - - $this->assertEquals('Test App', $setting->app_name); - $this->assertIsString($setting->configuration_settings); - $config = json_decode($setting->configuration_settings, true); - $this->assertEquals(100, $config['max_emails_per_user']); - } - - /** @test */ - public function it_can_query_public_settings() - { - $setting1 = Setting::factory()->create(['app_name' => 'Public App']); - $setting2 = Setting::factory()->create(['app_name' => 'Private App']); - - $allSettings = Setting::all(); - - $this->assertCount(2, $allSettings); - $this->assertIsString($allSettings->first()->app_name); - } -} - -class MessageTest extends TestCase -{ - /** @test */ - public function it_can_create_a_message_with_factory() - { - $message = Message::factory()->create(); - - $this->assertInstanceOf(Message::class, $message); - $this->assertIsString($message->subject); - $this->assertIsString($message->from); - } - - /** @test */ - public function it_has_correct_fillable_attributes() - { - $messageData = [ - 'subject' => 'Test Message', - 'from' => 'Test Sender ', - 'to' => 'recipient@example.com', - 'body' => 'Test body content', - 'attachments' => null, - 'is_seen' => false, - ]; - - $message = Message::create($messageData); - - foreach ($messageData as $key => $value) { - $this->assertEquals($value, $message->$key); - } - } - - /** @test */ - public function it_stores_to_field_as_string() - { - $to = 'test1@example.com'; - $message = Message::factory()->create(['to' => $to]); - - $this->assertIsString($message->to); - $this->assertEquals($to, $message->to); - } - - /** @test */ - public function it_uses_created_at_as_timestamp() - { - $message = Message::factory()->create(); - - $this->assertInstanceOf(Carbon::class, $message->created_at); - $this->assertNotNull($message->created_at); - } - - /** @test */ - public function it_can_query_unseen_messages() - { - $unseenMessage = Message::factory()->create(['is_seen' => false]); - $seenMessage = Message::factory()->create(['is_seen' => true]); - - $unseenMessages = Message::where('is_seen', false)->get(); - $seenMessages = Message::where('is_seen', true)->get(); - - $this->assertCount(1, $unseenMessages); - $this->assertCount(1, $seenMessages); - } -} \ No newline at end of file diff --git a/tests/Unit/Models/RemoteEmailTest.php b/tests/Unit/Models/RemoteEmailTest.php new file mode 100644 index 0000000..bd8b4f1 --- /dev/null +++ b/tests/Unit/Models/RemoteEmailTest.php @@ -0,0 +1,68 @@ +create(); + + $this->assertInstanceOf(RemoteEmail::class, $remoteEmail); + $this->assertIsArray($remoteEmail->to); + $this->assertIsString($remoteEmail->from_email); + } + + /** @test */ + public function it_has_correct_fillable_attributes() + { + $timestamp = now(); + $remoteEmailData = [ + 'message_id' => 'remote_123', + 'subject' => 'Remote Email Subject', + 'from_name' => 'Remote Sender', + 'from_email' => 'remote@example.com', + 'to' => ['recipient@example.com'], + 'body_html' => '

HTML content

', + 'body_text' => 'Text content', + 'is_seen' => false, + 'timestamp' => $timestamp, + ]; + + $remoteEmail = RemoteEmail::create($remoteEmailData); + + foreach ($remoteEmailData as $key => $value) { + if ($key === 'timestamp') { + $this->assertInstanceOf(Carbon::class, $remoteEmail->$key); + $this->assertEquals($timestamp->format('Y-m-d H:i:s'), $remoteEmail->$key->format('Y-m-d H:i:s')); + } else { + $this->assertEquals($value, $remoteEmail->$key); + } + } + } + + /** @test */ + public function it_casts_to_field_to_array() + { + $to = ['test1@example.com', 'test2@example.com']; + $remoteEmail = RemoteEmail::factory()->create(['to' => $to]); + + $this->assertIsArray($remoteEmail->to); + $this->assertEquals($to, $remoteEmail->to); + } + + /** @test */ + public function it_casts_timestamp_to_datetime() + { + $timestamp = now(); + $remoteEmail = RemoteEmail::factory()->create(['timestamp' => $timestamp]); + + $this->assertInstanceOf(Carbon::class, $remoteEmail->timestamp); + $this->assertEquals($timestamp->format('Y-m-d H:i:s'), $remoteEmail->timestamp->format('Y-m-d H:i:s')); + } +} \ No newline at end of file diff --git a/tests/Unit/Models/SettingTest.php b/tests/Unit/Models/SettingTest.php new file mode 100644 index 0000000..40a3118 --- /dev/null +++ b/tests/Unit/Models/SettingTest.php @@ -0,0 +1,67 @@ +create(); + + $this->assertInstanceOf(Setting::class, $setting); + $this->assertIsString($setting->app_name); + $this->assertIsString($setting->app_version); + } + + /** @test */ + public function it_has_correct_fillable_attributes() + { + $settingData = [ + 'app_name' => 'ZEmailnator', + 'app_version' => '1.0.0', + 'app_base_url' => 'https://example.com', + 'app_admin' => 'admin@example.com', + 'app_title' => 'Test Title', + ]; + + $setting = Setting::create($settingData); + + foreach ($settingData as $key => $value) { + $this->assertEquals($value, $setting->$key); + } + } + + /** @test */ + public function it_stores_configuration_values() + { + $setting = Setting::factory()->create([ + 'app_name' => 'Test App', + 'configuration_settings' => json_encode([ + 'max_emails_per_user' => 100, + 'enable_registrations' => true, + 'default_language' => 'en', + ]), + ]); + + $this->assertEquals('Test App', $setting->app_name); + $this->assertIsString($setting->configuration_settings); + $config = json_decode($setting->configuration_settings, true); + $this->assertEquals(100, $config['max_emails_per_user']); + } + + /** @test */ + public function it_can_query_public_settings() + { + $setting1 = Setting::factory()->create(['app_name' => 'Public App']); + $setting2 = Setting::factory()->create(['app_name' => 'Private App']); + + $allSettings = Setting::all(); + + $this->assertCount(2, $allSettings); + $this->assertIsString($allSettings->first()->app_name); + } +} \ No newline at end of file diff --git a/tests/Unit/Models/TicketResponseTest.php b/tests/Unit/Models/TicketResponseTest.php index 4720828..dae82d0 100644 --- a/tests/Unit/Models/TicketResponseTest.php +++ b/tests/Unit/Models/TicketResponseTest.php @@ -1,5 +1,7 @@ user = User::factory()->create(); + } + + /** @test */ + public function it_can_create_a_usage_log_with_factory() + { + $usageLog = UsageLog::factory()->create(); + + $this->assertInstanceOf(UsageLog::class, $usageLog); + $this->assertIsInt($usageLog->emails_created_count); + $this->assertIsInt($usageLog->emails_received_count); + } + + /** @test */ + public function it_has_correct_fillable_attributes() + { + $usageLogData = [ + 'user_id' => $this->user->id, + 'ip_address' => '192.168.1.1', + 'emails_created_count' => 5, + 'emails_received_count' => 10, + 'emails_created_history' => json_encode(['2023-01-01 12:00:00' => 3]), + 'emails_received_history' => json_encode(['2023-01-01 12:30:00' => 7]), + ]; + + $usageLog = UsageLog::create($usageLogData); + + foreach ($usageLogData as $key => $value) { + $this->assertEquals($value, $usageLog->$key); + } + } + + /** @test */ + public function it_belongs_to_a_user() + { + $usageLog = UsageLog::factory()->create(['user_id' => $this->user->id]); + + $this->assertInstanceOf(User::class, $usageLog->user); + $this->assertEquals($this->user->id, $usageLog->user->id); + } + + /** @test */ + public function it_tracks_different_email_counts() + { + $usageLog = UsageLog::factory()->create([ + 'emails_created_count' => 15, + 'emails_received_count' => 25, + ]); + + $this->assertEquals(15, $usageLog->emails_created_count); + $this->assertEquals(25, $usageLog->emails_received_count); + } +} \ No newline at end of file diff --git a/tests/Unit/Models/UserTest.php b/tests/Unit/Models/UserTest.php index 4d1d80d..584ba0c 100644 --- a/tests/Unit/Models/UserTest.php +++ b/tests/Unit/Models/UserTest.php @@ -1,5 +1,7 @@