merge user dan role conflict resolved
This commit is contained in:
41
tests/Feature/RoleIndexTest.php
Normal file
41
tests/Feature/RoleIndexTest.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Role;
|
||||
use App\Models\User;
|
||||
|
||||
test('guests are redirected to login from roles page', function () {
|
||||
$this->get('/roles')->assertRedirect('/login');
|
||||
});
|
||||
|
||||
test('authenticated users can view the roles page', function () {
|
||||
$this->actingAs(User::factory()->create())
|
||||
->get('/roles')
|
||||
->assertOk()
|
||||
->assertViewIs('roles.index');
|
||||
});
|
||||
|
||||
test('roles page passes paginated roles to view', function () {
|
||||
$this->actingAs(User::factory()->create())
|
||||
->get('/roles')
|
||||
->assertOk()
|
||||
->assertViewHas('roles');
|
||||
});
|
||||
|
||||
test('ajax request returns roles table partial', function () {
|
||||
$this->actingAs(User::factory()->create())
|
||||
->withHeader('X-Requested-With', 'XMLHttpRequest')
|
||||
->get('/roles')
|
||||
->assertOk()
|
||||
->assertViewIs('roles._table');
|
||||
});
|
||||
|
||||
test('ajax pagination returns correct page', function () {
|
||||
Role::factory()->count(15)->create();
|
||||
|
||||
$this->actingAs(User::factory()->create())
|
||||
->withHeader('X-Requested-With', 'XMLHttpRequest')
|
||||
->get('/roles?page=2')
|
||||
->assertOk()
|
||||
->assertViewIs('roles._table')
|
||||
->assertViewHas('roles', fn ($roles) => $roles->currentPage() === 2);
|
||||
});
|
||||
52
tests/Feature/StoreRoleTest.php
Normal file
52
tests/Feature/StoreRoleTest.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Role;
|
||||
use App\Models\User;
|
||||
|
||||
test('guests cannot access the create role page', function () {
|
||||
$this->get('/roles/create')->assertRedirect('/login');
|
||||
});
|
||||
|
||||
test('authenticated users can access the create role page', function () {
|
||||
$this->actingAs(User::factory()->create())
|
||||
->get('/roles/create')
|
||||
->assertOk()
|
||||
->assertViewIs('roles.create');
|
||||
});
|
||||
|
||||
test('authenticated users can create a role', function () {
|
||||
$this->actingAs(User::factory()->create())
|
||||
->post('/roles', ['name' => 'Manager', 'description' => 'Manages things'])
|
||||
->assertRedirect(route('roles.index'))
|
||||
->assertSessionHas('status', 'role-created');
|
||||
|
||||
$this->assertDatabaseHas('roles', ['name' => 'Manager', 'description' => 'Manages things']);
|
||||
});
|
||||
|
||||
test('role name is required', function () {
|
||||
$this->actingAs(User::factory()->create())
|
||||
->post('/roles', ['name' => '', 'description' => 'Some description'])
|
||||
->assertSessionHasErrors('name');
|
||||
});
|
||||
|
||||
test('role name must be unique', function () {
|
||||
Role::factory()->create(['name' => 'Admin']);
|
||||
|
||||
$this->actingAs(User::factory()->create())
|
||||
->post('/roles', ['name' => 'Admin'])
|
||||
->assertSessionHasErrors('name');
|
||||
});
|
||||
|
||||
test('description is optional', function () {
|
||||
$this->actingAs(User::factory()->create())
|
||||
->post('/roles', ['name' => 'Viewer'])
|
||||
->assertRedirect(route('roles.index'));
|
||||
|
||||
$this->assertDatabaseHas('roles', ['name' => 'Viewer', 'description' => null]);
|
||||
});
|
||||
|
||||
test('guests cannot create a role', function () {
|
||||
$this->post('/roles', ['name' => 'Admin'])->assertRedirect('/login');
|
||||
|
||||
$this->assertDatabaseMissing('roles', ['name' => 'Admin']);
|
||||
});
|
||||
Reference in New Issue
Block a user