snipe-it/tests/Feature/Categories/Api/CreateCategoriesTest.php

61 lines
1.8 KiB
PHP
Raw Normal View History

<?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());
}
}