mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-07-11 01:24:46 +02:00
2e930b17ff
* feat: initial migration to Laravel 10 * style: fix StyleCI findings
87 lines
2.0 KiB
PHP
87 lines
2.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Feature\Http\Api\Admin\Dump;
|
|
|
|
use App\Enums\Auth\CrudPermission;
|
|
use App\Models\Admin\Dump;
|
|
use App\Models\Auth\User;
|
|
use Laravel\Sanctum\Sanctum;
|
|
use Tests\TestCase;
|
|
|
|
/**
|
|
* Class DumpStoreTest.
|
|
*/
|
|
class DumpStoreTest extends TestCase
|
|
{
|
|
/**
|
|
* The Dump Store Endpoint shall be protected by sanctum.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function testProtected(): void
|
|
{
|
|
$dump = Dump::factory()->makeOne();
|
|
|
|
$response = $this->post(route('api.dump.store', $dump->toArray()));
|
|
|
|
$response->assertUnauthorized();
|
|
}
|
|
|
|
/**
|
|
* The Dump Store Endpoint shall forbid users without the create dump permission.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function testForbidden(): void
|
|
{
|
|
$dump = Dump::factory()->makeOne();
|
|
|
|
$user = User::factory()->createOne();
|
|
|
|
Sanctum::actingAs($user);
|
|
|
|
$response = $this->post(route('api.dump.store', $dump->toArray()));
|
|
|
|
$response->assertForbidden();
|
|
}
|
|
|
|
/**
|
|
* The Dump Store Endpoint shall require the path field.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function testRequiredFields(): void
|
|
{
|
|
$user = User::factory()->withPermissions(CrudPermission::CREATE()->format(Dump::class))->createOne();
|
|
|
|
Sanctum::actingAs($user);
|
|
|
|
$response = $this->post(route('api.dump.store'));
|
|
|
|
$response->assertJsonValidationErrors([
|
|
Dump::ATTRIBUTE_PATH,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* The Dump Store Endpoint shall create a dump.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function testCreate(): void
|
|
{
|
|
$parameters = Dump::factory()->raw();
|
|
|
|
$user = User::factory()->withPermissions(CrudPermission::CREATE()->format(Dump::class))->createOne();
|
|
|
|
Sanctum::actingAs($user);
|
|
|
|
$response = $this->post(route('api.dump.store', $parameters));
|
|
|
|
$response->assertCreated();
|
|
static::assertDatabaseCount(Dump::TABLE, 1);
|
|
}
|
|
}
|