-
Notifications
You must be signed in to change notification settings - Fork 959
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9ca060a
commit d342a09
Showing
4 changed files
with
90 additions
and
23 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
namespace Tests\Feature; | ||
|
||
use App\User; | ||
use Tests\TestCase; | ||
|
||
class LoginTest extends TestCase | ||
{ | ||
/** @var \App\User */ | ||
protected $user; | ||
|
||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$this->user = factory(User::class)->create(); | ||
} | ||
|
||
/** @test */ | ||
public function can_authenticate() | ||
{ | ||
$this->postJson('/api/login', [ | ||
'email' => $this->user->email, | ||
'password' => 'secret', | ||
]) | ||
->assertSuccessful() | ||
->assertJsonStructure(['token', 'expires_in']) | ||
->assertJson(['token_type' => 'bearer']); | ||
} | ||
|
||
/** @test */ | ||
public function can_fetch_the_current_user() | ||
{ | ||
$this->actingAs($this->user) | ||
->getJson('/api/user') | ||
->assertSuccessful() | ||
->assertJsonStructure(['id', 'name', 'email']); | ||
} | ||
|
||
/** @test */ | ||
public function can_log_out() | ||
{ | ||
$token = $this->postJson('/api/login', [ | ||
'email' => $this->user->email, | ||
'password' => 'secret', | ||
])->json()['token']; | ||
|
||
$this->json('POST', "/api/logout?token=$token") | ||
->assertSuccessful(); | ||
|
||
$this->getJson("/api/user?token=$token") | ||
->assertStatus(401); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace Tests\Feature; | ||
|
||
use Tests\TestCase; | ||
|
||
class RegisterTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function can_register() | ||
{ | ||
$this->postJson('/api/register', [ | ||
'name' => 'Test User', | ||
'email' => '[email protected]', | ||
'password' => 'secret', | ||
'password_confirmation' => 'secret', | ||
]) | ||
->assertSuccessful() | ||
->assertJsonStructure(['id', 'name', 'email']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters