mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-12 14:27:33 -08:00
Added basic Department UI tests
Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
parent
1d65781d8d
commit
0a7e053985
23
tests/Feature/Departments/Api/CreateDepartmentsTest.php
Normal file
23
tests/Feature/Departments/Api/CreateDepartmentsTest.php
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Department\Api;
|
||||
|
||||
use App\Models\AssetModel;
|
||||
use App\Models\Department;
|
||||
use App\Models\Category;
|
||||
use App\Models\User;
|
||||
use Illuminate\Testing\Fluent\AssertableJson;
|
||||
use Tests\TestCase;
|
||||
|
||||
class CreateDepartmentsTest extends TestCase
|
||||
{
|
||||
|
||||
|
||||
public function testRequiresPermissionToCreateDepartment()
|
||||
{
|
||||
$this->actingAsForApi(User::factory()->create())
|
||||
->postJson(route('api.departments.store'))
|
||||
->assertForbidden();
|
||||
}
|
||||
|
||||
}
|
|
@ -8,7 +8,7 @@ use App\Models\User;
|
|||
use Illuminate\Testing\Fluent\AssertableJson;
|
||||
use Tests\TestCase;
|
||||
|
||||
class DepartmentIndexTest extends TestCase
|
||||
class DepartmentsIndexTest extends TestCase
|
||||
{
|
||||
public function testViewingDepartmentIndexRequiresAuthentication()
|
||||
{
|
41
tests/Feature/Departments/Api/UpdateDepartmentTest.php
Normal file
41
tests/Feature/Departments/Api/UpdateDepartmentTest.php
Normal file
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Departments\Api;
|
||||
|
||||
use App\Models\Department;
|
||||
use App\Models\Category;
|
||||
use App\Models\User;
|
||||
use Tests\TestCase;
|
||||
|
||||
class UpdateDepartmentsTest extends TestCase
|
||||
{
|
||||
|
||||
public function testRequiresPermissionToEditDepartment()
|
||||
{
|
||||
$department = Department::factory()->create();
|
||||
$this->actingAsForApi(User::factory()->create())
|
||||
->patchJson(route('api.departments.update', $department))
|
||||
->assertForbidden();
|
||||
}
|
||||
|
||||
public function testCanUpdateDepartmentViaPatch()
|
||||
{
|
||||
$department = Department::factory()->create();
|
||||
|
||||
$this->actingAsForApi(User::factory()->superuser()->create())
|
||||
->patchJson(route('api.departments.update', $department), [
|
||||
'name' => 'Test Department',
|
||||
])
|
||||
->assertOk()
|
||||
->assertStatusMessageIs('success')
|
||||
->assertStatus(200)
|
||||
->json();
|
||||
|
||||
$department->refresh();
|
||||
$this->assertEquals('Test Department', $department->name, 'Name was not updated');
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
37
tests/Feature/Departments/Ui/CreateDepartmentsTest.php
Normal file
37
tests/Feature/Departments/Ui/CreateDepartmentsTest.php
Normal file
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Departments\Ui;
|
||||
|
||||
use App\Models\Department;
|
||||
use App\Models\Company;
|
||||
use App\Models\User;
|
||||
use Tests\TestCase;
|
||||
|
||||
class CreateDepartmentsTest extends TestCase
|
||||
{
|
||||
public function testPermissionRequiredToCreateDepartment()
|
||||
{
|
||||
$this->actingAs(User::factory()->create())
|
||||
->post(route('departments.store'), [
|
||||
'name' => 'Test Department',
|
||||
'company_id' => Company::factory()->create()->id
|
||||
])
|
||||
->assertForbidden();
|
||||
}
|
||||
|
||||
public function testUserCanCreateDepartments()
|
||||
{
|
||||
$this->assertFalse(Department::where('name', 'Test Department')->exists());
|
||||
|
||||
$this->actingAs(User::factory()->superuser()->create())
|
||||
->post(route('departments.store'), [
|
||||
'name' => 'Test Department',
|
||||
'company_id' => Company::factory()->create()->id
|
||||
])
|
||||
->assertRedirect(route('departments.index'));
|
||||
|
||||
$this->assertTrue(Department::where('name', 'Test Department')->exists());
|
||||
}
|
||||
|
||||
|
||||
}
|
23
tests/Feature/Departments/Ui/IndexDepartmentsTest.php
Normal file
23
tests/Feature/Departments/Ui/IndexDepartmentsTest.php
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Departments\Ui;
|
||||
|
||||
use App\Models\User;
|
||||
use Tests\TestCase;
|
||||
|
||||
class IndexDepartmentsTest extends TestCase
|
||||
{
|
||||
public function testPermissionRequiredToViewDepartmentsList()
|
||||
{
|
||||
$this->actingAs(User::factory()->create())
|
||||
->get(route('departments.index'))
|
||||
->assertForbidden();
|
||||
}
|
||||
|
||||
public function testUserCanListDepartments()
|
||||
{
|
||||
$this->actingAs(User::factory()->superuser()->create())
|
||||
->get(route('departments.index'))
|
||||
->assertOk();
|
||||
}
|
||||
}
|
61
tests/Feature/Departments/Ui/UpdateDepartmentsTest.php
Normal file
61
tests/Feature/Departments/Ui/UpdateDepartmentsTest.php
Normal file
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Departments\Ui;
|
||||
|
||||
use App\Models\Department;
|
||||
use App\Models\Category;
|
||||
use App\Models\User;
|
||||
use Tests\TestCase;
|
||||
|
||||
class UpdateDepartmentsTest extends TestCase
|
||||
{
|
||||
public function testPermissionRequiredToStoreDepartment()
|
||||
{
|
||||
$this->actingAs(User::factory()->create())
|
||||
->post(route('departments.store'), [
|
||||
'name' => 'Test Department',
|
||||
'category_id' => Category::factory()->create()->id
|
||||
])
|
||||
->assertStatus(403)
|
||||
->assertForbidden();
|
||||
}
|
||||
|
||||
public function testUserCanCreateDepartments()
|
||||
{
|
||||
$this->assertFalse(Department::where('name', 'Test Department')->exists());
|
||||
|
||||
$this->actingAs(User::factory()->superuser()->create())
|
||||
->post(route('departments.store'), [
|
||||
'name' => 'Test Department',
|
||||
'category_id' => Category::factory()->create()->id
|
||||
])
|
||||
->assertStatus(302)
|
||||
->assertSessionHasNoErrors()
|
||||
->assertRedirect(route('departments.index'));
|
||||
|
||||
$this->assertTrue(Department::where('name', 'Test Department')->exists());
|
||||
}
|
||||
|
||||
public function testUserCanEditDepartments()
|
||||
{
|
||||
$category = Category::factory()->forAssets()->create();
|
||||
$department = Department::factory()->create(['name' => 'Test Department']);
|
||||
$this->assertTrue(Department::where('name', 'Test Department')->exists());
|
||||
|
||||
$response = $this->actingAs(User::factory()->superuser()->create())
|
||||
->put(route('departments.update', ['department' => $department]), [
|
||||
'name' => 'Test Department Edited',
|
||||
'category_id' => $department->category_id,
|
||||
])
|
||||
->assertStatus(302)
|
||||
->assertSessionHasNoErrors()
|
||||
->assertRedirect(route('departments.index'));
|
||||
|
||||
$this->followRedirects($response)->assertSee('Success');
|
||||
$this->assertTrue(Department::where('name', 'Test Department Edited')->exists());
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in a new issue