Phase 2: Implement Domain & Mailbox persistence, Analytics, and fix pagination issues
This commit is contained in:
46
tests/Unit/DomainTest.php
Normal file
46
tests/Unit/DomainTest.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Domain;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
uses(Tests\TestCase::class, RefreshDatabase::class);
|
||||
|
||||
test('domain hash is automatically generated on creation', function () {
|
||||
$domain = Domain::factory()->create([
|
||||
'name' => 'auto-hash-test.com',
|
||||
]);
|
||||
|
||||
expect($domain->domain_hash)->not->toBeNull()
|
||||
->and(strlen($domain->domain_hash))->toBeGreaterThan(20);
|
||||
});
|
||||
|
||||
test('allowed_types is cast to array', function () {
|
||||
$domain = Domain::factory()->create([
|
||||
'allowed_types' => ['test', 'demo'],
|
||||
]);
|
||||
|
||||
$freshDomain = Domain::find($domain->id);
|
||||
expect($freshDomain->allowed_types)->toBeArray()
|
||||
->and($freshDomain->allowed_types)->toBe(['test', 'demo']);
|
||||
});
|
||||
|
||||
test('domain supports soft deletes', function () {
|
||||
$domain = Domain::factory()->create();
|
||||
$id = $domain->id;
|
||||
|
||||
$domain->delete();
|
||||
|
||||
$this->assertSoftDeleted('domains', ['id' => $id]);
|
||||
expect(Domain::find($id))->toBeNull();
|
||||
expect(Domain::withTrashed()->find($id))->not->toBeNull();
|
||||
});
|
||||
|
||||
test('domain is_active and is_archived are cast to boolean', function () {
|
||||
$domain = Domain::factory()->create([
|
||||
'is_active' => 1,
|
||||
'is_archived' => 0,
|
||||
]);
|
||||
|
||||
expect($domain->is_active)->toBeTrue()
|
||||
->and($domain->is_archived)->toBeFalse();
|
||||
});
|
||||
62
tests/Unit/MailboxModelTest.php
Normal file
62
tests/Unit/MailboxModelTest.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
use App\Jobs\TrackAnalytics;
|
||||
use App\Models\Domain;
|
||||
use App\Models\Mailbox;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
|
||||
uses(Tests\TestCase::class, RefreshDatabase::class);
|
||||
|
||||
test('mailbox hash is automatically generated on creation', function () {
|
||||
Queue::fake();
|
||||
|
||||
$domain = Domain::factory()->create();
|
||||
$mailbox = Mailbox::factory()->create([
|
||||
'domain_hash' => $domain->domain_hash,
|
||||
'address' => 'hash-test@'.$domain->name,
|
||||
]);
|
||||
|
||||
expect($mailbox->mailbox_hash)->not->toBeNull()
|
||||
->and(strlen($mailbox->mailbox_hash))->toBeGreaterThan(20);
|
||||
});
|
||||
|
||||
test('TrackAnalytics job is dispatched on mailbox creation', function () {
|
||||
Queue::fake();
|
||||
|
||||
$mailbox = Mailbox::factory()->create();
|
||||
|
||||
Queue::assertPushed(TrackAnalytics::class, function ($job) use ($mailbox) {
|
||||
return $job->eventType === 'mailbox_created' &&
|
||||
$job->mailboxHash === $mailbox->mailbox_hash;
|
||||
});
|
||||
});
|
||||
|
||||
test('mailbox relationships work correctly', function () {
|
||||
Queue::fake();
|
||||
|
||||
$user = User::factory()->create();
|
||||
$domain = Domain::factory()->create();
|
||||
$mailbox = Mailbox::factory()->create([
|
||||
'user_id' => $user->id,
|
||||
'domain_hash' => $domain->domain_hash,
|
||||
]);
|
||||
|
||||
expect($mailbox->user->id)->toBe($user->id)
|
||||
->and($mailbox->domain->domain_hash)->toBe($domain->domain_hash);
|
||||
});
|
||||
|
||||
test('mailbox casts dates and booleans correctly', function () {
|
||||
Queue::fake();
|
||||
|
||||
$mailbox = Mailbox::factory()->create([
|
||||
'expires_at' => now()->addHours(2),
|
||||
'is_blocked' => 1,
|
||||
'blocked_at' => now()->subMinute(),
|
||||
]);
|
||||
|
||||
expect($mailbox->expires_at)->toBeInstanceOf(\Illuminate\Support\Carbon::class)
|
||||
->and($mailbox->is_blocked)->toBeTrue()
|
||||
->and($mailbox->blocked_at)->toBeInstanceOf(\Illuminate\Support\Carbon::class);
|
||||
});
|
||||
Reference in New Issue
Block a user