mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-15 01:54:09 -08:00
61 lines
1.8 KiB
PHP
61 lines
1.8 KiB
PHP
|
<?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());
|
||
|
|
||
|
}
|
||
|
|
||
|
}
|