Files
exchange/tests/Feature/LoginTest.php
T
Jack Goh 72a4f6645f Added marking to admin home page
Merge branch 'master' of gitlab.com:CIEFWorldwideSdnBhd/exchange into fix/marking

# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
2018-07-08 10:53:24 +08:00

56 lines
1.3 KiB
PHP

<?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();
$this->withoutExceptionHandling();
}
/** @test */
public function authenticate()
{
$this->postJson('/api/login', [
'email' => $this->user->email,
'password' => 'secret',
])
->assertSuccessful()
->assertJsonStructure(['token', 'expires_in'])
->assertJson(['token_type' => 'bearer']);
}
/** @test */
public function fetch_the_current_user()
{
$this->actingAs($this->user)
->getJson('/api/user')
->assertSuccessful()
->assertJsonStructure(['id', 'name', 'email', 'marking']);
}
/** @test */
public function log_out()
{
$token = $this->postJson('/api/login', [
'email' => $this->user->email,
'password' => 'secret',
])->json()['token'];
$this->postJson("/api/logout?token=$token")
->assertSuccessful();
$this->getJson("/api/user?token=$token")
->assertStatus(401);
}
}