mirror of
https://github.com/snipe/snipe-it.git
synced 2025-02-21 03:15:45 -08:00
Added category tests
Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
parent
96d1aea54a
commit
4089b4cd68
60
tests/Feature/Categories/Api/CreateCategoriesTest.php
Normal file
60
tests/Feature/Categories/Api/CreateCategoriesTest.php
Normal file
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Categories\Api;
|
||||
|
||||
use App\Models\Asset;
|
||||
use App\Models\AssetModel;
|
||||
use App\Models\Category;
|
||||
use App\Models\User;
|
||||
use Illuminate\Testing\Fluent\AssertableJson;
|
||||
use Tests\TestCase;
|
||||
|
||||
class CreateCategoriesTest extends TestCase
|
||||
{
|
||||
|
||||
|
||||
public function testRequiresPermissionToCreateCategory()
|
||||
{
|
||||
$this->actingAsForApi(User::factory()->create())
|
||||
->postJson(route('api.categories.store'))
|
||||
->assertForbidden();
|
||||
}
|
||||
|
||||
public function testCanCreateCategoryWithCategoryType()
|
||||
{
|
||||
$response = $this->actingAsForApi(User::factory()->superuser()->create())
|
||||
->postJson(route('api.categories.store'), [
|
||||
'name' => 'Test Category',
|
||||
'eula_text' => 'Test EULA',
|
||||
'category_type' => 'accessory',
|
||||
])
|
||||
->assertOk()
|
||||
->assertStatusMessageIs('success')
|
||||
->assertStatus(200)
|
||||
->json();
|
||||
|
||||
$this->assertTrue(Category::where('name', 'Test Category')->exists());
|
||||
|
||||
$category = Category::find($response['payload']['id']);
|
||||
$this->assertEquals('Test Category', $category->name);
|
||||
$this->assertEquals('Test EULA', $category->eula_text);
|
||||
$this->assertEquals('accessory', $category->category_type);
|
||||
}
|
||||
|
||||
public function testCannotCreateCategoryWithoutCategoryType()
|
||||
{
|
||||
$this->actingAsForApi(User::factory()->superuser()->create())
|
||||
->postJson(route('api.categories.store'), [
|
||||
'name' => 'Test Category',
|
||||
'eula_text' => 'Test EULA',
|
||||
])
|
||||
->assertOk()
|
||||
->assertStatusMessageIs('error')
|
||||
->assertStatus(200)
|
||||
->json();
|
||||
|
||||
$this->assertFalse(Category::where('name', 'Test Category')->exists());
|
||||
|
||||
}
|
||||
|
||||
}
|
56
tests/Feature/Categories/Api/UpdateCategoryTest.php
Normal file
56
tests/Feature/Categories/Api/UpdateCategoryTest.php
Normal file
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Categories\Api;
|
||||
|
||||
use App\Models\Category;
|
||||
use App\Models\User;
|
||||
use Tests\TestCase;
|
||||
|
||||
class UpdateCategoriesTest extends TestCase
|
||||
{
|
||||
|
||||
public function testCanUpdateCategoryViaPatchWithoutCategoryType()
|
||||
{
|
||||
$category = Category::factory()->create();
|
||||
|
||||
$this->actingAsForApi(User::factory()->superuser()->create())
|
||||
->patchJson(route('api.categories.update', $category), [
|
||||
'name' => 'Test Category',
|
||||
'eula_text' => 'Test EULA',
|
||||
])
|
||||
->assertOk()
|
||||
->assertStatusMessageIs('success')
|
||||
->assertStatus(200)
|
||||
->json();
|
||||
|
||||
//dd($response);
|
||||
$category->refresh();
|
||||
$this->assertEquals('Test Category', $category->name, 'Name was not updated');
|
||||
$this->assertEquals('Test EULA', $category->eula_text, 'EULA was not updated');
|
||||
|
||||
}
|
||||
|
||||
public function testCannotUpdateCategoryViaPatchWithCategoryType()
|
||||
{
|
||||
$category = Category::factory()->create();
|
||||
|
||||
$this->actingAsForApi(User::factory()->superuser()->create())
|
||||
->patchJson(route('api.categories.update', $category), [
|
||||
'name' => 'Test Category',
|
||||
'eula_text' => 'Test EULA',
|
||||
'category_type' => 'accessory',
|
||||
])
|
||||
->assertOk()
|
||||
->assertStatusMessageIs('error')
|
||||
->assertStatus(200)
|
||||
->json();
|
||||
|
||||
//dd($response);
|
||||
$category->refresh();
|
||||
$this->assertNotEquals('Test Category', $category->name, 'Name was not updated');
|
||||
$this->assertNotEquals('Test EULA', $category->eula_text, 'EULA was not updated');
|
||||
$this->assertNotEquals('accessory', $category->category_type, 'EULA was not updated');
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue