|
|
|
@ -10,16 +10,21 @@ use App\Models\User;
|
|
|
|
|
|
|
|
|
|
class UserTest extends TestCase
|
|
|
|
|
{
|
|
|
|
|
protected $username = 'Oleg';
|
|
|
|
|
protected $matrix_username = '@oleg:oleg.com';
|
|
|
|
|
protected $phone = '380671231212';
|
|
|
|
|
|
|
|
|
|
protected $not_existing_user = [
|
|
|
|
|
'username' => 'Kostia',
|
|
|
|
|
'matrix_username' => '@kostia:kostia.com',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
public function test_register_new_user(): void
|
|
|
|
|
{
|
|
|
|
|
$username = 'Oleg';
|
|
|
|
|
$matrix_username = 'Oleg@oleg.com';
|
|
|
|
|
$phone = '380671231212';
|
|
|
|
|
|
|
|
|
|
$response = $this->post('/api/v2/register', [
|
|
|
|
|
'username' => $username,
|
|
|
|
|
'matrix_username' => $matrix_username,
|
|
|
|
|
'phone' => $phone,
|
|
|
|
|
'username' => $this->username,
|
|
|
|
|
'matrix_username' => $this->matrix_username,
|
|
|
|
|
'phone' => $this->phone,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response->assertStatus(200);
|
|
|
|
@ -29,60 +34,57 @@ class UserTest extends TestCase
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertDatabaseHas('users', [
|
|
|
|
|
'username' => $username
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$user = User::where('username', $username)->first();
|
|
|
|
|
$user->delete();
|
|
|
|
|
|
|
|
|
|
$this->assertDatabaseMissing('users', [
|
|
|
|
|
'username' => $username
|
|
|
|
|
'username' => $this->username
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function test_register_existing_user(): void
|
|
|
|
|
{
|
|
|
|
|
$username = 'Oleg';
|
|
|
|
|
$matrix_username = 'Oleg@oleg.com';
|
|
|
|
|
$phone = '380671231212';
|
|
|
|
|
|
|
|
|
|
$response = $this->post('/api/v2/register', [
|
|
|
|
|
'username' => $username,
|
|
|
|
|
'matrix_username' => $matrix_username,
|
|
|
|
|
'phone' => $phone,
|
|
|
|
|
'username' => $this->username,
|
|
|
|
|
'matrix_username' => $this->matrix_username,
|
|
|
|
|
'phone' => $this->phone,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response->assertStatus(200);
|
|
|
|
|
|
|
|
|
|
$response->assertJson([
|
|
|
|
|
'ok' => 'A user with the username registered successfully.'
|
|
|
|
|
'error' => 'A user with the username already exists!!!'
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->assertDatabaseHas('users', [
|
|
|
|
|
'username' => $username
|
|
|
|
|
]);
|
|
|
|
|
public function test_login_not_existing_user(): void
|
|
|
|
|
{
|
|
|
|
|
$response = $this->post('/api/v2/login', $this->not_existing_user);
|
|
|
|
|
|
|
|
|
|
// trying create again
|
|
|
|
|
$response->assertStatus(200);
|
|
|
|
|
|
|
|
|
|
$response = $this->post('/api/v2/register', [
|
|
|
|
|
'username' => $username,
|
|
|
|
|
'matrix_username' => $matrix_username,
|
|
|
|
|
'phone' => $phone,
|
|
|
|
|
$response->assertJson([
|
|
|
|
|
'error' => 'A user with the username does not exist!!!'
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function test_login_existing_user(): void
|
|
|
|
|
{
|
|
|
|
|
$response = $this->post('/api/v2/login', [
|
|
|
|
|
'username' => $this->username,
|
|
|
|
|
'matrix_username' => $this->matrix_username,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response->assertStatus(200);
|
|
|
|
|
|
|
|
|
|
$response->assertJson([
|
|
|
|
|
'error' => 'A user with the username already exists!!!'
|
|
|
|
|
'ok' => 'Login was successful.'
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// removing new user
|
|
|
|
|
|
|
|
|
|
$user = User::where('username', $username)->first();
|
|
|
|
|
public function test_removing_user(): void
|
|
|
|
|
{
|
|
|
|
|
$user = User::where('username', $this->username)->first();
|
|
|
|
|
$user->delete();
|
|
|
|
|
|
|
|
|
|
$this->assertDatabaseMissing('users', [
|
|
|
|
|
'username' => $username
|
|
|
|
|
'username' => $this->username
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|