Skip to content

A free open source IT asset/license management system

Fleshed out tests

snipea0914ccb2883
diff --git a/tests/Feature/Categories/Api/CreateCategoriesTest.php b/tests/Feature/Categories/Api/CreateCategoriesTest.php
index db5810cf14..fc464242af 100644
--- a/tests/Feature/Categories/Api/CreateCategoriesTest.php
+++ b/tests/Feature/Categories/Api/CreateCategoriesTest.php
@@ -20,7 +20,7 @@ class CreateCategoriesTest extends TestCase
->assertForbidden();
}
- public function testCanCreateCategoryWithCategoryType()
+ public function testCanCreateCategoryWithValidCategoryType()
{
$response = $this->actingAsForApi(User::factory()->superuser()->create())
->postJson(route('api.categories.store'), [
@@ -42,17 +42,40 @@ class CreateCategoriesTest extends TestCase
}
public function testCannotCreateCategoryWithoutCategoryType()
+ {
+ $response = $this->actingAsForApi(User::factory()->superuser()->create())
+ ->postJson(route('api.categories.store'), [
+ 'name' => 'Test Category',
+ ])
+ ->assertOk()
+ ->assertStatus(200)
+ ->assertStatusMessageIs('error')
+ ->assertJson([
+ 'messages' => [
+ 'category_type' => ['The category type field is required.'],
+ ],
+ ]);
+ $this->assertFalse(Category::where('name', 'Test Category')->exists());
+
+ }
+
+ public function testCannotCreateCategoryWithInvalidCategoryType()
{
$this->actingAsForApi(User::factory()->superuser()->create())
->postJson(route('api.categories.store'), [
'name' => 'Test Category',
'eula_text' => 'Test EULA',
+ 'category_type' => 'invalid',
])
->assertOk()
- ->assertStatusMessageIs('error')
->assertStatus(200)
- ->json();
-
+ ->assertStatusMessageIs('error')
+ ->assertJson([
+ 'messages' => [
+ 'category_type' => ['The selected category type is invalid.'],
+ ],
+ ]);
+
$this->assertFalse(Category::where('name', 'Test Category')->exists());
}