AuthControllerInvalidTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
c 1
b 0
f 0
dl 0
loc 42
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testLoginWithInvalidCredentials() 0 14 1
A testLoginWithInactiveUser() 0 20 1
1
<?php
2
3
namespace Tests\Feature;
4
5
use Tests\TestCase;
6
use App\Models\Employee;
7
use Illuminate\Foundation\Testing\DatabaseMigrations;
8
9
class AuthControllerInvalidTest extends TestCase
10
{
11
    use DatabaseMigrations;
12
13
    protected $authUri = 'api/v1/backoffice/login';
14
15
    public function testLoginWithInvalidCredentials()
16
    {
17
        //When we try to login passing wrong credentials
18
        $payload = [
19
            'login' => 'foo',
20
            'password' => 'bar',
21
        ];
22
23
        $response = $this->json('POST', $this->authUri, $payload);
24
25
        // It should return an error invalid_credentials
26
        $response
27
            ->assertStatus(401)
28
            ->assertJson([ 'error' => 'invalid_credentials' ]);
29
    }
30
31
    public function testLoginWithInactiveUser()
32
    {
33
        // We create 1 inactive employee
34
        $user = factory(Employee::class)->make();
35
        $user->password = bcrypt('teste123');
36
        $user->active = false;
37
        $user->save();
38
39
        //When we try to login with an inactive employee
40
        $credentials = [
41
            'login' => $user->email,
42
            'password' => 'teste123',
43
        ];
44
45
        $response = $this->json('POST', $this->authUri, $credentials);
46
47
        // It should return an error inactive
48
        $response
49
            ->assertStatus(401)
50
            ->assertJson([ 'error' => 'inactive' ]);
51
    }
52
}
53