Fleshed out tests

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2024-07-05 03:22:56 +01:00
parent efb9d107cf
commit a0914ccb28

View file

@ -20,7 +20,7 @@ class CreateCategoriesTest extends TestCase
->assertForbidden(); ->assertForbidden();
} }
public function testCanCreateCategoryWithCategoryType() public function testCanCreateCategoryWithValidCategoryType()
{ {
$response = $this->actingAsForApi(User::factory()->superuser()->create()) $response = $this->actingAsForApi(User::factory()->superuser()->create())
->postJson(route('api.categories.store'), [ ->postJson(route('api.categories.store'), [
@ -42,17 +42,40 @@ class CreateCategoriesTest extends TestCase
} }
public function testCannotCreateCategoryWithoutCategoryType() 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()) $this->actingAsForApi(User::factory()->superuser()->create())
->postJson(route('api.categories.store'), [ ->postJson(route('api.categories.store'), [
'name' => 'Test Category', 'name' => 'Test Category',
'eula_text' => 'Test EULA', 'eula_text' => 'Test EULA',
'category_type' => 'invalid',
]) ])
->assertOk() ->assertOk()
->assertStatusMessageIs('error')
->assertStatus(200) ->assertStatus(200)
->json(); ->assertStatusMessageIs('error')
->assertJson([
'messages' => [
'category_type' => ['The selected category type is invalid.'],
],
]);
$this->assertFalse(Category::where('name', 'Test Category')->exists()); $this->assertFalse(Category::where('name', 'Test Category')->exists());
} }