Commit d3771538 authored by Viral Solani's avatar Viral Solani

User Login Test With Helper function

parent 0f47fe87
...@@ -19,11 +19,12 @@ $factory->define(User::class, function (Generator $faker) { ...@@ -19,11 +19,12 @@ $factory->define(User::class, function (Generator $faker) {
static $password; static $password;
return [ return [
'name' => $faker->name, 'first_name' => $faker->name,
'last_name' => $faker->name,
'email' => $faker->safeEmail, 'email' => $faker->safeEmail,
'password' => $password ?: $password = bcrypt('secret'), 'password' => $password ?: $password = bcrypt('secret'),
'remember_token' => str_random(10),
'confirmation_code' => md5(uniqid(mt_rand(), true)), 'confirmation_code' => md5(uniqid(mt_rand(), true)),
'remember_token' => str_random(10)
]; ];
}); });
...@@ -51,6 +52,7 @@ $factory->state(User::class, 'unconfirmed', function () { ...@@ -51,6 +52,7 @@ $factory->state(User::class, 'unconfirmed', function () {
]; ];
}); });
/* /*
* Roles * Roles
*/ */
......
...@@ -26,8 +26,8 @@ class UserTableSeeder extends Seeder ...@@ -26,8 +26,8 @@ class UserTableSeeder extends Seeder
//Add the master administrator, user id of 1 //Add the master administrator, user id of 1
$users = [ $users = [
[ [
'first_name' => 'Admin Istrator', 'first_name' => 'Viral',
'last_name' => 'Admin Istrator', 'last_name' => 'Solani',
'email' => 'admin@admin.com', 'email' => 'admin@admin.com',
'password' => bcrypt('1234'), 'password' => bcrypt('1234'),
'confirmation_code' => md5(uniqid(mt_rand(), true)), 'confirmation_code' => md5(uniqid(mt_rand(), true)),
...@@ -39,8 +39,8 @@ class UserTableSeeder extends Seeder ...@@ -39,8 +39,8 @@ class UserTableSeeder extends Seeder
'deleted_at' => null, 'deleted_at' => null,
], ],
[ [
'first_name' => 'Backend User', 'first_name' => 'Vipul',
'last_name' => 'Admin Istrator', 'last_name' => 'Basapati',
'email' => 'executive@executive.com', 'email' => 'executive@executive.com',
'password' => bcrypt('1234'), 'password' => bcrypt('1234'),
'confirmation_code' => md5(uniqid(mt_rand(), true)), 'confirmation_code' => md5(uniqid(mt_rand(), true)),
...@@ -52,8 +52,8 @@ class UserTableSeeder extends Seeder ...@@ -52,8 +52,8 @@ class UserTableSeeder extends Seeder
'deleted_at' => null, 'deleted_at' => null,
], ],
[ [
'first_name' => 'Default User', 'first_name' => 'John',
'last_name' => 'Admin Istrator', 'last_name' => 'Doe',
'email' => 'user@user.com', 'email' => 'user@user.com',
'password' => bcrypt('1234'), 'password' => bcrypt('1234'),
'confirmation_code' => md5(uniqid(mt_rand(), true)), 'confirmation_code' => md5(uniqid(mt_rand(), true)),
......
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
namespace Tests; namespace Tests;
use App\Models\Access\Role\Role;
use App\Models\Access\User\User;
use Illuminate\Support\Facades\Artisan;
use Laravel\BrowserKitTesting\TestCase as BaseTestCase; use Laravel\BrowserKitTesting\TestCase as BaseTestCase;
abstract class BrowserKitTestCase extends BaseTestCase abstract class BrowserKitTestCase extends BaseTestCase
...@@ -9,4 +12,56 @@ abstract class BrowserKitTestCase extends BaseTestCase ...@@ -9,4 +12,56 @@ abstract class BrowserKitTestCase extends BaseTestCase
use CreatesApplication; use CreatesApplication;
public $baseUrl = 'http://localhost:8000'; public $baseUrl = 'http://localhost:8000';
/**
* @var
*/
protected $admin;
/**
* @var
*/
protected $executive;
/**
* @var
*/
protected $user;
/**
* @var
*/
protected $adminRole;
/**
* @var
*/
protected $executiveRole;
/**
* @var
*/
protected $userRole;
/**
* Set up tests.
*/
public function setUp()
{
parent::setUp();
// Set up the database
Artisan::call('migrate:refresh');
Artisan::call('db:seed');
/*
* Create class properties to be used in tests
*/
$this->admin = User::find(1);
$this->executive = User::find(2);
$this->user = User::find(3);
$this->adminRole = Role::find(1);
$this->executiveRole = Role::find(2);
$this->userRole = Role::find(3);
}
} }
...@@ -23,7 +23,6 @@ trait CreatesUsers ...@@ -23,7 +23,6 @@ trait CreatesUsers
'username' => 'johndoe', 'username' => 'johndoe',
'email' => 'john@example.com', 'email' => 'john@example.com',
'password' => bcrypt('password'), 'password' => bcrypt('password'),
'github_username' => 'johndoe',
], $attributes)); ], $attributes));
} }
} }
...@@ -2,7 +2,10 @@ ...@@ -2,7 +2,10 @@
namespace Tests\Feature; namespace Tests\Feature;
use Illuminate\Support\Facades\Auth;
use Tests\BrowserKitTestCase; use Tests\BrowserKitTestCase;
use Illuminate\Support\Facades\Event;
use App\Events\Frontend\Auth\UserLoggedIn;
class AuthTest extends BrowserKitTestCase class AuthTest extends BrowserKitTestCase
{ {
...@@ -40,11 +43,30 @@ class AuthTest extends BrowserKitTestCase ...@@ -40,11 +43,30 @@ class AuthTest extends BrowserKitTestCase
/** @test */ /** @test */
public function users_can_login() public function users_can_login()
{ {
//$this->createUser(); // Make sure our events are fired
$this->visit('/login') Event::fake();
->type('user@user.com', 'email')
->type('1234', 'password') Auth::logout();
//->press('Login')
->seePageIs('/login'); //User Test
$this->visit('/login')
->type($this->user->email, 'email')
->type('1234', 'password')
->press('Login')
->see($this->user->name)
->seePageIs('/dashboard');
Auth::logout();
//Admin Test
$this->visit('/login')
->type($this->admin->email, 'email')
->type('1234', 'password')
->press('Login')
->seePageIs('/admin/dashboard')
->see($this->admin->first_name)
->see('Access Management');
Event::assertDispatched(UserLoggedIn::class);
} }
} }
...@@ -2,9 +2,64 @@ ...@@ -2,9 +2,64 @@
namespace Tests; namespace Tests;
use App\Models\Access\Role\Role;
use App\Models\Access\User\User;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase; use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
abstract class TestCase extends BaseTestCase abstract class TestCase extends BaseTestCase
{ {
use CreatesApplication; use CreatesApplication;
/**
* @var
*/
protected $admin;
/**
* @var
*/
protected $executive;
/**
* @var
*/
protected $user;
/**
* @var
*/
protected $adminRole;
/**
* @var
*/
protected $executiveRole;
/**
* @var
*/
protected $userRole;
/**
* Set up tests.
*/
public function setUp()
{
parent::setUp();
// Set up the database
Artisan::call('migrate:refresh');
Artisan::call('db:seed');
/*
* Create class properties to be used in tests
*/
$this->admin = User::find(1);
$this->executive = User::find(2);
$this->user = User::find(3);
$this->adminRole = Role::find(1);
$this->executiveRole = Role::find(2);
$this->userRole = Role::find(3);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment