Files
vuefilemanager/tests/Feature/UserTest.php
Peter Papp b7e1be7518 - implement factories into models
- Model class refactored in relations
2021-02-26 17:57:21 +01:00

106 lines
2.4 KiB
PHP

<?php
namespace Tests\Feature;
use App\Models\File;
use App\Models\Folder;
use App\Models\User;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Laravel\Sanctum\Sanctum;
use Tests\TestCase;
class UserTest extends TestCase
{
use DatabaseMigrations;
/**
* @test
*/
public function it_generate_and_store_user()
{
$user = User::factory(User::class)
->create(['role' => 'user']);
$this->assertDatabaseHas('users', [
'id' => $user->id,
'role' => 'user',
]);
$this->assertDatabaseHas('user_settings', [
'user_id' => $user->id,
]);
}
/**
* @test
*/
public function it_register_user_via_public_api()
{
$this->postJson('/register', [
'email' => 'john@doe.com',
'password' => 'SecretPassword',
'password_confirmation' => 'SecretPassword',
'name' => 'John Doe',
])->assertStatus(201);
$this->assertDatabaseHas('users', [
'email' => 'john@doe.com',
]);
$this->assertDatabaseHas('user_settings', [
'name' => 'John Doe',
]);
}
/**
* @test
*/
public function it_login_user_via_post_request()
{
$user = User::factory(User::class)
->create(['email' => 'john@doe.com']);
$this->postJson('/login', [
'email' => $user->email,
'password' => 'secret',
])->assertStatus(200);
}
/**
* @test
*/
public function it_change_user_password_via_post_request()
{
$user = User::factory(User::class)
->create();
Sanctum::actingAs($user);
$this->putJson('/user/password', [
'current_password' => 'secret',
'password' => 'VerySecretPassword',
'password_confirmation' => 'VerySecretPassword',
])->assertStatus(200);
}
/**
* @test
*/
public function it_update_user_settings()
{
$user = User::factory(User::class)
->create();
Sanctum::actingAs($user);
$this->patchJson('/api/user/relationships/settings', [
'name' => 'address',
'value' => 'Jantar',
])->assertStatus(204);
$this->assertDatabaseHas('user_settings', [
'address' => 'Jantar',
]);
}
}