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) {
static $password;
return [
'name' => $faker->name,
'first_name' => $faker->name,
'last_name' => $faker->name,
'email' => $faker->safeEmail,
'password' => $password ?: $password = bcrypt('secret'),
'remember_token' => str_random(10),
'confirmation_code' => md5(uniqid(mt_rand(), true)),
'remember_token' => str_random(10)
];
});
......@@ -51,6 +52,7 @@ $factory->state(User::class, 'unconfirmed', function () {
];
});
/*
* Roles
*/
......
......@@ -26,8 +26,8 @@ class UserTableSeeder extends Seeder
//Add the master administrator, user id of 1
$users = [
[
'first_name' => 'Admin Istrator',
'last_name' => 'Admin Istrator',
'first_name' => 'Viral',
'last_name' => 'Solani',
'email' => 'admin@admin.com',
'password' => bcrypt('1234'),
'confirmation_code' => md5(uniqid(mt_rand(), true)),
......@@ -39,8 +39,8 @@ class UserTableSeeder extends Seeder
'deleted_at' => null,
],
[
'first_name' => 'Backend User',
'last_name' => 'Admin Istrator',
'first_name' => 'Vipul',
'last_name' => 'Basapati',
'email' => 'executive@executive.com',
'password' => bcrypt('1234'),
'confirmation_code' => md5(uniqid(mt_rand(), true)),
......@@ -52,8 +52,8 @@ class UserTableSeeder extends Seeder
'deleted_at' => null,
],
[
'first_name' => 'Default User',
'last_name' => 'Admin Istrator',
'first_name' => 'John',
'last_name' => 'Doe',
'email' => 'user@user.com',
'password' => bcrypt('1234'),
'confirmation_code' => md5(uniqid(mt_rand(), true)),
......
......@@ -2,6 +2,9 @@
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;
abstract class BrowserKitTestCase extends BaseTestCase
......@@ -9,4 +12,56 @@ abstract class BrowserKitTestCase extends BaseTestCase
use CreatesApplication;
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
'username' => 'johndoe',
'email' => 'john@example.com',
'password' => bcrypt('password'),
'github_username' => 'johndoe',
], $attributes));
}
}
......@@ -2,7 +2,10 @@
namespace Tests\Feature;
use Illuminate\Support\Facades\Auth;
use Tests\BrowserKitTestCase;
use Illuminate\Support\Facades\Event;
use App\Events\Frontend\Auth\UserLoggedIn;
class AuthTest extends BrowserKitTestCase
{
......@@ -40,11 +43,30 @@ class AuthTest extends BrowserKitTestCase
/** @test */
public function users_can_login()
{
//$this->createUser();
$this->visit('/login')
->type('user@user.com', 'email')
->type('1234', 'password')
//->press('Login')
->seePageIs('/login');
// Make sure our events are fired
Event::fake();
Auth::logout();
//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 @@
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;
abstract class TestCase extends BaseTestCase
{
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