add tests for admin reception screen
This commit is contained in:
parent
77d0f5e65a
commit
e2fab4b9bd
|
@ -0,0 +1,131 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ReceptionScreenTest extends TestCase
|
||||
{
|
||||
private User $adminUser;
|
||||
private User $noAdminUser;
|
||||
private array $user;
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->user = User::factory()->make()->only([
|
||||
'name',
|
||||
'email',
|
||||
'password'
|
||||
]);
|
||||
$this->adminUser = User::factory()->create([
|
||||
'name' => 'admin',
|
||||
'email' => 'test@example.com',
|
||||
'password' => 123456
|
||||
]);
|
||||
$this->noAdminUser = User::factory()->create([
|
||||
'name' => 'noadmin',
|
||||
'email' => 'notest@example.com',
|
||||
'password' => 'no123456'
|
||||
]);
|
||||
}
|
||||
public function testUsersPage(): void
|
||||
{
|
||||
$response = $this->actingAs($this->adminUser)
|
||||
->withSession(['banned' => false])
|
||||
->get(route('users.index'));
|
||||
|
||||
$response->assertOk();
|
||||
}
|
||||
|
||||
public function testNoAdminNoSeeUsersPage(): void
|
||||
{
|
||||
$response = $this->actingAs($this->noAdminUser)
|
||||
->withSession(['banned' => false])
|
||||
->get(route('users.index'));
|
||||
|
||||
$response->assertStatus(403);
|
||||
}
|
||||
|
||||
public function testCreateUserPage(): void
|
||||
{
|
||||
$response = $this->actingAs($this->adminUser)
|
||||
->withSession(['banned' => false])
|
||||
->get(route('users.create'));
|
||||
|
||||
$response->assertOk();
|
||||
}
|
||||
public function testNoAdminCreateUserPage(): void
|
||||
{
|
||||
$response = $this->actingAs($this->noAdminUser)
|
||||
->withSession(['banned' => false])
|
||||
->get(route('users.create'));
|
||||
|
||||
$response->assertStatus(403);
|
||||
}
|
||||
|
||||
public function testStoreUser(): void
|
||||
{
|
||||
$response = $this->actingAs($this->adminUser)
|
||||
->withSession(['banned' => false])
|
||||
->post(route('users.store', $this->user));
|
||||
|
||||
$response->assertRedirect(route('users.index'));
|
||||
|
||||
$this->assertDatabaseHas('users', $this->user);
|
||||
}
|
||||
|
||||
public function testNoAdminNoStoreUser(): void
|
||||
{
|
||||
$response = $this->actingAs($this->noAdminUser)
|
||||
->withSession(['banned' => false])
|
||||
->post(route('users.store', $this->user));
|
||||
|
||||
$response->assertStatus(403);
|
||||
|
||||
$this->assertDatabaseMissing('users', $this->user);
|
||||
}
|
||||
|
||||
public function testEditUserPage(): void
|
||||
{
|
||||
$response = $this->actingAs($this->adminUser)
|
||||
->withSession(['banned' => false])
|
||||
->get(route('users.edit', $this->adminUser));
|
||||
|
||||
$response->assertOk();
|
||||
}
|
||||
public function testNoAdminEditUserPage(): void
|
||||
{
|
||||
$response = $this->actingAs($this->noAdminUser)
|
||||
->withSession(['banned' => false])
|
||||
->get(route('users.edit', $this->noAdminUser));
|
||||
|
||||
$response->assertStatus(403);
|
||||
}
|
||||
|
||||
public function testUpdateUser(): void
|
||||
{
|
||||
$response = $this->actingAs($this->adminUser)
|
||||
->withSession(['banned' => false])
|
||||
->patch(route('users.update', $this->noAdminUser), $this->user);
|
||||
|
||||
$response->assertRedirect(route('users.index'));
|
||||
|
||||
$dataWithOutHashPassword = $this->user;
|
||||
unset($dataWithOutHashPassword['password']);
|
||||
$this->assertDatabaseHas('users', $dataWithOutHashPassword);
|
||||
}
|
||||
|
||||
public function testNoAdminNoUpdateUser(): void
|
||||
{
|
||||
$response = $this->actingAs($this->noAdminUser)
|
||||
->withSession(['banned' => false])
|
||||
->patch(route('users.update', $this->noAdminUser), $this->user);
|
||||
|
||||
$response->assertStatus(403);
|
||||
|
||||
$noAdminData = $this->noAdminUser->only(['name', 'email', 'password']);
|
||||
$this->assertDatabaseHas('users', $noAdminData);
|
||||
$this->assertDatabaseMissing('users', $this->user);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue