#118 - tests
This commit is contained in:
parent
63c7a3220e
commit
64032a7c73
@ -27,7 +27,7 @@
|
||||
scope="col"
|
||||
class="py-3 px-4 text-xs font-semibold tracking-wider text-left text-gray-500 uppercase whitespace-nowrap"
|
||||
>
|
||||
Nazwa
|
||||
Klucz
|
||||
</th>
|
||||
<th
|
||||
scope="col"
|
||||
|
118
tests/Feature/KeysTest.php
Normal file
118
tests/Feature/KeysTest.php
Normal file
@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use Inertia\Testing\AssertableInertia as Assert;
|
||||
use Tests\FeatureTestCase;
|
||||
use Toby\Eloquent\Models\Key;
|
||||
use Toby\Eloquent\Models\User;
|
||||
|
||||
class KeysTest extends FeatureTestCase
|
||||
{
|
||||
use DatabaseMigrations;
|
||||
|
||||
public function testUserCanSeeKeyList(): void
|
||||
{
|
||||
Key::factory()->count(10)->create();
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->assertDatabaseCount("keys", 10);
|
||||
|
||||
$this->actingAs($user)
|
||||
->get("/keys")
|
||||
->assertOk()
|
||||
->assertInertia(
|
||||
fn(Assert $page) => $page
|
||||
->component("Keys")
|
||||
->has("keys.data", 10),
|
||||
);
|
||||
}
|
||||
|
||||
public function testAdminCanCreateKey(): void
|
||||
{
|
||||
$admin = User::factory()->admin()->create();
|
||||
|
||||
$this->assertDatabaseMissing("keys", [
|
||||
"user_id" => $admin->id,
|
||||
]);
|
||||
|
||||
$this->actingAs($admin)
|
||||
->post("/keys")
|
||||
->assertSessionHasNoErrors()
|
||||
->assertRedirect();
|
||||
|
||||
$this->assertDatabaseHas("keys", [
|
||||
"user_id" => $admin->id,
|
||||
]);
|
||||
}
|
||||
|
||||
public function testUserCannotCreateKey(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->actingAs($user)
|
||||
->post("/keys")
|
||||
->assertForbidden();
|
||||
}
|
||||
|
||||
public function testAdminCanDeleteKey(): void
|
||||
{
|
||||
$admin = User::factory()->admin()->create();
|
||||
|
||||
$key = Key::factory()->create();
|
||||
|
||||
$this->actingAs($admin)
|
||||
->delete("/keys/{$key->id}")
|
||||
->assertRedirect();
|
||||
}
|
||||
|
||||
public function testUserCanTakeKeyFromAnotherUser(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$userWithKey = User::factory()->create();
|
||||
|
||||
$key = Key::factory()->for($userWithKey)->create();
|
||||
|
||||
$this->assertDatabaseHas("keys", [
|
||||
"id" => $key->id,
|
||||
"user_id" => $userWithKey->id,
|
||||
]);
|
||||
|
||||
$this->actingAs($user)
|
||||
->post("/keys/{$key->id}/take")
|
||||
->assertRedirect();
|
||||
|
||||
$this->assertDatabaseHas("keys", [
|
||||
"id" => $key->id,
|
||||
"user_id" => $user->id,
|
||||
]);
|
||||
}
|
||||
|
||||
public function testUserCanGiveTheirKeyToAnotherUser(): void
|
||||
{
|
||||
$userWithKey = User::factory()->create();
|
||||
$user = User::factory()->create();
|
||||
|
||||
$key = Key::factory()->for($userWithKey)->create();
|
||||
|
||||
$this->assertDatabaseHas("keys", [
|
||||
"id" => $key->id,
|
||||
"user_id" => $userWithKey->id,
|
||||
]);
|
||||
|
||||
$this->actingAs($userWithKey)
|
||||
->post("/keys/{$key->id}/give", [
|
||||
"user" => $user->id,
|
||||
])
|
||||
->assertSessionhasNoErrors()
|
||||
->assertRedirect();
|
||||
|
||||
$this->assertDatabaseHas("keys", [
|
||||
"id" => $key->id,
|
||||
"user_id" => $user->id,
|
||||
]);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user