Skip to content

Commit 60314b3

Browse files
author
Jovert Lota Palonpon
committed
[Testing] Added authentication tests
1 parent c5cd9ba commit 60314b3

File tree

6 files changed

+53
-46
lines changed

6 files changed

+53
-46
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace Tests\Feature\Api\Auth;
4+
5+
use App\User;
6+
use Tests\Feature\Api\BaseTest;
7+
8+
class SessionsTest extends BaseTest
9+
{
10+
/** @test */
11+
public function a_user_can_be_identified()
12+
{
13+
$user = User::first();
14+
15+
$attributes = [
16+
'username' => $user->username,
17+
];
18+
19+
$this->post(route('api.auth.identify'), $attributes)
20+
->assertStatus(200)
21+
->assertSee($user->email);
22+
}
23+
24+
/** @test */
25+
public function a_user_can_be_authenticated()
26+
{
27+
$user = User::first();
28+
29+
$attributes = [
30+
'username' => $user->username,
31+
'password' => 'secret'
32+
];
33+
34+
$this->post(route('api.auth.signin'), $attributes)
35+
->assertStatus(200)
36+
->assertJsonStructure([
37+
'auth_token', 'token_type', 'expires_in'
38+
]);
39+
}
40+
}

tests/Feature/Api/BaseTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Tests\Feature\Api;
4+
5+
use Tests\TestCase;
6+
use Illuminate\Foundation\Testing\WithFaker;
7+
use Illuminate\Foundation\Testing\RefreshDatabase;
8+
9+
abstract class BaseTest extends TestCase
10+
{
11+
use WithFaker, RefreshDatabase;
12+
}

tests/Feature/Api/UsersTest.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,9 @@
33
namespace Tests\Feature\Api;
44

55
use App\User;
6-
use Tests\TestCase;
7-
use Illuminate\Foundation\Testing\WithFaker;
8-
use Illuminate\Foundation\Testing\RefreshDatabase;
96

10-
class UsersTest extends TestCase
7+
class UsersTest extends BaseTest
118
{
12-
use WithFaker, RefreshDatabase;
13-
149
/** @test */
1510
public function a_user_can_list_users()
1611
{

tests/Feature/ExampleTest.php

Lines changed: 0 additions & 21 deletions
This file was deleted.

tests/Unit/.gitkeep

Whitespace-only changes.

tests/Unit/ExampleTest.php

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)