chore: run pint
This commit is contained in:
parent
5399505808
commit
87e25c9591
@ -58,7 +58,7 @@ function mountCreateComponent(User $user): Testable
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('prevents create when user is unauthorized', function () {
|
it('prevents create when user is unauthorized', function () {
|
||||||
Gate::define('create user', fn() => false);
|
Gate::define('create user', fn () => false);
|
||||||
|
|
||||||
mountCreateComponent($this->user)
|
mountCreateComponent($this->user)
|
||||||
->call('save')
|
->call('save')
|
||||||
@ -314,7 +314,7 @@ function mountCreateComponent(User $user): Testable
|
|||||||
$this->user->givePermissionTo($permission);
|
$this->user->givePermissionTo($permission);
|
||||||
|
|
||||||
mountCreateComponent($this->user)
|
mountCreateComponent($this->user)
|
||||||
->set('form.email', str_repeat('a', 90) . '@example.com')
|
->set('form.email', str_repeat('a', 90).'@example.com')
|
||||||
->call('save')
|
->call('save')
|
||||||
->assertHasErrors(['form.email']);
|
->assertHasErrors(['form.email']);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -28,7 +28,7 @@ function createEditUser(array $attributes = []): User
|
|||||||
return User::factory()
|
return User::factory()
|
||||||
->active()
|
->active()
|
||||||
->has(Employee::factory())
|
->has(Employee::factory())
|
||||||
->state(fn() => array_merge([
|
->state(fn () => array_merge([
|
||||||
'status' => fake()->randomElement(UserStatus::cases()),
|
'status' => fake()->randomElement(UserStatus::cases()),
|
||||||
], $attributes))
|
], $attributes))
|
||||||
->create();
|
->create();
|
||||||
@ -122,7 +122,7 @@ function mountEditComponent(User $user, User $employeeUser): Testable
|
|||||||
$employeeUser = createEditUser();
|
$employeeUser = createEditUser();
|
||||||
$employeeUser->assignRole($role->id);
|
$employeeUser->assignRole($role->id);
|
||||||
|
|
||||||
Gate::define('update user', fn() => false);
|
Gate::define('update user', fn () => false);
|
||||||
|
|
||||||
mountEditComponent($this->user, $employeeUser)
|
mountEditComponent($this->user, $employeeUser)
|
||||||
->call('save')
|
->call('save')
|
||||||
|
|||||||
@ -5,7 +5,6 @@
|
|||||||
use App\Models\Employee;
|
use App\Models\Employee;
|
||||||
use App\Models\Outlet;
|
use App\Models\Outlet;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Database\Eloquent\Collection;
|
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
use Livewire\Features\SupportTesting\Testable;
|
use Livewire\Features\SupportTesting\Testable;
|
||||||
use Livewire\Livewire;
|
use Livewire\Livewire;
|
||||||
@ -15,7 +14,7 @@
|
|||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
// Create roles for testing
|
// Create roles for testing
|
||||||
collect(['Developer', 'Owner', 'Leader', 'Admin', 'Partner', 'Customer'])
|
collect(['Developer', 'Owner', 'Leader', 'Admin', 'Partner', 'Customer'])
|
||||||
->each(fn($role) => \Spatie\Permission\Models\Role::create(['name' => $role]));
|
->each(fn ($role) => \Spatie\Permission\Models\Role::create(['name' => $role]));
|
||||||
|
|
||||||
$this->user = User::factory()
|
$this->user = User::factory()
|
||||||
->active()
|
->active()
|
||||||
@ -30,7 +29,7 @@ function createUser(array $attributes = []): User
|
|||||||
return User::factory()
|
return User::factory()
|
||||||
->active()
|
->active()
|
||||||
->has(Employee::factory())
|
->has(Employee::factory())
|
||||||
->state(fn() => array_merge([
|
->state(fn () => array_merge([
|
||||||
'status' => fake()->randomElement(UserStatus::cases()),
|
'status' => fake()->randomElement(UserStatus::cases()),
|
||||||
], $attributes))
|
], $attributes))
|
||||||
->create();
|
->create();
|
||||||
@ -64,7 +63,7 @@ function mountIndexComponent(User $user): Testable
|
|||||||
$user->outlets()->attach($outlet->id);
|
$user->outlets()->attach($outlet->id);
|
||||||
|
|
||||||
$component = mountIndexComponent($this->user);
|
$component = mountIndexComponent($this->user);
|
||||||
$loadedEmployee = $component->get('employees')->first(fn($emp) => $emp->user_id === $user->id);
|
$loadedEmployee = $component->get('employees')->first(fn ($emp) => $emp->user_id === $user->id);
|
||||||
|
|
||||||
expect($loadedEmployee)->not->toBeNull()
|
expect($loadedEmployee)->not->toBeNull()
|
||||||
->and($loadedEmployee->relationLoaded('user'))->toBeTrue()
|
->and($loadedEmployee->relationLoaded('user'))->toBeTrue()
|
||||||
@ -125,7 +124,7 @@ function mountIndexComponent(User $user): Testable
|
|||||||
$filteredComponent = mountIndexComponent($this->user)->set('status', [UserStatus::ACTIVE->value]);
|
$filteredComponent = mountIndexComponent($this->user)->set('status', [UserStatus::ACTIVE->value]);
|
||||||
|
|
||||||
expect(count($filteredComponent->get('employees')))->toBeGreaterThanOrEqual(1); // At least the active user
|
expect(count($filteredComponent->get('employees')))->toBeGreaterThanOrEqual(1); // At least the active user
|
||||||
expect($filteredComponent->get('employees')->contains(fn($emp) => $emp->user->status->value === UserStatus::ACTIVE->value))->toBeTrue();
|
expect($filteredComponent->get('employees')->contains(fn ($emp) => $emp->user->status->value === UserStatus::ACTIVE->value))->toBeTrue();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('filters employees by multiple statuses', function () {
|
it('filters employees by multiple statuses', function () {
|
||||||
@ -162,7 +161,7 @@ function mountIndexComponent(User $user): Testable
|
|||||||
$user->outlets()->attach($outlet->id);
|
$user->outlets()->attach($outlet->id);
|
||||||
|
|
||||||
$component = mountIndexComponent($this->user);
|
$component = mountIndexComponent($this->user);
|
||||||
$loadedEmployee = $component->get('employees')->first(fn($emp) => $emp->user_id === $user->id);
|
$loadedEmployee = $component->get('employees')->first(fn ($emp) => $emp->user_id === $user->id);
|
||||||
|
|
||||||
expect($loadedEmployee)->not->toBeNull()
|
expect($loadedEmployee)->not->toBeNull()
|
||||||
->and($loadedEmployee->user->outlets)->toHaveCount(1)
|
->and($loadedEmployee->user->outlets)->toHaveCount(1)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user