mirror of
https://github.com/Bubka/2FAuth.git
synced 2024-12-03 22:01:45 +01:00
68 lines
1.4 KiB
PHP
68 lines
1.4 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace Tests\Unit;
|
||
|
|
||
|
use Tests\TestCase;
|
||
|
use Illuminate\Support\Facades\Artisan;
|
||
|
use Illuminate\Foundation\Testing\WithFaker;
|
||
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||
|
use Illuminate\Auth\Authenticatable;
|
||
|
|
||
|
class UserTest extends TestCase
|
||
|
{
|
||
|
|
||
|
/**
|
||
|
* Rollback and execute migrations for each test.
|
||
|
*/
|
||
|
use DatabaseTransactions;
|
||
|
|
||
|
|
||
|
/**
|
||
|
* set up fresh db
|
||
|
*/
|
||
|
public function setUp(): void
|
||
|
{
|
||
|
parent::setUp();
|
||
|
Artisan::call('migrate', ['--seed' => true]);
|
||
|
Artisan::call('passport:install',['--verbose' => 2]);
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* test User creation via API
|
||
|
*
|
||
|
* @return void
|
||
|
*/
|
||
|
public function testUserCreation()
|
||
|
{
|
||
|
$response = $this->json('POST', '/api/register', [
|
||
|
'name' => 'testCreate',
|
||
|
'email' => str_random(10) . '@test.com',
|
||
|
'password' => 'test',
|
||
|
]);
|
||
|
|
||
|
$response->assertStatus(200)->assertJsonStructure([
|
||
|
'success' => ['token', 'name']
|
||
|
]);
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* test User login via API
|
||
|
*
|
||
|
* @return void
|
||
|
*/
|
||
|
public function testUserLogin()
|
||
|
{
|
||
|
$response = $this->json('POST', '/api/login', [
|
||
|
'email' => 'test@test.com',
|
||
|
'password' => 'test'
|
||
|
]);
|
||
|
|
||
|
$response->assertStatus(200)->assertJsonStructure([
|
||
|
'success' => ['token']
|
||
|
]);
|
||
|
}
|
||
|
|
||
|
}
|