diff --git a/tests/Feature/Filament/Resources/Master/Classifications/ClassificationResourceTest.php b/tests/Feature/Filament/Resources/Master/Classifications/ClassificationResourceTest.php deleted file mode 100644 index 564bd75..0000000 --- a/tests/Feature/Filament/Resources/Master/Classifications/ClassificationResourceTest.php +++ /dev/null @@ -1,199 +0,0 @@ -user = User::factory()->create(['is_active' => IsActive::ACTIVE]); - - // Setup Permissions - Permission::firstOrCreate(['name' => 'ViewAny:Classification', 'guard_name' => 'web']); - Permission::firstOrCreate(['name' => 'Create:Classification', 'guard_name' => 'web']); - Permission::firstOrCreate(['name' => 'Update:Classification', 'guard_name' => 'web']); - Permission::firstOrCreate(['name' => 'Delete:Classification', 'guard_name' => 'web']); - Permission::firstOrCreate(['name' => 'Restore:Classification', 'guard_name' => 'web']); - Permission::firstOrCreate(['name' => 'ForceDelete:Classification', 'guard_name' => 'web']); - - $this->user->givePermissionTo([ - 'ViewAny:Classification', - 'Create:Classification', - 'Update:Classification', - 'Delete:Classification', - 'Restore:Classification', - 'ForceDelete:Classification', - ]); -}); - -test('can render classification list page', function () { - $this->actingAs($this->user); - - Livewire::test(ManageClassifications::class) - ->assertSuccessful(); -}); - -test('can list classifications', function () { - $classifications = Classification::factory()->count(5)->create(); - - $this->actingAs($this->user); - - Livewire::test(ManageClassifications::class) - ->call('loadTable') - ->assertCanSeeTableRecords($classifications); -}); - -test('can create classification', function () { - $this->actingAs($this->user); - - Livewire::test(ManageClassifications::class) - ->mountAction('create') - ->setActionData([ - 'name' => 'Klasifikasi Baru', - ]) - ->callMountedAction() - ->assertHasNoActionErrors(); - - $this->assertDatabaseHas('classifications', [ - 'name' => 'Klasifikasi Baru', - 'is_active' => IsActive::ACTIVE->value, - ]); -}); - -test('cannot create classification with empty name', function () { - $this->actingAs($this->user); - - Livewire::test(ManageClassifications::class) - ->mountAction('create') - ->setActionData(['name' => '']) - ->callMountedAction() - ->assertHasActionErrors(['name' => 'required']); -}); - -test('cannot create classification with name exceeding 50 characters', function () { - $this->actingAs($this->user); - - Livewire::test(ManageClassifications::class) - ->mountAction('create') - ->setActionData(['name' => str_repeat('a', 51)]) - ->callMountedAction() - ->assertHasActionErrors(['name' => 'max']); -}); - -test('can edit classification', function () { - $classification = Classification::factory()->create(); - - $this->actingAs($this->user); - - Livewire::test(ManageClassifications::class) - ->mountTableAction('edit', $classification) - ->setActionData([ - 'name' => 'Klasifikasi Updated', - ]) - ->callMountedTableAction() - ->assertHasNoActionErrors(); - - expect($classification->refresh()->name)->toBe('Klasifikasi Updated'); -}); - -test('can toggle is_active status', function () { - $classification = Classification::factory()->create(['is_active' => IsActive::INACTIVE]); - - $this->actingAs($this->user); - - Livewire::test(ManageClassifications::class) - ->call('updateTableColumnState', 'is_active', $classification->getKey(), true); - - expect($classification->refresh()->is_active)->toBe(IsActive::ACTIVE); -}); - -test('unauthorized user cannot render classification page', function () { - $unauthorizedUser = User::factory()->create(['is_active' => IsActive::ACTIVE]); - - $this->actingAs($unauthorizedUser); - - Livewire::test(ManageClassifications::class) - ->assertForbidden(); -}); - -test('user without create permission cannot see create action', function () { - $viewOnlyUser = User::factory()->create(['is_active' => IsActive::ACTIVE]); - $viewOnlyUser->givePermissionTo('ViewAny:Classification'); - $classification = Classification::factory()->create(); - - $this->actingAs($viewOnlyUser); - - Livewire::test(ManageClassifications::class) - ->assertActionHidden('create') - ->assertTableActionHidden('edit', $classification); -}); - -test('can delete classification', function () { - $classification = Classification::factory()->create(); - - $this->actingAs($this->user); - - Livewire::test(ManageClassifications::class) - ->callTableAction('delete', $classification); - - $this->assertSoftDeleted($classification); -}); - -test('can restore deleted classification', function () { - // Need Developer role to see trashed records via filter - $roleDev = Role::firstOrCreate(['name' => RoleEnum::DEVELOPER->value, 'guard_name' => 'web']); - $this->user->assignRole($roleDev); - - $classification = Classification::factory()->create(['deleted_at' => now()]); - - $this->actingAs($this->user); - - Livewire::test(ManageClassifications::class) - ->filterTable('trashed', 'with') - ->callTableAction('restore', $classification); - - $this->assertDatabaseHas('classifications', [ - 'id' => $classification->id, - 'deleted_at' => null, - ]); -}); - -test('can force delete classification', function () { - $roleDev = Role::firstOrCreate(['name' => RoleEnum::DEVELOPER->value, 'guard_name' => 'web']); - $this->user->assignRole($roleDev); - - $classification = Classification::factory()->create(['deleted_at' => now()]); - - $this->actingAs($this->user); - - Livewire::test(ManageClassifications::class) - ->filterTable('trashed', 'only') - ->callTableAction('forceDelete', $classification); - - $this->assertDatabaseMissing('classifications', ['id' => $classification->id]); -}); - -test('trashed filter visibility depends on developer role', function () { - // Administrator but not Developer - $roleAdmin = Role::firstOrCreate(['name' => RoleEnum::ADMINISTRATOR->value, 'guard_name' => 'web']); - $this->user->assignRole($roleAdmin); - - $this->actingAs($this->user); - - Livewire::test(ManageClassifications::class) - ->assertTableFilterHidden('trashed'); - - // Upgrade to Developer - $roleDev = Role::firstOrCreate(['name' => RoleEnum::DEVELOPER->value, 'guard_name' => 'web']); - $this->user->assignRole($roleDev); - - Livewire::test(ManageClassifications::class) - ->assertTableFilterVisible('trashed'); -}); diff --git a/tests/Feature/Filament/Resources/Master/Departments/DepartmentResourceTest.php b/tests/Feature/Filament/Resources/Master/Departments/DepartmentResourceTest.php deleted file mode 100644 index 5e787da..0000000 --- a/tests/Feature/Filament/Resources/Master/Departments/DepartmentResourceTest.php +++ /dev/null @@ -1,222 +0,0 @@ -user = User::factory()->create(['is_active' => IsActive::ACTIVE]); - - // Setup Permissions - Permission::firstOrCreate(['name' => 'ViewAny:Department', 'guard_name' => 'web']); - Permission::firstOrCreate(['name' => 'Create:Department', 'guard_name' => 'web']); - Permission::firstOrCreate(['name' => 'Update:Department', 'guard_name' => 'web']); - Permission::firstOrCreate(['name' => 'Delete:Department', 'guard_name' => 'web']); - Permission::firstOrCreate(['name' => 'Restore:Department', 'guard_name' => 'web']); - Permission::firstOrCreate(['name' => 'ForceDelete:Department', 'guard_name' => 'web']); - - $this->user->givePermissionTo([ - 'ViewAny:Department', - 'Create:Department', - 'Update:Department', - 'Delete:Department', - 'Restore:Department', - 'ForceDelete:Department', - ]); -}); - -/* -|-------------------------------------------------------------------------- -| Positive Scenarios -|-------------------------------------------------------------------------- -*/ - -test('can render department list page', function () { - $this->actingAs($this->user); - - Livewire::test(ManageDepartments::class) - ->assertSuccessful(); -}); - -test('can list departments', function () { - $departments = Department::factory()->count(5)->create(); - - $this->actingAs($this->user); - - Livewire::test(ManageDepartments::class) - ->call('loadTable') - ->assertCanSeeTableRecords($departments); -}); - -test('can create department', function () { - $this->actingAs($this->user); - - Livewire::test(ManageDepartments::class) - ->mountAction('create') - ->setActionData([ - 'name' => 'Dinas Pendidikan', - 'alias' => 'Disdik', - ]) - ->callMountedAction() - ->assertHasNoActionErrors(); - - $this->assertDatabaseHas('departments', [ - 'name' => 'Dinas Pendidikan', - 'alias' => 'Disdik', - 'is_active' => IsActive::ACTIVE->value, - ]); -}); - -test('can edit department', function () { - $department = Department::factory()->create(); - - $this->actingAs($this->user); - - Livewire::test(ManageDepartments::class) - ->mountTableAction('edit', $department) - ->setActionData([ - 'name' => 'OPD Baru Updated', - 'alias' => 'OPD-U', - ]) - ->callMountedTableAction() - ->assertHasNoActionErrors(); - - expect($department->refresh()->name)->toBe('OPD Baru Updated'); -}); - -test('can toggle is_active status', function () { - $department = Department::factory()->create(['is_active' => IsActive::INACTIVE]); - - $this->actingAs($this->user); - - Livewire::test(ManageDepartments::class) - ->call('updateTableColumnState', 'is_active', $department->getKey(), true); - - expect($department->refresh()->is_active)->toBe(IsActive::ACTIVE); -}); - -/* -|-------------------------------------------------------------------------- -| Negative Scenarios (Validation & Authorization) -|-------------------------------------------------------------------------- -*/ - -test('cannot create department with invalid data', function () { - $this->actingAs($this->user); - - // Empty name & alias - Livewire::test(ManageDepartments::class) - ->mountAction('create') - ->setActionData(['name' => '', 'alias' => '']) - ->callMountedAction() - ->assertHasActionErrors(['name' => 'required', 'alias' => 'required']); - - // Name exceeding 100 chars - Livewire::test(ManageDepartments::class) - ->mountAction('create') - ->setActionData(['name' => str_repeat('a', 101), 'alias' => 'Short']) - ->callMountedAction() - ->assertHasActionErrors(['name' => 'max']); - - // Alias exceeding 20 chars - Livewire::test(ManageDepartments::class) - ->mountAction('create') - ->setActionData(['name' => 'Valid Name', 'alias' => str_repeat('a', 21)]) - ->callMountedAction() - ->assertHasActionErrors(['alias' => 'max']); -}); - -test('unauthorized user cannot render department page', function () { - $unauthorizedUser = User::factory()->create(['is_active' => IsActive::ACTIVE]); - - $this->actingAs($unauthorizedUser); - - Livewire::test(ManageDepartments::class) - ->assertForbidden(); -}); - -test('user without permissions cannot see actions', function () { - $viewOnlyUser = User::factory()->create(['is_active' => IsActive::ACTIVE]); - $viewOnlyUser->givePermissionTo('ViewAny:Department'); - $department = Department::factory()->create(); - - $this->actingAs($viewOnlyUser); - - Livewire::test(ManageDepartments::class) - ->assertActionHidden('create') - ->assertTableActionHidden('edit', $department); -}); - -/* -|-------------------------------------------------------------------------- -| Soft Delete Scenarios -|-------------------------------------------------------------------------- -*/ - -test('can delete department', function () { - $department = Department::factory()->create(); - - $this->actingAs($this->user); - - Livewire::test(ManageDepartments::class) - ->callTableAction('delete', $department); - - $this->assertSoftDeleted($department); -}); - -test('can restore deleted department', function () { - $roleDev = Role::firstOrCreate(['name' => RoleEnum::DEVELOPER->value, 'guard_name' => 'web']); - $this->user->assignRole($roleDev); - - $department = Department::factory()->create(['deleted_at' => now()]); - - $this->actingAs($this->user); - - Livewire::test(ManageDepartments::class) - ->filterTable('trashed', 'with') - ->callTableAction('restore', $department); - - $this->assertDatabaseHas('departments', [ - 'id' => $department->id, - 'deleted_at' => null, - ]); -}); - -test('can force delete department', function () { - $roleDev = Role::firstOrCreate(['name' => RoleEnum::DEVELOPER->value, 'guard_name' => 'web']); - $this->user->assignRole($roleDev); - - $department = Department::factory()->create(['deleted_at' => now()]); - - $this->actingAs($this->user); - - Livewire::test(ManageDepartments::class) - ->filterTable('trashed', 'only') - ->callTableAction('forceDelete', $department); - - $this->assertDatabaseMissing('departments', ['id' => $department->id]); -}); - -test('trashed filter visibility depends on developer role', function () { - $roleAdmin = Role::firstOrCreate(['name' => RoleEnum::ADMINISTRATOR->value, 'guard_name' => 'web']); - $this->user->assignRole($roleAdmin); - - $this->actingAs($this->user); - - Livewire::test(ManageDepartments::class) - ->assertTableFilterHidden('trashed'); - - $roleDev = Role::firstOrCreate(['name' => RoleEnum::DEVELOPER->value, 'guard_name' => 'web']); - $this->user->assignRole($roleDev); - - Livewire::test(ManageDepartments::class) - ->assertTableFilterVisible('trashed'); -}); diff --git a/tests/Feature/Filament/Resources/Master/Locations/LocationResourceTest.php b/tests/Feature/Filament/Resources/Master/Locations/LocationResourceTest.php deleted file mode 100644 index 1ee8327..0000000 --- a/tests/Feature/Filament/Resources/Master/Locations/LocationResourceTest.php +++ /dev/null @@ -1,214 +0,0 @@ -user = User::factory()->create(['is_active' => IsActive::ACTIVE]); - - // Setup Permissions - Permission::firstOrCreate(['name' => 'ViewAny:Location', 'guard_name' => 'web']); - Permission::firstOrCreate(['name' => 'Create:Location', 'guard_name' => 'web']); - Permission::firstOrCreate(['name' => 'Update:Location', 'guard_name' => 'web']); - Permission::firstOrCreate(['name' => 'Delete:Location', 'guard_name' => 'web']); - Permission::firstOrCreate(['name' => 'Restore:Location', 'guard_name' => 'web']); - Permission::firstOrCreate(['name' => 'ForceDelete:Location', 'guard_name' => 'web']); - - $this->user->givePermissionTo([ - 'ViewAny:Location', - 'Create:Location', - 'Update:Location', - 'Delete:Location', - 'Restore:Location', - 'ForceDelete:Location', - ]); -}); - -/* -|-------------------------------------------------------------------------- -| Positive Scenarios -|-------------------------------------------------------------------------- -*/ - -test('can render location list page', function () { - $this->actingAs($this->user); - - Livewire::test(ManageLocations::class) - ->assertSuccessful(); -}); - -test('can list locations', function () { - $locations = Location::factory()->count(5)->create(); - - $this->actingAs($this->user); - - Livewire::test(ManageLocations::class) - ->call('loadTable') - ->assertCanSeeTableRecords($locations); -}); - -test('can create location', function () { - $this->actingAs($this->user); - - Livewire::test(ManageLocations::class) - ->mountAction('create') - ->setActionData([ - 'name' => 'Lokus Baru', - ]) - ->callMountedAction() - ->assertHasNoActionErrors(); - - $this->assertDatabaseHas('locations', [ - 'name' => 'Lokus Baru', - 'is_active' => IsActive::ACTIVE->value, - ]); -}); - -test('can edit location', function () { - $location = Location::factory()->create(); - - $this->actingAs($this->user); - - Livewire::test(ManageLocations::class) - ->mountTableAction('edit', $location) - ->setActionData([ - 'name' => 'Lokus Updated', - ]) - ->callMountedTableAction() - ->assertHasNoActionErrors(); - - expect($location->refresh()->name)->toBe('Lokus Updated'); -}); - -test('can toggle is_active status', function () { - $location = Location::factory()->create(['is_active' => IsActive::INACTIVE]); - - $this->actingAs($this->user); - - Livewire::test(ManageLocations::class) - ->call('updateTableColumnState', 'is_active', $location->getKey(), true); - - expect($location->refresh()->is_active)->toBe(IsActive::ACTIVE); -}); - -/* -|-------------------------------------------------------------------------- -| Negative Scenarios (Validation & Authorization) -|-------------------------------------------------------------------------- -*/ - -test('cannot create location with empty name', function () { - $this->actingAs($this->user); - - Livewire::test(ManageLocations::class) - ->mountAction('create') - ->setActionData(['name' => '']) - ->callMountedAction() - ->assertHasActionErrors(['name' => 'required']); -}); - -test('cannot create location with name exceeding 50 characters', function () { - $this->actingAs($this->user); - - Livewire::test(ManageLocations::class) - ->mountAction('create') - ->setActionData(['name' => str_repeat('a', 51)]) - ->callMountedAction() - ->assertHasActionErrors(['name' => 'max']); -}); - -test('unauthorized user cannot render location page', function () { - $unauthorizedUser = User::factory()->create(['is_active' => IsActive::ACTIVE]); - - $this->actingAs($unauthorizedUser); - - Livewire::test(ManageLocations::class) - ->assertForbidden(); -}); - -test('user without create permission cannot see create action', function () { - $viewOnlyUser = User::factory()->create(['is_active' => IsActive::ACTIVE]); - $viewOnlyUser->givePermissionTo('ViewAny:Location'); - $location = Location::factory()->create(); - - $this->actingAs($viewOnlyUser); - - Livewire::test(ManageLocations::class) - ->assertActionHidden('create') - ->assertTableActionHidden('edit', $location); -}); - -/* -|-------------------------------------------------------------------------- -| Soft Delete Scenarios -|-------------------------------------------------------------------------- -*/ - -test('can delete location', function () { - $location = Location::factory()->create(); - - $this->actingAs($this->user); - - Livewire::test(ManageLocations::class) - ->callTableAction('delete', $location); - - $this->assertSoftDeleted($location); -}); - -test('can restore deleted location', function () { - $roleDev = Role::firstOrCreate(['name' => RoleEnum::DEVELOPER->value, 'guard_name' => 'web']); - $this->user->assignRole($roleDev); - - $location = Location::factory()->create(['deleted_at' => now()]); - - $this->actingAs($this->user); - - Livewire::test(ManageLocations::class) - ->filterTable('trashed', 'with') - ->callTableAction('restore', $location); - - $this->assertDatabaseHas('locations', [ - 'id' => $location->id, - 'deleted_at' => null, - ]); -}); - -test('can force delete location', function () { - $roleDev = Role::firstOrCreate(['name' => RoleEnum::DEVELOPER->value, 'guard_name' => 'web']); - $this->user->assignRole($roleDev); - - $location = Location::factory()->create(['deleted_at' => now()]); - - $this->actingAs($this->user); - - Livewire::test(ManageLocations::class) - ->filterTable('trashed', 'only') - ->callTableAction('forceDelete', $location); - - $this->assertDatabaseMissing('locations', ['id' => $location->id]); -}); - -test('trashed filter visibility depends on developer role', function () { - $roleAdmin = Role::firstOrCreate(['name' => RoleEnum::ADMINISTRATOR->value, 'guard_name' => 'web']); - $this->user->assignRole($roleAdmin); - - $this->actingAs($this->user); - - Livewire::test(ManageLocations::class) - ->assertTableFilterHidden('trashed'); - - $roleDev = Role::firstOrCreate(['name' => RoleEnum::DEVELOPER->value, 'guard_name' => 'web']); - $this->user->assignRole($roleDev); - - Livewire::test(ManageLocations::class) - ->assertTableFilterVisible('trashed'); -}); diff --git a/tests/Feature/Filament/Resources/Master/SubClassifications/SubClassificationResourceTest.php b/tests/Feature/Filament/Resources/Master/SubClassifications/SubClassificationResourceTest.php deleted file mode 100644 index 630e245..0000000 --- a/tests/Feature/Filament/Resources/Master/SubClassifications/SubClassificationResourceTest.php +++ /dev/null @@ -1,200 +0,0 @@ -user = User::factory()->create(['is_active' => IsActive::ACTIVE]); - - // Setup Permissions - Permission::firstOrCreate(['name' => 'ViewAny:SubClassification', 'guard_name' => 'web']); - Permission::firstOrCreate(['name' => 'Create:SubClassification', 'guard_name' => 'web']); - Permission::firstOrCreate(['name' => 'Update:SubClassification', 'guard_name' => 'web']); - Permission::firstOrCreate(['name' => 'Delete:SubClassification', 'guard_name' => 'web']); - Permission::firstOrCreate(['name' => 'Restore:SubClassification', 'guard_name' => 'web']); - Permission::firstOrCreate(['name' => 'ForceDelete:SubClassification', 'guard_name' => 'web']); - - $this->user->givePermissionTo([ - 'ViewAny:SubClassification', - 'Create:SubClassification', - 'Update:SubClassification', - 'Delete:SubClassification', - 'Restore:SubClassification', - 'ForceDelete:SubClassification', - ]); -}); - -test('can render subklasifikasi list page', function () { - $this->actingAs($this->user); - - Livewire::test(ManageSubClassifications::class) - ->assertSuccessful(); -}); - -test('can list subklasifikasi', function () { - $subClassifications = SubClassification::factory()->count(5)->create(); - - $this->actingAs($this->user); - - Livewire::test(ManageSubClassifications::class) - ->call('loadTable') - ->assertCanSeeTableRecords($subClassifications); -}); - -test('can create subklasifikasi', function () { - $classification = Classification::factory()->create(['is_active' => IsActive::ACTIVE]); - - $this->actingAs($this->user); - - Livewire::test(ManageSubClassifications::class) - ->mountAction('create') - ->setActionData([ - 'classification_id' => $classification->id, - 'name' => 'Subklasifikasi Baru', - ]) - ->callMountedAction() - ->assertHasNoActionErrors(); - - $this->assertDatabaseHas('sub_classifications', [ - 'classification_id' => $classification->id, - 'name' => 'Subklasifikasi Baru', - ]); -}); - -test('cannot create subklasifikasi with invalid data', function () { - $this->actingAs($this->user); - - // Empty name - Livewire::test(ManageSubClassifications::class) - ->mountAction('create') - ->setActionData(['name' => '', 'classification_id' => null]) - ->callMountedAction() - ->assertHasActionErrors(['name' => 'required', 'classification_id' => 'required']); - - // Non-existent classification - Livewire::test(ManageSubClassifications::class) - ->mountAction('create') - ->setActionData(['name' => 'Valid Name', 'classification_id' => 999999]) - ->callMountedAction() - ->assertHasActionErrors(['classification_id']); -}); - -test('can edit subklasifikasi', function () { - $subClassification = SubClassification::factory()->create(); - $newClassification = Classification::factory()->create(['is_active' => IsActive::ACTIVE]); - - $this->actingAs($this->user); - - Livewire::test(ManageSubClassifications::class) - ->mountTableAction('edit', $subClassification) - ->setActionData([ - 'classification_id' => $newClassification->id, - 'name' => 'Subklasifikasi Updated', - ]) - ->callMountedTableAction() - ->assertHasNoActionErrors(); - - expect($subClassification->refresh()->name)->toBe('Subklasifikasi Updated'); - expect($subClassification->classification_id)->toBe($newClassification->id); -}); - -test('can toggle is_active status', function () { - $subClassification = SubClassification::factory()->create(['is_active' => IsActive::INACTIVE]); - - $this->actingAs($this->user); - - Livewire::test(ManageSubClassifications::class) - ->call('updateTableColumnState', 'is_active', $subClassification->getKey(), true); - - expect($subClassification->refresh()->is_active)->toBe(IsActive::ACTIVE); -}); - -test('unauthorized user cannot render subklasifikasi page', function () { - $unauthorizedUser = User::factory()->create(['is_active' => IsActive::ACTIVE]); - - $this->actingAs($unauthorizedUser); - - Livewire::test(ManageSubClassifications::class) - ->assertForbidden(); -}); - -test('user without update permission cannot see edit action', function () { - $viewOnlyUser = User::factory()->create(['is_active' => IsActive::ACTIVE]); - $viewOnlyUser->givePermissionTo('ViewAny:SubClassification'); - $subClassification = SubClassification::factory()->create(); - - $this->actingAs($viewOnlyUser); - - Livewire::test(ManageSubClassifications::class) - ->assertTableActionHidden('edit', $subClassification); -}); - -test('can delete subklasifikasi', function () { - $subClassification = SubClassification::factory()->create(); - - $this->actingAs($this->user); - - Livewire::test(ManageSubClassifications::class) - ->callTableAction('delete', $subClassification); - - $this->assertSoftDeleted($subClassification); -}); - -test('can restore deleted subklasifikasi', function () { - $roleDev = Role::firstOrCreate(['name' => RoleEnum::DEVELOPER->value, 'guard_name' => 'web']); - $this->user->assignRole($roleDev); - - $subClassification = SubClassification::factory()->create(['deleted_at' => now()]); - - $this->actingAs($this->user); - - Livewire::test(ManageSubClassifications::class) - ->filterTable('trashed', 'with') - ->callTableAction('restore', $subClassification); - - $this->assertDatabaseHas('sub_classifications', [ - 'id' => $subClassification->id, - 'deleted_at' => null, - ]); -}); - -test('can force delete subklasifikasi', function () { - $roleDev = Role::firstOrCreate(['name' => RoleEnum::DEVELOPER->value, 'guard_name' => 'web']); - $this->user->assignRole($roleDev); - - $subClassification = SubClassification::factory()->create(['deleted_at' => now()]); - - $this->actingAs($this->user); - - Livewire::test(ManageSubClassifications::class) - ->filterTable('trashed', 'only') - ->callTableAction('forceDelete', $subClassification); - - $this->assertDatabaseMissing('sub_classifications', ['id' => $subClassification->id]); -}); - -test('trashed filter visibility depends on developer role', function () { - $roleAdmin = Role::firstOrCreate(['name' => RoleEnum::ADMINISTRATOR->value, 'guard_name' => 'web']); - $this->user->assignRole($roleAdmin); - - $this->actingAs($this->user); - - Livewire::test(ManageSubClassifications::class) - ->assertTableFilterHidden('trashed'); - - $roleDev = Role::firstOrCreate(['name' => RoleEnum::DEVELOPER->value, 'guard_name' => 'web']); - $this->user->assignRole($roleDev); - - Livewire::test(ManageSubClassifications::class) - ->assertTableFilterVisible('trashed'); -}); diff --git a/tests/Feature/Filament/Resources/Master/SubLocations/SubLocationResourceTest.php b/tests/Feature/Filament/Resources/Master/SubLocations/SubLocationResourceTest.php deleted file mode 100644 index c369e4a..0000000 --- a/tests/Feature/Filament/Resources/Master/SubLocations/SubLocationResourceTest.php +++ /dev/null @@ -1,218 +0,0 @@ -user = User::factory()->create(['is_active' => IsActive::ACTIVE]); - - // Setup Permissions - Permission::firstOrCreate(['name' => 'ViewAny:SubLocation', 'guard_name' => 'web']); - Permission::firstOrCreate(['name' => 'Create:SubLocation', 'guard_name' => 'web']); - Permission::firstOrCreate(['name' => 'Update:SubLocation', 'guard_name' => 'web']); - Permission::firstOrCreate(['name' => 'Delete:SubLocation', 'guard_name' => 'web']); - Permission::firstOrCreate(['name' => 'Restore:SubLocation', 'guard_name' => 'web']); - Permission::firstOrCreate(['name' => 'ForceDelete:SubLocation', 'guard_name' => 'web']); - - $this->user->givePermissionTo([ - 'ViewAny:SubLocation', - 'Create:SubLocation', - 'Update:SubLocation', - 'Delete:SubLocation', - 'Restore:SubLocation', - 'ForceDelete:SubLocation', - ]); -}); - -/* -|-------------------------------------------------------------------------- -| Positive Scenarios -|-------------------------------------------------------------------------- -*/ - -test('can render sublokus list page', function () { - $this->actingAs($this->user); - - Livewire::test(ManageSubLocations::class) - ->assertSuccessful(); -}); - -test('can list sublokus', function () { - $subLocations = SubLocation::factory()->count(5)->create(); - - $this->actingAs($this->user); - - Livewire::test(ManageSubLocations::class) - ->call('loadTable') - ->assertCanSeeTableRecords($subLocations); -}); - -test('can create sublokus', function () { - $location = Location::factory()->create(['is_active' => IsActive::ACTIVE]); - - $this->actingAs($this->user); - - Livewire::test(ManageSubLocations::class) - ->mountAction('create') - ->setActionData([ - 'location_id' => $location->id, - 'name' => 'Sublokus Baru', - ]) - ->callMountedAction() - ->assertHasNoActionErrors(); - - $this->assertDatabaseHas('sub_locations', [ - 'location_id' => $location->id, - 'name' => 'Sublokus Baru', - ]); -}); - -test('can edit sublokus', function () { - $subLocation = SubLocation::factory()->create(); - $newLocation = Location::factory()->create(['is_active' => IsActive::ACTIVE]); - - $this->actingAs($this->user); - - Livewire::test(ManageSubLocations::class) - ->mountTableAction('edit', $subLocation) - ->setActionData([ - 'location_id' => $newLocation->id, - 'name' => 'Sublokus Updated', - ]) - ->callMountedTableAction() - ->assertHasNoActionErrors(); - - expect($subLocation->refresh()->name)->toBe('Sublokus Updated'); - expect($subLocation->location_id)->toBe($newLocation->id); -}); - -test('can toggle is_active status', function () { - $subLocation = SubLocation::factory()->create(['is_active' => IsActive::INACTIVE]); - - $this->actingAs($this->user); - - Livewire::test(ManageSubLocations::class) - ->call('updateTableColumnState', 'is_active', $subLocation->getKey(), true); - - expect($subLocation->refresh()->is_active)->toBe(IsActive::ACTIVE); -}); - -/* -|-------------------------------------------------------------------------- -| Negative Scenarios (Validation & Authorization) -|-------------------------------------------------------------------------- -*/ - -test('cannot create sublokus with invalid data', function () { - $this->actingAs($this->user); - - // Empty name - Livewire::test(ManageSubLocations::class) - ->mountAction('create') - ->setActionData(['name' => '', 'location_id' => null]) - ->callMountedAction() - ->assertHasActionErrors(['name' => 'required', 'location_id' => 'required']); - - // Non-existent location - Livewire::test(ManageSubLocations::class) - ->mountAction('create') - ->setActionData(['name' => 'Valid Name', 'location_id' => 999999]) - ->callMountedAction() - ->assertHasActionErrors(['location_id']); -}); - -test('unauthorized user cannot render sublokus page', function () { - $unauthorizedUser = User::factory()->create(['is_active' => IsActive::ACTIVE]); - - $this->actingAs($unauthorizedUser); - - Livewire::test(ManageSubLocations::class) - ->assertForbidden(); -}); - -test('user without update permission cannot see edit action', function () { - $viewOnlyUser = User::factory()->create(['is_active' => IsActive::ACTIVE]); - $viewOnlyUser->givePermissionTo('ViewAny:SubLocation'); - $subLocation = SubLocation::factory()->create(); - - $this->actingAs($viewOnlyUser); - - Livewire::test(ManageSubLocations::class) - ->assertTableActionHidden('edit', $subLocation); -}); - -/* -|-------------------------------------------------------------------------- -| Soft Delete Scenarios -|-------------------------------------------------------------------------- -*/ - -test('can delete sublokus', function () { - $subLocation = SubLocation::factory()->create(); - - $this->actingAs($this->user); - - Livewire::test(ManageSubLocations::class) - ->callTableAction('delete', $subLocation); - - $this->assertSoftDeleted($subLocation); -}); - -test('can restore deleted sublokus', function () { - $roleDev = Role::firstOrCreate(['name' => RoleEnum::DEVELOPER->value, 'guard_name' => 'web']); - $this->user->assignRole($roleDev); - - $subLocation = SubLocation::factory()->create(['deleted_at' => now()]); - - $this->actingAs($this->user); - - Livewire::test(ManageSubLocations::class) - ->filterTable('trashed', 'with') - ->callTableAction('restore', $subLocation); - - $this->assertDatabaseHas('sub_locations', [ - 'id' => $subLocation->id, - 'deleted_at' => null, - ]); -}); - -test('can force delete sublokus', function () { - $roleDev = Role::firstOrCreate(['name' => RoleEnum::DEVELOPER->value, 'guard_name' => 'web']); - $this->user->assignRole($roleDev); - - $subLocation = SubLocation::factory()->create(['deleted_at' => now()]); - - $this->actingAs($this->user); - - Livewire::test(ManageSubLocations::class) - ->filterTable('trashed', 'only') - ->callTableAction('forceDelete', $subLocation); - - $this->assertDatabaseMissing('sub_locations', ['id' => $subLocation->id]); -}); - -test('trashed filter visibility depends on developer role', function () { - $roleAdmin = Role::firstOrCreate(['name' => RoleEnum::ADMINISTRATOR->value, 'guard_name' => 'web']); - $this->user->assignRole($roleAdmin); - - $this->actingAs($this->user); - - Livewire::test(ManageSubLocations::class) - ->assertTableFilterHidden('trashed'); - - $roleDev = Role::firstOrCreate(['name' => RoleEnum::DEVELOPER->value, 'guard_name' => 'web']); - $this->user->assignRole($roleDev); - - Livewire::test(ManageSubLocations::class) - ->assertTableFilterVisible('trashed'); -}); diff --git a/tests/Feature/Filament/Resources/Master/Themes/ThemeResourceTest.php b/tests/Feature/Filament/Resources/Master/Themes/ThemeResourceTest.php deleted file mode 100644 index 2596484..0000000 --- a/tests/Feature/Filament/Resources/Master/Themes/ThemeResourceTest.php +++ /dev/null @@ -1,214 +0,0 @@ -user = User::factory()->create(['is_active' => IsActive::ACTIVE]); - - // Setup Permissions - Permission::firstOrCreate(['name' => 'ViewAny:Theme', 'guard_name' => 'web']); - Permission::firstOrCreate(['name' => 'Create:Theme', 'guard_name' => 'web']); - Permission::firstOrCreate(['name' => 'Update:Theme', 'guard_name' => 'web']); - Permission::firstOrCreate(['name' => 'Delete:Theme', 'guard_name' => 'web']); - Permission::firstOrCreate(['name' => 'Restore:Theme', 'guard_name' => 'web']); - Permission::firstOrCreate(['name' => 'ForceDelete:Theme', 'guard_name' => 'web']); - - $this->user->givePermissionTo([ - 'ViewAny:Theme', - 'Create:Theme', - 'Update:Theme', - 'Delete:Theme', - 'Restore:Theme', - 'ForceDelete:Theme', - ]); -}); - -/* -|-------------------------------------------------------------------------- -| Positive Scenarios -|-------------------------------------------------------------------------- -*/ - -test('can render theme list page', function () { - $this->actingAs($this->user); - - Livewire::test(ManageThemes::class) - ->assertSuccessful(); -}); - -test('can list themes', function () { - $themes = Theme::factory()->count(5)->create(); - - $this->actingAs($this->user); - - Livewire::test(ManageThemes::class) - ->call('loadTable') - ->assertCanSeeTableRecords($themes); -}); - -test('can create theme', function () { - $this->actingAs($this->user); - - Livewire::test(ManageThemes::class) - ->mountAction('create') - ->setActionData([ - 'name' => 'Tema Pendidikan', - ]) - ->callMountedAction() - ->assertHasNoActionErrors(); - - $this->assertDatabaseHas('themes', [ - 'name' => 'Tema Pendidikan', - 'is_active' => IsActive::ACTIVE->value, - ]); -}); - -test('can edit theme', function () { - $theme = Theme::factory()->create(); - - $this->actingAs($this->user); - - Livewire::test(ManageThemes::class) - ->mountTableAction('edit', $theme) - ->setActionData([ - 'name' => 'Tema Updated', - ]) - ->callMountedTableAction() - ->assertHasNoActionErrors(); - - expect($theme->refresh()->name)->toBe('Tema Updated'); -}); - -test('can toggle is_active status', function () { - $theme = Theme::factory()->create(['is_active' => IsActive::INACTIVE]); - - $this->actingAs($this->user); - - Livewire::test(ManageThemes::class) - ->call('updateTableColumnState', 'is_active', $theme->getKey(), true); - - expect($theme->refresh()->is_active)->toBe(IsActive::ACTIVE); -}); - -/* -|-------------------------------------------------------------------------- -| Negative Scenarios (Validation & Authorization) -|-------------------------------------------------------------------------- -*/ - -test('cannot create theme with empty name', function () { - $this->actingAs($this->user); - - Livewire::test(ManageThemes::class) - ->mountAction('create') - ->setActionData(['name' => '']) - ->callMountedAction() - ->assertHasActionErrors(['name' => 'required']); -}); - -test('cannot create theme with name exceeding 50 characters', function () { - $this->actingAs($this->user); - - Livewire::test(ManageThemes::class) - ->mountAction('create') - ->setActionData(['name' => str_repeat('a', 51)]) - ->callMountedAction() - ->assertHasActionErrors(['name' => 'max']); -}); - -test('unauthorized user cannot render theme page', function () { - $unauthorizedUser = User::factory()->create(['is_active' => IsActive::ACTIVE]); - - $this->actingAs($unauthorizedUser); - - Livewire::test(ManageThemes::class) - ->assertForbidden(); -}); - -test('user without permissions cannot see actions', function () { - $viewOnlyUser = User::factory()->create(['is_active' => IsActive::ACTIVE]); - $viewOnlyUser->givePermissionTo('ViewAny:Theme'); - $theme = Theme::factory()->create(); - - $this->actingAs($viewOnlyUser); - - Livewire::test(ManageThemes::class) - ->assertActionHidden('create') - ->assertTableActionHidden('edit', $theme); -}); - -/* -|-------------------------------------------------------------------------- -| Soft Delete Scenarios -|-------------------------------------------------------------------------- -*/ - -test('can delete theme', function () { - $theme = Theme::factory()->create(); - - $this->actingAs($this->user); - - Livewire::test(ManageThemes::class) - ->callTableAction('delete', $theme); - - $this->assertSoftDeleted($theme); -}); - -test('can restore deleted theme', function () { - $roleDev = Role::firstOrCreate(['name' => RoleEnum::DEVELOPER->value, 'guard_name' => 'web']); - $this->user->assignRole($roleDev); - - $theme = Theme::factory()->create(['deleted_at' => now()]); - - $this->actingAs($this->user); - - Livewire::test(ManageThemes::class) - ->filterTable('trashed', 'with') - ->callTableAction('restore', $theme); - - $this->assertDatabaseHas('themes', [ - 'id' => $theme->id, - 'deleted_at' => null, - ]); -}); - -test('can force delete theme', function () { - $roleDev = Role::firstOrCreate(['name' => RoleEnum::DEVELOPER->value, 'guard_name' => 'web']); - $this->user->assignRole($roleDev); - - $theme = Theme::factory()->create(['deleted_at' => now()]); - - $this->actingAs($this->user); - - Livewire::test(ManageThemes::class) - ->filterTable('trashed', 'only') - ->callTableAction('forceDelete', $theme); - - $this->assertDatabaseMissing('themes', ['id' => $theme->id]); -}); - -test('trashed filter visibility depends on developer role', function () { - $roleAdmin = Role::firstOrCreate(['name' => RoleEnum::ADMINISTRATOR->value, 'guard_name' => 'web']); - $this->user->assignRole($roleAdmin); - - $this->actingAs($this->user); - - Livewire::test(ManageThemes::class) - ->assertTableFilterHidden('trashed'); - - $roleDev = Role::firstOrCreate(['name' => RoleEnum::DEVELOPER->value, 'guard_name' => 'web']); - $this->user->assignRole($roleDev); - - Livewire::test(ManageThemes::class) - ->assertTableFilterVisible('trashed'); -}); diff --git a/tests/Feature/Filament/Resources/Master/Users/UserResourceTest.php b/tests/Feature/Filament/Resources/Master/Users/UserResourceTest.php deleted file mode 100644 index 347ad20..0000000 --- a/tests/Feature/Filament/Resources/Master/Users/UserResourceTest.php +++ /dev/null @@ -1,245 +0,0 @@ -user = User::factory()->create(['is_active' => IsActive::ACTIVE]); - - // Setup Permissions - $permissions = [ - 'ViewAny:User', - 'Create:User', - 'Update:User', - 'Delete:User', - 'Restore:User', - 'ForceDelete:User', - ]; - - foreach ($permissions as $permission) { - Permission::firstOrCreate(['name' => $permission, 'guard_name' => 'web']); - } - - $this->user->givePermissionTo($permissions); - - // Create a default role for testing - Role::firstOrCreate(['name' => RoleEnum::ADMINISTRATOR->value, 'guard_name' => 'web']); -}); - -test('can render user list page', function () { - $this->actingAs($this->user); - - Livewire::test(ManageUsers::class) - ->assertSuccessful(); -}); - -test('can list users', function () { - $users = User::factory()->count(5)->create(); - - $this->actingAs($this->user); - - Livewire::test(ManageUsers::class) - ->call('loadTable') - ->assertCanSeeTableRecords($users); -}); - -test('cannot see developers in the list', function () { - $devRole = Role::firstOrCreate(['name' => RoleEnum::DEVELOPER->value, 'guard_name' => 'web']); - $developer = User::factory()->create(); - $developer->assignRole($devRole); - - $this->actingAs($this->user); - - Livewire::test(ManageUsers::class) - ->call('loadTable') - ->assertCanNotSeeTableRecords([$developer]); -}); - -test('can create user', function () { - $role = Role::where('name', RoleEnum::ADMINISTRATOR->value)->first(); - - $this->actingAs($this->user); - - Livewire::test(ManageUsers::class) - ->mountAction('create') - ->setActionData([ - 'name' => 'Test User', - 'email' => 'test@example.com', - 'username' => 'testuser', - 'roles' => [$role->id], - ]) - ->callMountedAction() - ->assertHasNoActionErrors(); - - $this->assertDatabaseHas('users', [ - 'name' => 'Test User', - 'email' => 'test@example.com', - 'username' => 'testuser', - 'is_active' => IsActive::ACTIVE->value, - ]); - - $newUser = User::where('email', 'test@example.com')->first(); - expect($newUser->roles->pluck('id'))->toContain($role->id); -}); - -test('validation: required fields', function () { - $this->actingAs($this->user); - - Livewire::test(ManageUsers::class) - ->mountAction('create') - ->setActionData([ - 'name' => '', - 'email' => '', - 'username' => '', - 'roles' => [], - ]) - ->callMountedAction() - ->assertHasActionErrors([ - 'name' => 'required', - 'email' => 'required', - 'username' => 'required', - 'roles' => 'required', - ]); -}); - -test('validation: username length and format', function () { - $this->actingAs($this->user); - - // Too short - Livewire::test(ManageUsers::class) - ->mountAction('create') - ->setActionData(['username' => 'abc']) - ->callMountedAction() - ->assertHasActionErrors(['username' => 'min']); - - // Invalid format - Livewire::test(ManageUsers::class) - ->mountAction('create') - ->setActionData(['username' => 'user name']) - ->callMountedAction() - ->assertHasActionErrors(['username' => 'regex']); -}); - -test('can edit user', function () { - $userToEdit = User::factory()->create(); - - $this->actingAs($this->user); - - $role = Role::where('name', RoleEnum::ADMINISTRATOR->value)->first(); - - Livewire::test(ManageUsers::class) - ->mountTableAction('edit', $userToEdit) - ->setActionData([ - 'name' => 'Updated Name', - 'roles' => [$role->id], - ]) - ->callMountedTableAction() - ->assertHasNoActionErrors(); - - expect($userToEdit->refresh()->name)->toBe('Updated Name'); -}); - -test('can change user password', function () { - $userToModify = User::factory()->create(); - $oldPassword = $userToModify->password; - - $this->actingAs($this->user); - - Livewire::test(ManageUsers::class) - ->mountTableAction('changePassword', $userToModify) - ->setActionData([ - 'password' => 'newpassword123', - ]) - ->callMountedTableAction() - ->assertHasNoActionErrors(); - - $userToModify->refresh(); - expect(Hash::check('newpassword123', $userToModify->password))->toBeTrue(); - expect($userToModify->password)->not->toBe($oldPassword); -}); - -test('can toggle user active status', function () { - $userToToggle = User::factory()->create(['is_active' => IsActive::INACTIVE]); - - $this->actingAs($this->user); - - Livewire::test(ManageUsers::class) - ->call('updateTableColumnState', 'is_active', $userToToggle->getKey(), true); - - expect($userToToggle->refresh()->is_active)->toBe(IsActive::ACTIVE); -}); - -test('cannot toggle active status for company role', function () { - $companyRole = Role::firstOrCreate(['name' => RoleEnum::PERUSAHAAN->value, 'guard_name' => 'web']); - $companyUser = User::factory()->create(['is_active' => IsActive::ACTIVE]); - $companyUser->assignRole($companyRole); - - $this->actingAs($this->user); - - Livewire::test(ManageUsers::class) - ->call('updateTableColumnState', 'is_active', $companyUser->getKey(), false); - - expect($companyUser->refresh()->is_active)->toBe(IsActive::ACTIVE); -}); - -test('unauthorized user cannot render user page', function () { - $unauthorizedUser = User::factory()->create(['is_active' => IsActive::ACTIVE]); - - $this->actingAs($unauthorizedUser); - - Livewire::test(ManageUsers::class) - ->assertForbidden(); -}); - -test('can delete user', function () { - $userToDelete = User::factory()->create(); - - $this->actingAs($this->user); - - Livewire::test(ManageUsers::class) - ->callTableAction('delete', $userToDelete); - - $this->assertSoftDeleted($userToDelete); -}); - -test('can restore deleted user', function () { - $roleDev = Role::firstOrCreate(['name' => RoleEnum::DEVELOPER->value, 'guard_name' => 'web']); - $this->user->assignRole($roleDev); - - $userToRestore = User::factory()->create(['deleted_at' => now()]); - - $this->actingAs($this->user); - - Livewire::test(ManageUsers::class) - ->filterTable('trashed', 'with') - ->callTableAction('restore', $userToRestore); - - $this->assertDatabaseHas('users', [ - 'id' => $userToRestore->id, - 'deleted_at' => null, - ]); -}); - -test('can force delete user', function () { - $roleDev = Role::firstOrCreate(['name' => RoleEnum::DEVELOPER->value, 'guard_name' => 'web']); - $this->user->assignRole($roleDev); - - $userToForceDelete = User::factory()->create(['deleted_at' => now()]); - - $this->actingAs($this->user); - - Livewire::test(ManageUsers::class) - ->filterTable('trashed', 'only') - ->callTableAction('forceDelete', $userToForceDelete); - - $this->assertDatabaseMissing('users', ['id' => $userToForceDelete->id]); -}); diff --git a/tests/Feature/Models/AnnouncementMediaTest.php b/tests/Feature/Models/AnnouncementMediaTest.php deleted file mode 100644 index cc8a355..0000000 --- a/tests/Feature/Models/AnnouncementMediaTest.php +++ /dev/null @@ -1,20 +0,0 @@ -create(); - $media = PartnerMedia::factory()->create(); - $announcementMedia = AnnouncementMedia::factory()->create([ - 'announcement_id' => $announcement->id, - 'partner_media_id' => $media->id, - ]); - - expect($announcementMedia->announcement->id)->toBe($announcement->id); - expect($announcementMedia->partnerMedia->id)->toBe($media->id); -}); diff --git a/tests/Feature/Models/AnnouncementTest.php b/tests/Feature/Models/AnnouncementTest.php deleted file mode 100644 index 10c4d39..0000000 --- a/tests/Feature/Models/AnnouncementTest.php +++ /dev/null @@ -1,13 +0,0 @@ -create(['title' => 'Test Promo']); - expect($announcement->title)->toBe('Test Promo'); - expect($announcement->type)->toBe(AnnouncementType::PUBLIC); -}); diff --git a/tests/Feature/Models/ClassificationTest.php b/tests/Feature/Models/ClassificationTest.php deleted file mode 100644 index 629b30b..0000000 --- a/tests/Feature/Models/ClassificationTest.php +++ /dev/null @@ -1,56 +0,0 @@ -getGuarded())->toBe(['id']); -}); - -test('classification has correct casts', function () { - $classification = new Classification; - - expect($classification->getCasts())->toHaveKey('is_active', IsActive::class); - expect($classification->getCasts())->toHaveKey('deleted_at', 'datetime'); -}); - -test('classification can be created using factory', function () { - $classification = Classification::factory()->create([ - 'name' => 'Test Classification', - ]); - - expect($classification->name)->toBe('Test Classification'); - $this->assertDatabaseHas('classifications', [ - 'id' => $classification->id, - 'name' => 'Test Classification', - ]); -}); - -test('classification active scope filters correctly', function () { - Classification::factory()->count(3)->active()->create(); - Classification::factory()->count(2)->inactive()->create(); - - expect(Classification::active()->count())->toBe(3); -}); - -test('classification inactive scope filters correctly', function () { - Classification::factory()->count(3)->active()->create(); - Classification::factory()->count(2)->inactive()->create(); - - expect(Classification::inactive()->count())->toBe(2); -}); - -test('classification has many sub classifications', function () { - $classification = Classification::factory()->create(); - - // We need SubClassification factory for this, but let's just check the relation type for now - // or create a quick test without factory if it's not ready. - expect($classification->subClassifications())->toBeInstanceOf(HasMany::class); -}); diff --git a/tests/Feature/Models/CompanyTest.php b/tests/Feature/Models/CompanyTest.php deleted file mode 100644 index bfd65f3..0000000 --- a/tests/Feature/Models/CompanyTest.php +++ /dev/null @@ -1,46 +0,0 @@ -getGuarded())->toBe(['id']); -}); - -test('company can be created using factory', function () { - $company = Company::factory()->create([ - 'name' => 'PT Media Maju', - ]); - - expect($company->name)->toBe('PT Media Maju'); - $this->assertDatabaseHas('companies', ['name' => 'PT Media Maju']); -}); - -test('company belongs to a user', function () { - $user = User::factory()->create(); - $company = Company::factory()->create(['user_id' => $user->id]); - - expect($company->user)->toBeInstanceOf(User::class); - expect($company->user->id)->toBe($user->id); -}); - -test('company has one verification request', function () { - $company = Company::factory()->create(); - $request = VerificationRequest::factory()->create(['company_id' => $company->id]); - - expect($company->verificationRequest)->toBeInstanceOf(VerificationRequest::class); - expect($company->verificationRequest->id)->toBe($request->id); -}); - -test('company has static method for data change labels', function () { - $labels = Company::dataChangeEntryLabels(); - - expect($labels)->toBeArray(); - expect($labels)->toHaveKey('name', 'Nama'); - expect($labels)->toHaveKey('director_nik', 'NIK Direktur'); -}); diff --git a/tests/Feature/Models/ContactTest.php b/tests/Feature/Models/ContactTest.php deleted file mode 100644 index 52ad366..0000000 --- a/tests/Feature/Models/ContactTest.php +++ /dev/null @@ -1,11 +0,0 @@ -create(['email' => 'user@test.com']); - expect($contact->email)->toBe('user@test.com'); -}); diff --git a/tests/Feature/Models/ContentRecapTest.php b/tests/Feature/Models/ContentRecapTest.php deleted file mode 100644 index 465f8a1..0000000 --- a/tests/Feature/Models/ContentRecapTest.php +++ /dev/null @@ -1,13 +0,0 @@ -create(['title' => 'Weekly Recap']); - expect($recap->title)->toBe('Weekly Recap'); - expect($recap->classification)->toBeInstanceOf(Classification::class); -}); diff --git a/tests/Feature/Models/CooperationMediaTest.php b/tests/Feature/Models/CooperationMediaTest.php deleted file mode 100644 index f0a7755..0000000 --- a/tests/Feature/Models/CooperationMediaTest.php +++ /dev/null @@ -1,21 +0,0 @@ -create(); - $media = PartnerMedia::factory()->create(); - - $coopMedia = CooperationMedia::factory()->create([ - 'cooperation_id' => $cooperation->id, - 'partner_media_id' => $media->id, - ]); - - expect($coopMedia->cooperation->id)->toBe($cooperation->id); - expect($coopMedia->partnerMedia->id)->toBe($media->id); -}); diff --git a/tests/Feature/Models/CooperationPaymentTest.php b/tests/Feature/Models/CooperationPaymentTest.php deleted file mode 100644 index 8513f34..0000000 --- a/tests/Feature/Models/CooperationPaymentTest.php +++ /dev/null @@ -1,18 +0,0 @@ -create(); - $payment = CooperationPayment::factory()->create([ - 'cooperation_media_id' => $coopMedia->id, - 'amount' => 5000000, - ]); - - expect($payment->amount)->toBe(5000000); - expect($payment->cooperationMedia->id)->toBe($coopMedia->id); -}); diff --git a/tests/Feature/Models/CooperationProposalTest.php b/tests/Feature/Models/CooperationProposalTest.php deleted file mode 100644 index b84142d..0000000 --- a/tests/Feature/Models/CooperationProposalTest.php +++ /dev/null @@ -1,15 +0,0 @@ -create([ - 'status' => ApprovalStatus::PENDING, - ]); - - expect($proposal->status)->toBe(ApprovalStatus::PENDING); -}); diff --git a/tests/Feature/Models/CooperationTest.php b/tests/Feature/Models/CooperationTest.php deleted file mode 100644 index bbb7d0f..0000000 --- a/tests/Feature/Models/CooperationTest.php +++ /dev/null @@ -1,12 +0,0 @@ -create(); - expect($cooperation->status)->toBe(CooperationStatus::PENDING); -}); diff --git a/tests/Feature/Models/DataChangeRequestTest.php b/tests/Feature/Models/DataChangeRequestTest.php deleted file mode 100644 index e5b266a..0000000 --- a/tests/Feature/Models/DataChangeRequestTest.php +++ /dev/null @@ -1,21 +0,0 @@ -create(); - $request = DataChangeRequest::factory()->create([ - 'entity_type' => Company::class, - 'entity_id' => $company->id, - 'status' => DataChangeStatus::PENDING, - ]); - - expect($request->status)->toBe(DataChangeStatus::PENDING); - expect($request->entity)->toBeInstanceOf(Company::class); - expect($request->entity->id)->toBe($company->id); -}); diff --git a/tests/Feature/Models/DataChangeReviewTest.php b/tests/Feature/Models/DataChangeReviewTest.php deleted file mode 100644 index 7fbb5ae..0000000 --- a/tests/Feature/Models/DataChangeReviewTest.php +++ /dev/null @@ -1,19 +0,0 @@ -create(); - $review = DataChangeReview::factory()->create([ - 'data_change_request_id' => $request->id, - 'decision' => DataChangeDecision::APPROVED, - ]); - - expect($request->review->id)->toBe($review->id); - expect($review->request->id)->toBe($request->id); -}); diff --git a/tests/Feature/Models/DepartmentTest.php b/tests/Feature/Models/DepartmentTest.php deleted file mode 100644 index 17b49ef..0000000 --- a/tests/Feature/Models/DepartmentTest.php +++ /dev/null @@ -1,13 +0,0 @@ -create(['name' => 'IT Research', 'alias' => 'ITR']); - expect($dept->name)->toBe('IT Research'); - expect($dept->is_active)->toBe(IsActive::ACTIVE); -}); diff --git a/tests/Feature/Models/IssueManagementTest.php b/tests/Feature/Models/IssueManagementTest.php deleted file mode 100644 index 0b3a0ae..0000000 --- a/tests/Feature/Models/IssueManagementTest.php +++ /dev/null @@ -1,32 +0,0 @@ -create(); - $classification = Classification::factory()->create(); - $monitoring = MediaMonitoring::factory()->create(); - $department = Department::factory()->create(); - - $issue = IssueManagement::factory()->create([ - 'location_id' => $location->id, - 'classification_id' => $classification->id, - 'media_monitoring_id' => $monitoring->id, - 'issue' => IssueSentiment::POSITIVE, - ]); - - $issue->departments()->attach($department->id); - - expect($issue->issue)->toBe(IssueSentiment::POSITIVE); - expect($issue->location->id)->toBe($location->id); - expect($issue->mediaMonitoring->id)->toBe($monitoring->id); - expect($issue->departments->first()->id)->toBe($department->id); -}); diff --git a/tests/Feature/Models/JournalistTest.php b/tests/Feature/Models/JournalistTest.php deleted file mode 100644 index 06498d2..0000000 --- a/tests/Feature/Models/JournalistTest.php +++ /dev/null @@ -1,14 +0,0 @@ -create(); - $journalist = Journalist::factory()->create(['partner_media_id' => $media->id]); - - expect($journalist->partnerMedia->id)->toBe($media->id); -}); diff --git a/tests/Feature/Models/LocationTest.php b/tests/Feature/Models/LocationTest.php deleted file mode 100644 index 8ac2d14..0000000 --- a/tests/Feature/Models/LocationTest.php +++ /dev/null @@ -1,13 +0,0 @@ -create(['name' => 'Purwakarta']); - expect($location->name)->toBe('Purwakarta'); - expect($location->is_active)->toBe(IsActive::ACTIVE); -}); diff --git a/tests/Feature/Models/MediaMonitoringTest.php b/tests/Feature/Models/MediaMonitoringTest.php deleted file mode 100644 index 1988173..0000000 --- a/tests/Feature/Models/MediaMonitoringTest.php +++ /dev/null @@ -1,11 +0,0 @@ -create(['media_name' => 'Tempo']); - expect($monitoring->media_name)->toBe('Tempo'); -}); diff --git a/tests/Feature/Models/MediaMonitoringThemeTest.php b/tests/Feature/Models/MediaMonitoringThemeTest.php deleted file mode 100644 index 847e8e0..0000000 --- a/tests/Feature/Models/MediaMonitoringThemeTest.php +++ /dev/null @@ -1,21 +0,0 @@ -create(); - $theme = Theme::factory()->create(); - $mmt = MediaMonitoringTheme::factory()->create([ - 'media_monitoring_id' => $monitoring->id, - 'theme_id' => $theme->id, - ]); - - expect($mmt->mediaMonitoring->id)->toBe($monitoring->id); - expect($mmt->theme->id)->toBe($theme->id); - expect($monitoring->themes->first()->id)->toBe($theme->id); -}); diff --git a/tests/Feature/Models/MediaTaskAssignmentTest.php b/tests/Feature/Models/MediaTaskAssignmentTest.php deleted file mode 100644 index b3a2bab..0000000 --- a/tests/Feature/Models/MediaTaskAssignmentTest.php +++ /dev/null @@ -1,15 +0,0 @@ -create(); - $report = Report::factory()->create(['media_task_assignment_id' => $mta->id]); - - expect($report->mediaTaskAssignment->id)->toBe($mta->id); - expect($mta->reports)->toHaveCount(1); -}); diff --git a/tests/Feature/Models/NewsTest.php b/tests/Feature/Models/NewsTest.php deleted file mode 100644 index 95c7c6f..0000000 --- a/tests/Feature/Models/NewsTest.php +++ /dev/null @@ -1,15 +0,0 @@ -create([ - 'title' => 'Kabar Purwakarta', - 'slug' => 'kabar-purwakarta', - ]); - expect($news->title)->toBe('Kabar Purwakarta'); - expect($news->slug)->toBe('kabar-purwakarta'); -}); diff --git a/tests/Feature/Models/PartnerMediaTest.php b/tests/Feature/Models/PartnerMediaTest.php deleted file mode 100644 index 2ab959b..0000000 --- a/tests/Feature/Models/PartnerMediaTest.php +++ /dev/null @@ -1,14 +0,0 @@ -create(); - Journalist::factory()->count(2)->create(['partner_media_id' => $media->id]); - - expect($media->journalists)->toHaveCount(2); -}); diff --git a/tests/Feature/Models/RejectionReasonTest.php b/tests/Feature/Models/RejectionReasonTest.php deleted file mode 100644 index 0658e01..0000000 --- a/tests/Feature/Models/RejectionReasonTest.php +++ /dev/null @@ -1,19 +0,0 @@ -create(); - $rejection = RejectionReason::factory()->create([ - 'rejectable_type' => Report::class, - 'rejectable_id' => $report->id, - 'reason' => 'Invalid link', - ]); - - expect($rejection->reason)->toBe('Invalid link'); - expect($rejection->rejectable)->toBeInstanceOf(Report::class); -}); diff --git a/tests/Feature/Models/ReportTest.php b/tests/Feature/Models/ReportTest.php deleted file mode 100644 index cc5d03c..0000000 --- a/tests/Feature/Models/ReportTest.php +++ /dev/null @@ -1,12 +0,0 @@ -create(['status' => ApprovalStatus::PENDING]); - expect($report->status)->toBe(ApprovalStatus::PENDING); -}); diff --git a/tests/Feature/Models/SubClassificationTest.php b/tests/Feature/Models/SubClassificationTest.php deleted file mode 100644 index ef9c532..0000000 --- a/tests/Feature/Models/SubClassificationTest.php +++ /dev/null @@ -1,28 +0,0 @@ -create(['name' => 'Sub Test']); - - expect($sub->name)->toBe('Sub Test'); - expect($sub->classification)->toBeInstanceOf(Classification::class); -}); - -test('sub classification belongs to a classification', function () { - $parent = Classification::factory()->create(); - $sub = SubClassification::factory()->create(['classification_id' => $parent->id]); - - expect($sub->classification->id)->toBe($parent->id); -}); - -test('classification has many sub classifications relationship works', function () { - $parent = Classification::factory()->create(); - SubClassification::factory()->count(3)->create(['classification_id' => $parent->id]); - - expect($parent->subClassifications)->toHaveCount(3); -}); diff --git a/tests/Feature/Models/SubLocationTest.php b/tests/Feature/Models/SubLocationTest.php deleted file mode 100644 index 3261740..0000000 --- a/tests/Feature/Models/SubLocationTest.php +++ /dev/null @@ -1,15 +0,0 @@ -create(); - $sub = SubLocation::factory()->create(['location_id' => $parent->id]); - - expect($sub->location->id)->toBe($parent->id); - expect($parent->subLocations)->toHaveCount(1); -}); diff --git a/tests/Feature/Models/TaskAssignmentTest.php b/tests/Feature/Models/TaskAssignmentTest.php deleted file mode 100644 index e627ada..0000000 --- a/tests/Feature/Models/TaskAssignmentTest.php +++ /dev/null @@ -1,15 +0,0 @@ -create(); - $task = TaskAssignment::factory()->create(['cooperation_id' => $cooperation->id]); - - expect($task->cooperation->id)->toBe($cooperation->id); - expect($cooperation->taskAssignment->id)->toBe($task->id); -}); diff --git a/tests/Feature/Models/ThemeTest.php b/tests/Feature/Models/ThemeTest.php deleted file mode 100644 index e0b1172..0000000 --- a/tests/Feature/Models/ThemeTest.php +++ /dev/null @@ -1,13 +0,0 @@ -create(['name' => 'Politik']); - expect($theme->name)->toBe('Politik'); - expect($theme->is_active)->toBe(IsActive::ACTIVE); -}); diff --git a/tests/Feature/Models/UserTest.php b/tests/Feature/Models/UserTest.php deleted file mode 100644 index 8faf41e..0000000 --- a/tests/Feature/Models/UserTest.php +++ /dev/null @@ -1,57 +0,0 @@ -getGuarded())->toBe(['id']); -}); - -test('user has correct casts', function () { - $user = new User; - expect($user->getCasts())->toHaveKey('password', 'hashed'); - expect($user->getCasts())->toHaveKey('is_active', IsActive::class); -}); - -test('user can be created using factory', function () { - $user = User::factory()->create([ - 'name' => 'John Doe', - 'email' => 'john@example.com', - ]); - - expect($user->name)->toBe('John Doe'); - expect(Hash::check('password', $user->password))->toBeTrue(); - $this->assertDatabaseHas('users', ['email' => 'john@example.com']); -}); - -test('user active scope filters correctly', function () { - User::factory()->count(2)->create(['is_active' => IsActive::ACTIVE]); - User::factory()->count(1)->create(['is_active' => IsActive::INACTIVE]); - - expect(User::active()->count())->toBe(2); -}); - -test('user can access panel if active', function () { - $user = User::factory()->create(['is_active' => IsActive::ACTIVE]); - - // Default mock for Filament Panel if needed, but the method logic is simple - expect($user->canAccessPanel(mock(Panel::class)))->toBeTrue(); -}); - -test('user cannot access panel if inactive', function () { - $user = User::factory()->create(['is_active' => IsActive::INACTIVE]); - - expect($user->canAccessPanel(mock(Panel::class)))->toBeFalse(); -}); - -test('user has company relation', function () { - $user = User::factory()->create(); - expect($user->company())->toBeInstanceOf(HasOne::class); -}); diff --git a/tests/Feature/Models/VerificationRequestTest.php b/tests/Feature/Models/VerificationRequestTest.php deleted file mode 100644 index 0e7a255..0000000 --- a/tests/Feature/Models/VerificationRequestTest.php +++ /dev/null @@ -1,53 +0,0 @@ -getGuarded())->toBe(['id']); -}); - -test('verification request has correct casts', function () { - $request = new VerificationRequest; - expect($request->getCasts())->toHaveKey('status', VerificationStatus::class); -}); - -test('verification request can be created using factory', function () { - $request = VerificationRequest::factory()->create(); - - expect($request->status)->toBe(VerificationStatus::PENDING); - $this->assertDatabaseHas('verification_requests', ['id' => $request->id]); -}); - -test('verification request scopes filter correctly', function () { - VerificationRequest::factory()->count(2)->approved()->create(); - VerificationRequest::factory()->count(3)->pending()->create(); - VerificationRequest::factory()->count(1)->rejected()->create(); - VerificationRequest::factory()->count(1)->needRevision()->create(); - - expect(VerificationRequest::approved()->count())->toBe(2); - expect(VerificationRequest::pending()->count())->toBe(3); - expect(VerificationRequest::rejected()->count())->toBe(1); - expect(VerificationRequest::needRevision()->count())->toBe(1); -}); - -test('verification request belongs to company and user', function () { - $company = Company::factory()->create(); - $user = User::factory()->create(); - - $request = VerificationRequest::factory()->create([ - 'company_id' => $company->id, - 'submitted_by' => $user->id, - ]); - - expect($request->company)->toBeInstanceOf(Company::class); - expect($request->submittedBy)->toBeInstanceOf(User::class); - expect($request->company->id)->toBe($company->id); - expect($request->submittedBy->id)->toBe($user->id); -}); diff --git a/tests/Feature/Models/VerificationReviewTest.php b/tests/Feature/Models/VerificationReviewTest.php deleted file mode 100644 index 8e7c03d..0000000 --- a/tests/Feature/Models/VerificationReviewTest.php +++ /dev/null @@ -1,31 +0,0 @@ -create(); - $reviewer = User::factory()->create(); - - $review = VerificationReview::factory()->create([ - 'verification_request_id' => $request->id, - 'reviewer_id' => $reviewer->id, - 'decision' => DecisionAdmin::APPROVED, - ]); - - expect($review->decision)->toBe(DecisionAdmin::APPROVED); - expect($review->verificationRequest->id)->toBe($request->id); - expect($review->reviewer->id)->toBe($reviewer->id); -}); - -test('verification request has many reviews', function () { - $request = VerificationRequest::factory()->create(); - VerificationReview::factory()->count(2)->create(['verification_request_id' => $request->id]); - - expect($request->reviews)->toHaveCount(2); -}); diff --git a/tests/Feature/Models/VisitorTest.php b/tests/Feature/Models/VisitorTest.php deleted file mode 100644 index 08ea57e..0000000 --- a/tests/Feature/Models/VisitorTest.php +++ /dev/null @@ -1,13 +0,0 @@ -create(['ip' => '127.0.0.1']); - expect($visitor->ip)->toBe('127.0.0.1'); - expect($visitor->user)->toBeInstanceOf(User::class); -});