ClearBowl/api/tests/Feature/UsersTest.php
2020-01-19 20:21:46 +01:00

54 lines
1.4 KiB
PHP

<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class UsersTest extends TestCase
{
use RefreshDatabase;
protected $loginData = ['email' => 'artur.nowakowski@gmail.com', 'password' => 'test123'];
protected function getToken()
{
$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']]);
}
}