completed story 1.1 with QA tests and fixes
This commit is contained in:
@@ -10,7 +10,7 @@ test('login screen can be rendered', function () {
|
||||
});
|
||||
|
||||
test('users can authenticate using the login screen', function () {
|
||||
$user = User::factory()->withoutTwoFactor()->create();
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this->post(route('login.store'), [
|
||||
'email' => $user->email,
|
||||
@@ -47,7 +47,7 @@ test('users with two factor enabled are redirected to two factor challenge', fun
|
||||
'confirmPassword' => true,
|
||||
]);
|
||||
|
||||
$user = User::factory()->create();
|
||||
$user = User::factory()->withTwoFactor()->create();
|
||||
|
||||
$response = $this->post(route('login.store'), [
|
||||
'email' => $user->email,
|
||||
@@ -66,4 +66,4 @@ test('users can logout', function () {
|
||||
$response->assertRedirect(route('home'));
|
||||
|
||||
$this->assertGuest();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -8,8 +8,9 @@ test('registration screen can be rendered', function () {
|
||||
|
||||
test('new users can register', function () {
|
||||
$response = $this->post(route('register.store'), [
|
||||
'name' => 'John Doe',
|
||||
'full_name' => 'John Doe',
|
||||
'email' => 'test@example.com',
|
||||
'phone' => '+1234567890',
|
||||
'password' => 'password',
|
||||
'password_confirmation' => 'password',
|
||||
]);
|
||||
@@ -18,4 +19,4 @@ test('new users can register', function () {
|
||||
->assertRedirect(route('dashboard', absolute: false));
|
||||
|
||||
$this->assertAuthenticated();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -23,10 +23,10 @@ test('two factor challenge can be rendered', function () {
|
||||
'confirmPassword' => true,
|
||||
]);
|
||||
|
||||
$user = User::factory()->create();
|
||||
$user = User::factory()->withTwoFactor()->create();
|
||||
|
||||
$this->post(route('login.store'), [
|
||||
'email' => $user->email,
|
||||
'password' => 'password',
|
||||
])->assertRedirect(route('two-factor.login'));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\ConsultationStatus;
|
||||
use App\Enums\PostStatus;
|
||||
use App\Enums\TimelineStatus;
|
||||
use App\Enums\UserStatus;
|
||||
use App\Enums\UserType;
|
||||
use App\Models\AdminLog;
|
||||
use App\Models\BlockedTime;
|
||||
use App\Models\Consultation;
|
||||
use App\Models\Notification;
|
||||
use App\Models\Post;
|
||||
use App\Models\Timeline;
|
||||
use App\Models\TimelineUpdate;
|
||||
use App\Models\User;
|
||||
use App\Models\WorkingHour;
|
||||
|
||||
test('user factory creates valid user', function () {
|
||||
$user = User::factory()->create();
|
||||
|
||||
expect($user)->toBeInstanceOf(User::class)
|
||||
->and($user->user_type)->toBeInstanceOf(UserType::class)
|
||||
->and($user->status)->toBeInstanceOf(UserStatus::class)
|
||||
->and($user->full_name)->toBeString()
|
||||
->and($user->email)->toBeString()
|
||||
->and($user->phone)->toBeString();
|
||||
});
|
||||
|
||||
test('user factory admin state creates admin user', function () {
|
||||
$user = User::factory()->admin()->create();
|
||||
|
||||
expect($user->user_type)->toBe(UserType::Admin);
|
||||
});
|
||||
|
||||
test('user factory individual state creates individual user', function () {
|
||||
$user = User::factory()->individual()->create();
|
||||
|
||||
expect($user->user_type)->toBe(UserType::Individual);
|
||||
});
|
||||
|
||||
test('user factory company state creates company user', function () {
|
||||
$user = User::factory()->company()->create();
|
||||
|
||||
expect($user->user_type)->toBe(UserType::Company)
|
||||
->and($user->company_name)->toBeString()
|
||||
->and($user->company_cert_number)->toBeString();
|
||||
});
|
||||
|
||||
test('consultation factory creates valid consultation', function () {
|
||||
$consultation = Consultation::factory()->create();
|
||||
|
||||
expect($consultation)->toBeInstanceOf(Consultation::class)
|
||||
->and($consultation->user)->toBeInstanceOf(User::class)
|
||||
->and($consultation->status)->toBeInstanceOf(ConsultationStatus::class)
|
||||
->and($consultation->booking_date)->toBeInstanceOf(\Illuminate\Support\Carbon::class);
|
||||
});
|
||||
|
||||
test('timeline factory creates valid timeline', function () {
|
||||
$timeline = Timeline::factory()->create();
|
||||
|
||||
expect($timeline)->toBeInstanceOf(Timeline::class)
|
||||
->and($timeline->user)->toBeInstanceOf(User::class)
|
||||
->and($timeline->status)->toBeInstanceOf(TimelineStatus::class)
|
||||
->and($timeline->case_name)->toBeString();
|
||||
});
|
||||
|
||||
test('timeline update factory creates valid timeline update', function () {
|
||||
$update = TimelineUpdate::factory()->create();
|
||||
|
||||
expect($update)->toBeInstanceOf(TimelineUpdate::class)
|
||||
->and($update->timeline)->toBeInstanceOf(Timeline::class)
|
||||
->and($update->admin)->toBeInstanceOf(User::class)
|
||||
->and($update->update_text)->toBeString();
|
||||
});
|
||||
|
||||
test('post factory creates valid post', function () {
|
||||
$post = Post::factory()->create();
|
||||
|
||||
expect($post)->toBeInstanceOf(Post::class)
|
||||
->and($post->status)->toBeInstanceOf(PostStatus::class)
|
||||
->and($post->title)->toBeArray()
|
||||
->and($post->body)->toBeArray()
|
||||
->and($post->title)->toHaveKeys(['ar', 'en'])
|
||||
->and($post->body)->toHaveKeys(['ar', 'en']);
|
||||
});
|
||||
|
||||
test('working hour factory creates valid working hour', function () {
|
||||
$workingHour = WorkingHour::factory()->create();
|
||||
|
||||
expect($workingHour)->toBeInstanceOf(WorkingHour::class)
|
||||
->and($workingHour->day_of_week)->toBeInt()
|
||||
->and($workingHour->day_of_week)->toBeBetween(0, 6)
|
||||
->and($workingHour->is_active)->toBeBool();
|
||||
});
|
||||
|
||||
test('blocked time factory creates valid blocked time', function () {
|
||||
$blockedTime = BlockedTime::factory()->create();
|
||||
|
||||
expect($blockedTime)->toBeInstanceOf(BlockedTime::class)
|
||||
->and($blockedTime->block_date)->toBeInstanceOf(\Illuminate\Support\Carbon::class);
|
||||
});
|
||||
|
||||
test('notification factory creates valid notification', function () {
|
||||
$notification = Notification::factory()->create();
|
||||
|
||||
expect($notification)->toBeInstanceOf(Notification::class)
|
||||
->and($notification->user)->toBeInstanceOf(User::class)
|
||||
->and($notification->type)->toBeString()
|
||||
->and($notification->data)->toBeArray();
|
||||
});
|
||||
|
||||
test('admin log factory creates valid admin log', function () {
|
||||
$log = AdminLog::factory()->create();
|
||||
|
||||
expect($log)->toBeInstanceOf(AdminLog::class)
|
||||
->and($log->admin)->toBeInstanceOf(User::class)
|
||||
->and($log->action)->toBeString()
|
||||
->and($log->ip_address)->toBeString();
|
||||
});
|
||||
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
test('all tables exist after migration', function () {
|
||||
expect(Schema::hasTable('users'))->toBeTrue()
|
||||
->and(Schema::hasTable('consultations'))->toBeTrue()
|
||||
->and(Schema::hasTable('timelines'))->toBeTrue()
|
||||
->and(Schema::hasTable('timeline_updates'))->toBeTrue()
|
||||
->and(Schema::hasTable('posts'))->toBeTrue()
|
||||
->and(Schema::hasTable('working_hours'))->toBeTrue()
|
||||
->and(Schema::hasTable('blocked_times'))->toBeTrue()
|
||||
->and(Schema::hasTable('notifications'))->toBeTrue()
|
||||
->and(Schema::hasTable('admin_logs'))->toBeTrue();
|
||||
});
|
||||
|
||||
test('users table has all required columns', function () {
|
||||
expect(Schema::hasColumns('users', [
|
||||
'id',
|
||||
'user_type',
|
||||
'full_name',
|
||||
'national_id',
|
||||
'company_name',
|
||||
'company_cert_number',
|
||||
'contact_person_name',
|
||||
'contact_person_id',
|
||||
'email',
|
||||
'phone',
|
||||
'password',
|
||||
'status',
|
||||
'preferred_language',
|
||||
'email_verified_at',
|
||||
'remember_token',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
]))->toBeTrue();
|
||||
});
|
||||
|
||||
test('consultations table has all required columns', function () {
|
||||
expect(Schema::hasColumns('consultations', [
|
||||
'id',
|
||||
'user_id',
|
||||
'booking_date',
|
||||
'booking_time',
|
||||
'problem_summary',
|
||||
'consultation_type',
|
||||
'payment_amount',
|
||||
'payment_status',
|
||||
'status',
|
||||
'admin_notes',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
]))->toBeTrue();
|
||||
});
|
||||
|
||||
test('timelines table has all required columns', function () {
|
||||
expect(Schema::hasColumns('timelines', [
|
||||
'id',
|
||||
'user_id',
|
||||
'case_name',
|
||||
'case_reference',
|
||||
'status',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
]))->toBeTrue();
|
||||
});
|
||||
|
||||
test('posts table has all required columns', function () {
|
||||
expect(Schema::hasColumns('posts', [
|
||||
'id',
|
||||
'title',
|
||||
'body',
|
||||
'status',
|
||||
'published_at',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
]))->toBeTrue();
|
||||
});
|
||||
|
||||
test('migrate rollback works without errors', function () {
|
||||
$result = Artisan::call('migrate:rollback', ['--force' => true]);
|
||||
expect($result)->toBe(0);
|
||||
|
||||
$result = Artisan::call('migrate', ['--force' => true]);
|
||||
expect($result)->toBe(0);
|
||||
});
|
||||
@@ -15,7 +15,7 @@ test('profile information can be updated', function () {
|
||||
$this->actingAs($user);
|
||||
|
||||
$response = Volt::test('settings.profile')
|
||||
->set('name', 'Test User')
|
||||
->set('full_name', 'Test User')
|
||||
->set('email', 'test@example.com')
|
||||
->call('updateProfileInformation');
|
||||
|
||||
@@ -23,7 +23,7 @@ test('profile information can be updated', function () {
|
||||
|
||||
$user->refresh();
|
||||
|
||||
expect($user->name)->toEqual('Test User');
|
||||
expect($user->full_name)->toEqual('Test User');
|
||||
expect($user->email)->toEqual('test@example.com');
|
||||
expect($user->email_verified_at)->toBeNull();
|
||||
});
|
||||
@@ -34,7 +34,7 @@ test('email verification status is unchanged when email address is unchanged', f
|
||||
$this->actingAs($user);
|
||||
|
||||
$response = Volt::test('settings.profile')
|
||||
->set('name', 'Test User')
|
||||
->set('full_name', 'Test User')
|
||||
->set('email', $user->email)
|
||||
->call('updateProfileInformation');
|
||||
|
||||
@@ -72,4 +72,4 @@ test('correct password must be provided to delete account', function () {
|
||||
$response->assertHasErrors(['password']);
|
||||
|
||||
expect($user->fresh())->not->toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -15,6 +15,10 @@ pest()->extend(Tests\TestCase::class)
|
||||
->use(Illuminate\Foundation\Testing\RefreshDatabase::class)
|
||||
->in('Feature');
|
||||
|
||||
pest()->extend(Tests\TestCase::class)
|
||||
->use(Illuminate\Foundation\Testing\RefreshDatabase::class)
|
||||
->in('Unit/Models');
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Expectations
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\ConsultationStatus;
|
||||
|
||||
test('consultation status has correct cases', function () {
|
||||
expect(ConsultationStatus::cases())->toHaveCount(6);
|
||||
});
|
||||
|
||||
test('consultation status pending has correct value', function () {
|
||||
expect(ConsultationStatus::Pending->value)->toBe('pending');
|
||||
});
|
||||
|
||||
test('consultation status approved has correct value', function () {
|
||||
expect(ConsultationStatus::Approved->value)->toBe('approved');
|
||||
});
|
||||
|
||||
test('consultation status rejected has correct value', function () {
|
||||
expect(ConsultationStatus::Rejected->value)->toBe('rejected');
|
||||
});
|
||||
|
||||
test('consultation status completed has correct value', function () {
|
||||
expect(ConsultationStatus::Completed->value)->toBe('completed');
|
||||
});
|
||||
|
||||
test('consultation status no show has correct value', function () {
|
||||
expect(ConsultationStatus::NoShow->value)->toBe('no_show');
|
||||
});
|
||||
|
||||
test('consultation status cancelled has correct value', function () {
|
||||
expect(ConsultationStatus::Cancelled->value)->toBe('cancelled');
|
||||
});
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\ConsultationType;
|
||||
|
||||
test('consultation type has correct cases', function () {
|
||||
expect(ConsultationType::cases())->toHaveCount(2);
|
||||
});
|
||||
|
||||
test('consultation type free has correct value', function () {
|
||||
expect(ConsultationType::Free->value)->toBe('free');
|
||||
});
|
||||
|
||||
test('consultation type paid has correct value', function () {
|
||||
expect(ConsultationType::Paid->value)->toBe('paid');
|
||||
});
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\PaymentStatus;
|
||||
|
||||
test('payment status has correct cases', function () {
|
||||
expect(PaymentStatus::cases())->toHaveCount(3);
|
||||
});
|
||||
|
||||
test('payment status pending has correct value', function () {
|
||||
expect(PaymentStatus::Pending->value)->toBe('pending');
|
||||
});
|
||||
|
||||
test('payment status received has correct value', function () {
|
||||
expect(PaymentStatus::Received->value)->toBe('received');
|
||||
});
|
||||
|
||||
test('payment status not applicable has correct value', function () {
|
||||
expect(PaymentStatus::NotApplicable->value)->toBe('na');
|
||||
});
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\PostStatus;
|
||||
|
||||
test('post status has correct cases', function () {
|
||||
expect(PostStatus::cases())->toHaveCount(2);
|
||||
});
|
||||
|
||||
test('post status draft has correct value', function () {
|
||||
expect(PostStatus::Draft->value)->toBe('draft');
|
||||
});
|
||||
|
||||
test('post status published has correct value', function () {
|
||||
expect(PostStatus::Published->value)->toBe('published');
|
||||
});
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\TimelineStatus;
|
||||
|
||||
test('timeline status has correct cases', function () {
|
||||
expect(TimelineStatus::cases())->toHaveCount(2);
|
||||
});
|
||||
|
||||
test('timeline status active has correct value', function () {
|
||||
expect(TimelineStatus::Active->value)->toBe('active');
|
||||
});
|
||||
|
||||
test('timeline status archived has correct value', function () {
|
||||
expect(TimelineStatus::Archived->value)->toBe('archived');
|
||||
});
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\UserStatus;
|
||||
|
||||
test('user status has correct cases', function () {
|
||||
expect(UserStatus::cases())->toHaveCount(2);
|
||||
});
|
||||
|
||||
test('user status active has correct value', function () {
|
||||
expect(UserStatus::Active->value)->toBe('active');
|
||||
});
|
||||
|
||||
test('user status deactivated has correct value', function () {
|
||||
expect(UserStatus::Deactivated->value)->toBe('deactivated');
|
||||
});
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\UserType;
|
||||
|
||||
test('user type has correct cases', function () {
|
||||
expect(UserType::cases())->toHaveCount(3);
|
||||
});
|
||||
|
||||
test('user type admin has correct value', function () {
|
||||
expect(UserType::Admin->value)->toBe('admin');
|
||||
});
|
||||
|
||||
test('user type individual has correct value', function () {
|
||||
expect(UserType::Individual->value)->toBe('individual');
|
||||
});
|
||||
|
||||
test('user type company has correct value', function () {
|
||||
expect(UserType::Company->value)->toBe('company');
|
||||
});
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\ConsultationStatus;
|
||||
use App\Enums\ConsultationType;
|
||||
use App\Enums\PaymentStatus;
|
||||
use App\Models\Consultation;
|
||||
use App\Models\User;
|
||||
|
||||
test('consultation has correct consultation type cast', function () {
|
||||
$consultation = Consultation::factory()->create(['consultation_type' => 'free']);
|
||||
|
||||
expect($consultation->consultation_type)->toBeInstanceOf(ConsultationType::class)
|
||||
->and($consultation->consultation_type)->toBe(ConsultationType::Free);
|
||||
});
|
||||
|
||||
test('consultation has correct status cast', function () {
|
||||
$consultation = Consultation::factory()->create(['status' => 'pending']);
|
||||
|
||||
expect($consultation->status)->toBeInstanceOf(ConsultationStatus::class)
|
||||
->and($consultation->status)->toBe(ConsultationStatus::Pending);
|
||||
});
|
||||
|
||||
test('consultation has correct payment status cast', function () {
|
||||
$consultation = Consultation::factory()->create(['payment_status' => 'na']);
|
||||
|
||||
expect($consultation->payment_status)->toBeInstanceOf(PaymentStatus::class)
|
||||
->and($consultation->payment_status)->toBe(PaymentStatus::NotApplicable);
|
||||
});
|
||||
|
||||
test('consultation belongs to user', function () {
|
||||
$user = User::factory()->create();
|
||||
$consultation = Consultation::factory()->create(['user_id' => $user->id]);
|
||||
|
||||
expect($consultation->user)->toBeInstanceOf(User::class)
|
||||
->and($consultation->user->id)->toBe($user->id);
|
||||
});
|
||||
|
||||
test('consultation has booking date cast as date', function () {
|
||||
$consultation = Consultation::factory()->create();
|
||||
|
||||
expect($consultation->booking_date)->toBeInstanceOf(\Illuminate\Support\Carbon::class);
|
||||
});
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Post;
|
||||
|
||||
test('post getTitle returns title in specified locale', function () {
|
||||
$post = Post::factory()->create([
|
||||
'title' => ['ar' => 'عنوان عربي', 'en' => 'English Title'],
|
||||
]);
|
||||
|
||||
expect($post->getTitle('ar'))->toBe('عنوان عربي')
|
||||
->and($post->getTitle('en'))->toBe('English Title');
|
||||
});
|
||||
|
||||
test('post getTitle falls back to Arabic when locale missing', function () {
|
||||
$post = Post::factory()->create([
|
||||
'title' => ['ar' => 'عنوان عربي'],
|
||||
]);
|
||||
|
||||
expect($post->getTitle('en'))->toBe('عنوان عربي');
|
||||
});
|
||||
|
||||
test('post getTitle uses current locale by default', function () {
|
||||
$post = Post::factory()->create([
|
||||
'title' => ['ar' => 'عنوان عربي', 'en' => 'English Title'],
|
||||
]);
|
||||
|
||||
app()->setLocale('en');
|
||||
expect($post->getTitle())->toBe('English Title');
|
||||
|
||||
app()->setLocale('ar');
|
||||
expect($post->getTitle())->toBe('عنوان عربي');
|
||||
});
|
||||
|
||||
test('post getBody returns body in specified locale', function () {
|
||||
$post = Post::factory()->create([
|
||||
'body' => ['ar' => 'محتوى عربي', 'en' => 'English Content'],
|
||||
]);
|
||||
|
||||
expect($post->getBody('ar'))->toBe('محتوى عربي')
|
||||
->and($post->getBody('en'))->toBe('English Content');
|
||||
});
|
||||
|
||||
test('post getBody falls back to Arabic when locale missing', function () {
|
||||
$post = Post::factory()->create([
|
||||
'body' => ['ar' => 'محتوى عربي'],
|
||||
]);
|
||||
|
||||
expect($post->getBody('en'))->toBe('محتوى عربي');
|
||||
});
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\TimelineStatus;
|
||||
use App\Models\Timeline;
|
||||
use App\Models\TimelineUpdate;
|
||||
use App\Models\User;
|
||||
|
||||
test('timeline belongs to user', function () {
|
||||
$user = User::factory()->create();
|
||||
$timeline = Timeline::factory()->create(['user_id' => $user->id]);
|
||||
|
||||
expect($timeline->user)->toBeInstanceOf(User::class)
|
||||
->and($timeline->user->id)->toBe($user->id);
|
||||
});
|
||||
|
||||
test('timeline has correct status cast', function () {
|
||||
$timeline = Timeline::factory()->create(['status' => 'active']);
|
||||
|
||||
expect($timeline->status)->toBeInstanceOf(TimelineStatus::class)
|
||||
->and($timeline->status)->toBe(TimelineStatus::Active);
|
||||
});
|
||||
|
||||
test('timeline has many updates', function () {
|
||||
$timeline = Timeline::factory()->create();
|
||||
TimelineUpdate::factory()->count(3)->create(['timeline_id' => $timeline->id]);
|
||||
|
||||
expect($timeline->updates)->toHaveCount(3)
|
||||
->and($timeline->updates->first())->toBeInstanceOf(TimelineUpdate::class);
|
||||
});
|
||||
|
||||
test('timeline update belongs to timeline', function () {
|
||||
$timeline = Timeline::factory()->create();
|
||||
$update = TimelineUpdate::factory()->create(['timeline_id' => $timeline->id]);
|
||||
|
||||
expect($update->timeline)->toBeInstanceOf(Timeline::class)
|
||||
->and($update->timeline->id)->toBe($timeline->id);
|
||||
});
|
||||
|
||||
test('timeline update belongs to admin', function () {
|
||||
$admin = User::factory()->admin()->create();
|
||||
$update = TimelineUpdate::factory()->create(['admin_id' => $admin->id]);
|
||||
|
||||
expect($update->admin)->toBeInstanceOf(User::class)
|
||||
->and($update->admin->id)->toBe($admin->id);
|
||||
});
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\UserStatus;
|
||||
use App\Enums\UserType;
|
||||
use App\Models\User;
|
||||
|
||||
test('user has correct user type cast', function () {
|
||||
$user = User::factory()->create(['user_type' => 'admin']);
|
||||
|
||||
expect($user->user_type)->toBeInstanceOf(UserType::class)
|
||||
->and($user->user_type)->toBe(UserType::Admin);
|
||||
});
|
||||
|
||||
test('user has correct status cast', function () {
|
||||
$user = User::factory()->create(['status' => 'active']);
|
||||
|
||||
expect($user->status)->toBeInstanceOf(UserStatus::class)
|
||||
->and($user->status)->toBe(UserStatus::Active);
|
||||
});
|
||||
|
||||
test('user is admin returns true for admin users', function () {
|
||||
$user = User::factory()->admin()->create();
|
||||
|
||||
expect($user->isAdmin())->toBeTrue()
|
||||
->and($user->isClient())->toBeFalse();
|
||||
});
|
||||
|
||||
test('user is individual returns true for individual users', function () {
|
||||
$user = User::factory()->individual()->create();
|
||||
|
||||
expect($user->isIndividual())->toBeTrue()
|
||||
->and($user->isClient())->toBeTrue();
|
||||
});
|
||||
|
||||
test('user is company returns true for company users', function () {
|
||||
$user = User::factory()->company()->create();
|
||||
|
||||
expect($user->isCompany())->toBeTrue()
|
||||
->and($user->isClient())->toBeTrue();
|
||||
});
|
||||
|
||||
test('user initials are generated correctly', function () {
|
||||
$user = User::factory()->create(['full_name' => 'John Doe']);
|
||||
|
||||
expect($user->initials())->toBe('JD');
|
||||
});
|
||||
|
||||
test('user admins scope returns only admin users', function () {
|
||||
User::factory()->admin()->count(2)->create();
|
||||
User::factory()->individual()->count(3)->create();
|
||||
|
||||
expect(User::admins()->count())->toBe(2);
|
||||
});
|
||||
|
||||
test('user clients scope returns only client users', function () {
|
||||
User::factory()->admin()->count(2)->create();
|
||||
User::factory()->individual()->count(2)->create();
|
||||
User::factory()->company()->count(1)->create();
|
||||
|
||||
expect(User::clients()->count())->toBe(3);
|
||||
});
|
||||
|
||||
test('user active scope returns only active users', function () {
|
||||
User::factory()->count(2)->create();
|
||||
User::factory()->deactivated()->count(1)->create();
|
||||
|
||||
expect(User::active()->count())->toBe(2);
|
||||
});
|
||||
Reference in New Issue
Block a user