mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-06-15 13:32:43 +01:00
Add more tests; Add filter in filament resource; Added options for user create command
This commit is contained in:
committed by
Constantin Graf
parent
84c9cfe2f2
commit
dce608e403
@@ -22,7 +22,8 @@ class UserCreateCommand extends Command
|
|||||||
protected $signature = 'admin:user:create
|
protected $signature = 'admin:user:create
|
||||||
{ name : The name of the user }
|
{ name : The name of the user }
|
||||||
{ email : The email of the user }
|
{ email : The email of the user }
|
||||||
{ --ask-for-password : Ask for the password, otherwise the command will generate a random one }';
|
{ --ask-for-password : Ask for the password, otherwise the command will generate a random one }
|
||||||
|
{ --verify-email : Verify the email address of the user }';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The console command description.
|
* The console command description.
|
||||||
@@ -39,6 +40,7 @@ class UserCreateCommand extends Command
|
|||||||
$name = $this->argument('name');
|
$name = $this->argument('name');
|
||||||
$email = $this->argument('email');
|
$email = $this->argument('email');
|
||||||
$askForPassword = (bool) $this->option('ask-for-password');
|
$askForPassword = (bool) $this->option('ask-for-password');
|
||||||
|
$verifyEmail = (bool) $this->option('verify-email');
|
||||||
|
|
||||||
if (User::query()->where('email', $email)->where('is_placeholder', '=', false)->exists()) {
|
if (User::query()->where('email', $email)->where('is_placeholder', '=', false)->exists()) {
|
||||||
$this->error('User with email "'.$email.'" already exists.');
|
$this->error('User with email "'.$email.'" already exists.');
|
||||||
@@ -71,6 +73,10 @@ class UserCreateCommand extends Command
|
|||||||
throw new LogicException('User does not have an organization');
|
throw new LogicException('User does not have an organization');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($verifyEmail) {
|
||||||
|
$user->markEmailAsVerified();
|
||||||
|
}
|
||||||
|
|
||||||
$this->info('Created user "'.$name.'" ("'.$email.'")');
|
$this->info('Created user "'.$name.'" ("'.$email.'")');
|
||||||
$this->line('ID: '.$user->getKey());
|
$this->line('ID: '.$user->getKey());
|
||||||
$this->line('Name: '.$name);
|
$this->line('Name: '.$name);
|
||||||
|
|||||||
@@ -60,8 +60,13 @@ class ClientResource extends Resource
|
|||||||
->defaultSort('created_at', 'desc')
|
->defaultSort('created_at', 'desc')
|
||||||
->filters([
|
->filters([
|
||||||
SelectFilter::make('organization')
|
SelectFilter::make('organization')
|
||||||
|
->label('Organization')
|
||||||
->relationship('organization', 'name')
|
->relationship('organization', 'name')
|
||||||
->searchable(),
|
->searchable(),
|
||||||
|
SelectFilter::make('organization_id')
|
||||||
|
->label('Organization ID')
|
||||||
|
->relationship('organization', 'id')
|
||||||
|
->searchable(),
|
||||||
])
|
])
|
||||||
->actions([
|
->actions([
|
||||||
Tables\Actions\EditAction::make(),
|
Tables\Actions\EditAction::make(),
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||||||
namespace App\Filament\Resources\OrganizationInvitationResource\Pages;
|
namespace App\Filament\Resources\OrganizationInvitationResource\Pages;
|
||||||
|
|
||||||
use App\Filament\Resources\OrganizationInvitationResource;
|
use App\Filament\Resources\OrganizationInvitationResource;
|
||||||
|
use Filament\Actions;
|
||||||
use Filament\Resources\Pages\EditRecord;
|
use Filament\Resources\Pages\EditRecord;
|
||||||
|
|
||||||
class EditOrganizationInvitation extends EditRecord
|
class EditOrganizationInvitation extends EditRecord
|
||||||
@@ -14,6 +15,8 @@ class EditOrganizationInvitation extends EditRecord
|
|||||||
protected function getHeaderActions(): array
|
protected function getHeaderActions(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
Actions\DeleteAction::make()
|
||||||
|
->icon('heroicon-m-trash'),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ class UsersRelationManager extends RelationManager
|
|||||||
])
|
])
|
||||||
->headerActions([
|
->headerActions([
|
||||||
Tables\Actions\AttachAction::make()
|
Tables\Actions\AttachAction::make()
|
||||||
|
->recordTitle(fn (User $record): string => "{$record->name} ({$record->email})")
|
||||||
->form(fn (AttachAction $action): array => [
|
->form(fn (AttachAction $action): array => [
|
||||||
$action->getRecordSelect(),
|
$action->getRecordSelect(),
|
||||||
Select::make('role')
|
Select::make('role')
|
||||||
|
|||||||
@@ -72,8 +72,13 @@ class ProjectResource extends Resource
|
|||||||
])
|
])
|
||||||
->filters([
|
->filters([
|
||||||
SelectFilter::make('organization')
|
SelectFilter::make('organization')
|
||||||
|
->label('Organization')
|
||||||
->relationship('organization', 'name')
|
->relationship('organization', 'name')
|
||||||
->searchable(),
|
->searchable(),
|
||||||
|
SelectFilter::make('organization_id')
|
||||||
|
->label('Organization ID')
|
||||||
|
->relationship('organization', 'id')
|
||||||
|
->searchable(),
|
||||||
])
|
])
|
||||||
->defaultSort('created_at', 'desc')
|
->defaultSort('created_at', 'desc')
|
||||||
->actions([
|
->actions([
|
||||||
|
|||||||
@@ -101,8 +101,13 @@ class ReportResource extends Resource
|
|||||||
->defaultSort('created_at', 'desc')
|
->defaultSort('created_at', 'desc')
|
||||||
->filters([
|
->filters([
|
||||||
SelectFilter::make('organization')
|
SelectFilter::make('organization')
|
||||||
|
->label('Organization')
|
||||||
->relationship('organization', 'name')
|
->relationship('organization', 'name')
|
||||||
->searchable(),
|
->searchable(),
|
||||||
|
SelectFilter::make('organization_id')
|
||||||
|
->label('Organization ID')
|
||||||
|
->relationship('organization', 'id')
|
||||||
|
->searchable(),
|
||||||
])
|
])
|
||||||
->actions([
|
->actions([
|
||||||
Action::make('public-view')
|
Action::make('public-view')
|
||||||
|
|||||||
@@ -60,8 +60,13 @@ class TagResource extends Resource
|
|||||||
->defaultSort('created_at', 'desc')
|
->defaultSort('created_at', 'desc')
|
||||||
->filters([
|
->filters([
|
||||||
SelectFilter::make('organization')
|
SelectFilter::make('organization')
|
||||||
|
->label('Organization')
|
||||||
->relationship('organization', 'name')
|
->relationship('organization', 'name')
|
||||||
->searchable(),
|
->searchable(),
|
||||||
|
SelectFilter::make('organization_id')
|
||||||
|
->label('Organization ID')
|
||||||
|
->relationship('organization', 'id')
|
||||||
|
->searchable(),
|
||||||
])
|
])
|
||||||
->actions([
|
->actions([
|
||||||
Tables\Actions\EditAction::make(),
|
Tables\Actions\EditAction::make(),
|
||||||
|
|||||||
@@ -61,8 +61,13 @@ class TaskResource extends Resource
|
|||||||
])
|
])
|
||||||
->filters([
|
->filters([
|
||||||
SelectFilter::make('organization')
|
SelectFilter::make('organization')
|
||||||
|
->label('Organization')
|
||||||
->relationship('organization', 'name')
|
->relationship('organization', 'name')
|
||||||
->searchable(),
|
->searchable(),
|
||||||
|
SelectFilter::make('organization_id')
|
||||||
|
->label('Organization ID')
|
||||||
|
->relationship('organization', 'id')
|
||||||
|
->searchable(),
|
||||||
])
|
])
|
||||||
->defaultSort('created_at', 'desc')
|
->defaultSort('created_at', 'desc')
|
||||||
->actions([
|
->actions([
|
||||||
|
|||||||
@@ -92,8 +92,13 @@ class TimeEntryResource extends Resource
|
|||||||
])
|
])
|
||||||
->filters([
|
->filters([
|
||||||
SelectFilter::make('organization')
|
SelectFilter::make('organization')
|
||||||
|
->label('Organization')
|
||||||
->relationship('organization', 'name')
|
->relationship('organization', 'name')
|
||||||
->searchable(),
|
->searchable(),
|
||||||
|
SelectFilter::make('organization_id')
|
||||||
|
->label('Organization ID')
|
||||||
|
->relationship('organization', 'id')
|
||||||
|
->searchable(),
|
||||||
])
|
])
|
||||||
->defaultSort('created_at', 'desc')
|
->defaultSort('created_at', 'desc')
|
||||||
->actions([
|
->actions([
|
||||||
|
|||||||
@@ -196,6 +196,7 @@ class ImportDatabaseHelper
|
|||||||
if ($this->mapKeyToModel === null) {
|
if ($this->mapKeyToModel === null) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
return array_values($this->mapKeyToModel);
|
return array_values($this->mapKeyToModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,8 +28,10 @@ class OrganizationDeleteCommandTest extends TestCaseWithDatabase
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
$this->artisan('admin:organization:delete', ['organization' => $organization->getKey()])
|
$command = $this->artisan('admin:organization:delete', ['organization' => $organization->getKey()]);
|
||||||
->expectsOutput("Deleting organization with ID {$organization->getKey()}")
|
|
||||||
|
// Assert
|
||||||
|
$command->expectsOutput("Deleting organization with ID {$organization->getKey()}")
|
||||||
->expectsOutput("Organization with ID {$organization->getKey()} has been deleted.")
|
->expectsOutput("Organization with ID {$organization->getKey()} has been deleted.")
|
||||||
->assertExitCode(0);
|
->assertExitCode(0);
|
||||||
}
|
}
|
||||||
@@ -40,9 +42,11 @@ class OrganizationDeleteCommandTest extends TestCaseWithDatabase
|
|||||||
$organizationId = Str::uuid()->toString();
|
$organizationId = Str::uuid()->toString();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
$this->artisan('admin:organization:delete', ['organization' => $organizationId])
|
$command = $this->artisan('admin:organization:delete', ['organization' => $organizationId]);
|
||||||
->expectsOutput('Organization with ID '.$organizationId.' not found.')
|
|
||||||
->assertExitCode(1);
|
// Assert
|
||||||
|
$command->expectsOutput('Organization with ID '.$organizationId.' not found.');
|
||||||
|
$command->assertExitCode(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_it_fails_if_organization_id_is_not_a_valid_uuid(): void
|
public function test_it_fails_if_organization_id_is_not_a_valid_uuid(): void
|
||||||
@@ -51,8 +55,10 @@ class OrganizationDeleteCommandTest extends TestCaseWithDatabase
|
|||||||
$organizationId = 'invalid-uuid';
|
$organizationId = 'invalid-uuid';
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
$this->artisan('admin:organization:delete', ['organization' => $organizationId])
|
$command = $this->artisan('admin:organization:delete', ['organization' => $organizationId]);
|
||||||
->expectsOutput('Organization ID must be a valid UUID.')
|
|
||||||
|
// Assert
|
||||||
|
$command->expectsOutput('Organization ID must be a valid UUID.')
|
||||||
->assertExitCode(1);
|
->assertExitCode(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,114 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Tests\Unit\Console\Commands\Admin;
|
||||||
|
|
||||||
|
use App\Console\Commands\Admin\UserCreateCommand;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use Illuminate\Support\Facades\Artisan;
|
||||||
|
use Illuminate\Support\Facades\Hash;
|
||||||
|
use PHPUnit\Framework\Attributes\CoversClass;
|
||||||
|
use PHPUnit\Framework\Attributes\UsesClass;
|
||||||
|
use Tests\TestCaseWithDatabase;
|
||||||
|
|
||||||
|
#[CoversClass(UserCreateCommand::class)]
|
||||||
|
#[UsesClass(UserCreateCommand::class)]
|
||||||
|
class UserCreateCommandCommandTest extends TestCaseWithDatabase
|
||||||
|
{
|
||||||
|
public function test_it_creates_user(): void
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
$email = 'mail@testuser.test';
|
||||||
|
$name = 'Test User';
|
||||||
|
|
||||||
|
// Act
|
||||||
|
$exitCode = $this->withoutMockingConsoleOutput()->artisan('admin:user:create', [
|
||||||
|
'name' => $name,
|
||||||
|
'email' => $email,
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
$this->assertSame(Command::SUCCESS, $exitCode);
|
||||||
|
$output = Artisan::output();
|
||||||
|
$this->assertStringContainsString('Created user "'.$name.'" ("'.$email.'")', $output);
|
||||||
|
$this->assertDatabaseHas(User::class, [
|
||||||
|
'name' => $name,
|
||||||
|
'email' => $email,
|
||||||
|
'email_verified_at' => null,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_created_user_is_verified_if_option_is_set(): void
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
$email = 'mail@testuser.test';
|
||||||
|
$name = 'Test User';
|
||||||
|
|
||||||
|
// Act
|
||||||
|
$exitCode = $this->withoutMockingConsoleOutput()->artisan('admin:user:create', [
|
||||||
|
'name' => $name,
|
||||||
|
'email' => $email,
|
||||||
|
'--verify-email' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
$this->assertSame(Command::SUCCESS, $exitCode);
|
||||||
|
$output = Artisan::output();
|
||||||
|
$this->assertStringContainsString('Created user "'.$name.'" ("'.$email.'")', $output);
|
||||||
|
$this->assertDatabaseHas(User::class, [
|
||||||
|
'name' => $name,
|
||||||
|
'email' => $email,
|
||||||
|
]);
|
||||||
|
$user = User::where('email', $email)->first();
|
||||||
|
$this->assertNotNull($user->email_verified_at);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_it_fails_if_user_with_email_already_exists(): void
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
$email = 'mail@testuser.test';
|
||||||
|
$name = 'Test User';
|
||||||
|
|
||||||
|
User::factory()->create([
|
||||||
|
'email' => $email,
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
$exitCode = $this->withoutMockingConsoleOutput()->artisan('admin:user:create', [
|
||||||
|
'name' => $name,
|
||||||
|
'email' => $email,
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
$this->assertSame(Command::FAILURE, $exitCode);
|
||||||
|
$output = Artisan::output();
|
||||||
|
$this->assertStringContainsString('User with email "'.$email.'" already exists.', $output);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_it_asks_for_password_if_option_is_set(): void
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
$email = 'mail@testuser.test';
|
||||||
|
$name = 'Test User';
|
||||||
|
|
||||||
|
// Act
|
||||||
|
$this->artisan('admin:user:create', [
|
||||||
|
'name' => $name,
|
||||||
|
'email' => $email,
|
||||||
|
'--ask-for-password' => true,
|
||||||
|
])
|
||||||
|
->expectsQuestion('Enter the password', 'password')
|
||||||
|
->assertExitCode(Command::SUCCESS);
|
||||||
|
|
||||||
|
$this->assertDatabaseHas(User::class, [
|
||||||
|
'name' => $name,
|
||||||
|
'email' => $email,
|
||||||
|
'email_verified_at' => null,
|
||||||
|
]);
|
||||||
|
$user = User::where('email', $email)->first();
|
||||||
|
$this->assertNotNull($user->password);
|
||||||
|
$this->assertTrue(Hash::check('password', $user->password));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -29,7 +29,6 @@ class UserVerifyCommandTest extends TestCaseWithDatabase
|
|||||||
$command = $this->artisan('admin:user:verify', ['email' => $user->email]);
|
$command = $this->artisan('admin:user:verify', ['email' => $user->email]);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
|
|
||||||
$command->expectsOutput('Start verifying user with email "'.$user->email.'"')
|
$command->expectsOutput('Start verifying user with email "'.$user->email.'"')
|
||||||
->expectsOutput('User with email "'.$user->email.'" has been verified.')
|
->expectsOutput('User with email "'.$user->email.'" has been verified.')
|
||||||
->assertExitCode(0);
|
->assertExitCode(0);
|
||||||
|
|||||||
@@ -0,0 +1,78 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Tests\Unit\Filament\Resources;
|
||||||
|
|
||||||
|
use App\Filament\Resources\OrganizationInvitationResource;
|
||||||
|
use App\Models\Organization;
|
||||||
|
use App\Models\OrganizationInvitation;
|
||||||
|
use App\Models\User;
|
||||||
|
use Filament\Actions\DeleteAction;
|
||||||
|
use Illuminate\Support\Facades\Config;
|
||||||
|
use Livewire\Livewire;
|
||||||
|
use PHPUnit\Framework\Attributes\UsesClass;
|
||||||
|
use Tests\Unit\Filament\FilamentTestCase;
|
||||||
|
|
||||||
|
#[UsesClass(OrganizationInvitationResource::class)]
|
||||||
|
class OrganizationInvitationResourceTest extends FilamentTestCase
|
||||||
|
{
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
Config::set('auth.super_admins', ['admin@example.com']);
|
||||||
|
$user = User::factory()->withPersonalOrganization()->create([
|
||||||
|
'email' => 'admin@example.com',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->actingAs($user);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_can_list_organization_invitations(): void
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$organization = Organization::factory()->withOwner($user)->create();
|
||||||
|
$organizationInvitations = OrganizationInvitation::factory()->forOrganization($organization)->createMany(5);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
$response = Livewire::test(OrganizationInvitationResource\Pages\ListOrganizationInvitations::class);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
$response->assertSuccessful();
|
||||||
|
$response->assertCanSeeTableRecords($organizationInvitations);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_can_see_edit_page_of_organization_invitation(): void
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
$organization = Organization::factory()->create();
|
||||||
|
$organizationInvitation = OrganizationInvitation::factory()->forOrganization($organization)->create();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
$response = Livewire::test(OrganizationInvitationResource\Pages\EditOrganizationInvitation::class, [
|
||||||
|
'record' => $organizationInvitation->getKey(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
$response->assertSuccessful();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_can_delete_a_organization_invitation(): void
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
$organization = Organization::factory()->create();
|
||||||
|
$organizationInvitation = OrganizationInvitation::factory()->forOrganization($organization)->create();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
$response = Livewire::test(OrganizationInvitationResource\Pages\EditOrganizationInvitation::class, [
|
||||||
|
'record' => $organizationInvitation->getKey(),
|
||||||
|
])->callAction(DeleteAction::class);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
$response->assertSuccessful();
|
||||||
|
$this->assertDatabaseMissing(OrganizationInvitation::class, [
|
||||||
|
'id' => $organizationInvitation->getKey(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ namespace Tests\Unit\Filament\Resources;
|
|||||||
|
|
||||||
use App\Filament\Resources\OrganizationResource;
|
use App\Filament\Resources\OrganizationResource;
|
||||||
use App\Models\Organization;
|
use App\Models\Organization;
|
||||||
|
use App\Models\OrganizationInvitation;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Service\DeletionService;
|
use App\Service\DeletionService;
|
||||||
use Illuminate\Support\Facades\Config;
|
use Illuminate\Support\Facades\Config;
|
||||||
@@ -74,4 +75,41 @@ class OrganizationResourceTest extends FilamentTestCase
|
|||||||
// Assert
|
// Assert
|
||||||
$response->assertSuccessful();
|
$response->assertSuccessful();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_can_list_related_users(): void
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
$organization = Organization::factory()->create();
|
||||||
|
$user1 = User::factory()->create();
|
||||||
|
$user2 = User::factory()->create();
|
||||||
|
$organization->users()->attach($user1);
|
||||||
|
$organization->users()->attach($user2);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
$response = Livewire::test(OrganizationResource\RelationManagers\UsersRelationManager::class, [
|
||||||
|
'ownerRecord' => $organization,
|
||||||
|
'pageClass' => OrganizationResource\Pages\EditOrganization::class,
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
$response->assertSuccessful();
|
||||||
|
$response->assertCanSeeTableRecords($organization->users()->get());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_can_list_related_invitations(): void
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
$organization = Organization::factory()->create();
|
||||||
|
$organizationInvitations = OrganizationInvitation::factory()->forOrganization($organization)->createMany(5);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
$response = Livewire::test(OrganizationResource\RelationManagers\InvitationsRelationManager::class, [
|
||||||
|
'ownerRecord' => $organization,
|
||||||
|
'pageClass' => OrganizationResource\Pages\EditOrganization::class,
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
$response->assertSuccessful();
|
||||||
|
$response->assertCanSeeTableRecords($organizationInvitations);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
55
tests/Unit/Filament/Resources/ReportResourceTest.php
Normal file
55
tests/Unit/Filament/Resources/ReportResourceTest.php
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Tests\Unit\Filament\Resources;
|
||||||
|
|
||||||
|
use App\Filament\Resources\ReportResource;
|
||||||
|
use App\Models\Report;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Support\Facades\Config;
|
||||||
|
use Livewire\Livewire;
|
||||||
|
use PHPUnit\Framework\Attributes\UsesClass;
|
||||||
|
use Tests\Unit\Filament\FilamentTestCase;
|
||||||
|
|
||||||
|
#[UsesClass(ReportResource::class)]
|
||||||
|
class ReportResourceTest extends FilamentTestCase
|
||||||
|
{
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
Config::set('auth.super_admins', ['admin@example.com']);
|
||||||
|
$user = User::factory()->withPersonalOrganization()->create([
|
||||||
|
'email' => 'admin@example.com',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->actingAs($user);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_can_list_reports(): void
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
$reports = Report::factory()->createMany(5);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
$response = Livewire::test(ReportResource\Pages\ListReports::class);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
$response->assertSuccessful();
|
||||||
|
$response->assertCanSeeTableRecords($reports);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_can_see_edit_page_of_report(): void
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
$report = Report::factory()->create();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
$response = Livewire::test(ReportResource\Pages\EditReport::class, [
|
||||||
|
'record' => $report->getKey(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
$response->assertSuccessful();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@ namespace Tests\Unit\Filament\Resources;
|
|||||||
use App\Exceptions\Api\CanNotDeleteUserWhoIsOwnerOfOrganizationWithMultipleMembers;
|
use App\Exceptions\Api\CanNotDeleteUserWhoIsOwnerOfOrganizationWithMultipleMembers;
|
||||||
use App\Filament\Resources\TimeEntryResource;
|
use App\Filament\Resources\TimeEntryResource;
|
||||||
use App\Filament\Resources\UserResource;
|
use App\Filament\Resources\UserResource;
|
||||||
|
use App\Models\Organization;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Service\DeletionService;
|
use App\Service\DeletionService;
|
||||||
use Illuminate\Support\Facades\Config;
|
use Illuminate\Support\Facades\Config;
|
||||||
@@ -54,6 +55,18 @@ class UserResourceTest extends FilamentTestCase
|
|||||||
$response->assertSuccessful();
|
$response->assertSuccessful();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_can_see_view_page_of_user(): void
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
$user = User::factory()->create();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
$response = Livewire::test(UserResource\Pages\ViewUser::class, ['record' => $user->getKey()]);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
$response->assertSuccessful();
|
||||||
|
}
|
||||||
|
|
||||||
public function test_can_delete_a_user(): void
|
public function test_can_delete_a_user(): void
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
@@ -91,4 +104,42 @@ class UserResourceTest extends FilamentTestCase
|
|||||||
$response->assertNotified(__('exceptions.api.can_not_delete_user_who_is_owner_of_organization_with_multiple_members'));
|
$response->assertNotified(__('exceptions.api.can_not_delete_user_who_is_owner_of_organization_with_multiple_members'));
|
||||||
$response->assertSuccessful();
|
$response->assertSuccessful();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_can_list_related_organizations(): void
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$ownedOrganization = Organization::factory()->withOwner($user)->create();
|
||||||
|
$organization = Organization::factory()->create();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
$response = Livewire::test(UserResource\RelationManagers\OrganizationsRelationManager::class, [
|
||||||
|
'ownerRecord' => $user,
|
||||||
|
'pageClass' => UserResource\Pages\EditUser::class,
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
$response->assertSuccessful();
|
||||||
|
$response->assertCanSeeTableRecords($user->organizations()->get());
|
||||||
|
$response->assertCanNotSeeTableRecords($user->ownedTeams()->get());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_can_list_related_owned_organizations(): void
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$ownedOrganization = Organization::factory()->withOwner($user)->create();
|
||||||
|
$organization = Organization::factory()->create();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
$response = Livewire::test(UserResource\RelationManagers\OwnedOrganizationsRelationManager::class, [
|
||||||
|
'ownerRecord' => $user,
|
||||||
|
'pageClass' => UserResource\Pages\EditUser::class,
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
$response->assertSuccessful();
|
||||||
|
$response->assertCanSeeTableRecords($user->ownedTeams()->get());
|
||||||
|
$response->assertCanNotSeeTableRecords($user->organizations()->get());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -229,4 +229,23 @@ class ImportDatabaseHelperTest extends TestCase
|
|||||||
// Assert
|
// Assert
|
||||||
$this->assertSame($user->getKey(), $model1->getKey());
|
$this->assertSame($user->getKey(), $model1->getKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_get_cached_models_returns_all_models_where_the_helper_already_fetched_the_model(): void
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
$user1 = User::factory()->create();
|
||||||
|
$user2 = User::factory()->create();
|
||||||
|
$helper = new ImportDatabaseHelper(User::class, ['email'], true);
|
||||||
|
$helper->getModelById($user1->getKey());
|
||||||
|
$helper->getModelById($user2->getKey());
|
||||||
|
$helper->getModelById($user1->getKey());
|
||||||
|
|
||||||
|
// Act
|
||||||
|
$models = $helper->getCachedModels();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
$this->assertCount(2, $models);
|
||||||
|
$this->assertContains($user1->getKey(), collect($models)->pluck('id')->toArray());
|
||||||
|
$this->assertContains($user2->getKey(), collect($models)->pluck('id')->toArray());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ class TimezoneServiceTest extends TestCase
|
|||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
$this->assertIsArray($result);
|
$this->assertIsArray($result);
|
||||||
$this->assertCount(419, $result);
|
$this->assertTrue(in_array(count($result), [418, 419], true));
|
||||||
$this->assertContains('Europe/Vienna', $result);
|
$this->assertContains('Europe/Vienna', $result);
|
||||||
$this->assertContains('Europe/Berlin', $result);
|
$this->assertContains('Europe/Berlin', $result);
|
||||||
$this->assertContains('Europe/London', $result);
|
$this->assertContains('Europe/London', $result);
|
||||||
|
|||||||
Reference in New Issue
Block a user