mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-10-24 11:39:21 +02:00
69 lines
1.5 KiB
PHP
69 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Feature\Http\Api\Wiki\Group;
|
|
|
|
use App\Enums\Auth\CrudPermission;
|
|
use App\Models\Auth\User;
|
|
use App\Models\Wiki\Group;
|
|
use Laravel\Sanctum\Sanctum;
|
|
use Tests\TestCase;
|
|
|
|
/**
|
|
* Class GroupStoreTest.
|
|
*/
|
|
class GroupStoreTest extends TestCase
|
|
{
|
|
/**
|
|
* The Group Store Endpoint shall be protected by sanctum.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function testProtected(): void
|
|
{
|
|
$group = Group::factory()->makeOne();
|
|
|
|
$response = $this->post(route('api.group.store', $group->toArray()));
|
|
|
|
$response->assertUnauthorized();
|
|
}
|
|
|
|
/**
|
|
* The Group Store Endpoint shall forbid users without the create group permission.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function testForbidden(): void
|
|
{
|
|
$group = Group::factory()->makeOne();
|
|
|
|
$user = User::factory()->createOne();
|
|
|
|
Sanctum::actingAs($user);
|
|
|
|
$response = $this->post(route('api.group.store', $group->toArray()));
|
|
|
|
$response->assertForbidden();
|
|
}
|
|
|
|
/**
|
|
* The Group Store Endpoint shall create a group.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function testCreate(): void
|
|
{
|
|
$parameters = Group::factory()->raw();
|
|
|
|
$user = User::factory()->withPermissions(CrudPermission::CREATE->format(Group::class))->createOne();
|
|
|
|
Sanctum::actingAs($user);
|
|
|
|
$response = $this->post(route('api.group.store', $parameters));
|
|
|
|
$response->assertCreated();
|
|
static::assertDatabaseCount(Group::class, 1);
|
|
}
|
|
}
|