2019-11-30 18:19:13 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature;
|
|
|
|
|
|
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
class UsersTest extends TestCase
|
|
|
|
{
|
|
|
|
use RefreshDatabase;
|
|
|
|
|
2020-01-19 20:21:41 +01:00
|
|
|
protected $loginData = ['email' => 'artur.nowakowski@gmail.com', 'password' => 'test123'];
|
2019-11-30 18:19:13 +01:00
|
|
|
|
2020-01-19 20:21:41 +01:00
|
|
|
protected function getToken()
|
2019-11-30 18:19:13 +01:00
|
|
|
{
|
|
|
|
$response = $this->post('http://localhost:8000/api/user/login', $this->loginData)->decodeResponseJson();
|
|
|
|
|
|
|
|
return $response['data']['token'];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A basic test example.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testRegistration()
|
|
|
|
{
|
|
|
|
|
|
|
|
$response = $this->post('http://localhost:8000/api/user/register', $this->loginData);
|
|
|
|
|
|
|
|
$response->assertStatus(200);
|
|
|
|
$response->assertJsonStructure(['success', 'data' => ['token']]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testLogin()
|
|
|
|
{
|
|
|
|
$this->testRegistration();
|
|
|
|
$response = $this->post('http://localhost:8000/api/user/login', $this->loginData);
|
|
|
|
|
|
|
|
$response->assertStatus(200);
|
|
|
|
$response->assertJsonStructure(['success', 'data' => ['token']]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testMe()
|
|
|
|
{
|
|
|
|
$this->testRegistration();
|
|
|
|
$token = $this->getToken();
|
|
|
|
$response = $this->get('http://localhost:8000/api/user/me', ['Authorization' => "Bearer $token"]);
|
|
|
|
|
|
|
|
$response->assertStatus(200);
|
|
|
|
$response->assertJsonStructure(['success', 'data' => ['email', 'role']]);
|
|
|
|
}
|
|
|
|
}
|