Commit ea9e06ea authored by Viral Solani's avatar Viral Solani

- Test case for create user

- Make created_by null on role and permission table
- create factory for permission table
parent 09f96a1a
<?php
use Faker\Generator;
use App\Models\Access\Role\Role;
use App\Models\Access\User\User;
use Faker\Generator;
use App\Models\Access\Permission\Permission;
/*
|--------------------------------------------------------------------------
......@@ -68,3 +69,16 @@ $factory->state(Role::class, 'admin', function () {
'all' => 1,
];
});
/*
* Permissions
*/
$factory->define(Permission::class, function (Generator $faker) {
$name = $faker->word;
return [
'name' => $name,
'display_name' => $name,
'sort' => $faker->numberBetween(1, 100),
];
});
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddNullConstraintOnCreatedByOnRoleTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('roles', function (Blueprint $table) {
$table->integer('created_by')->nullable()->change();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddNullConstraintOnCreatedByOnPermissionTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('permissions', function (Blueprint $table) {
$table->integer('created_by')->nullable()->change();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}
{
"/js/frontend.js": "/js/frontend.70ee44a92d84e7318a9d.js",
"/js/backend.js": "/js/backend.9cdae6ab449e701ce881.js",
"/js/frontend.js": "/js/frontend.945469bbbc12df3ad9e1.js",
"/js/backend.js": "/js/backend.79d9e4698dadbc0d93c7.js",
"/mix.js": "/mix.247ab120fe7680658924.js",
"/css/frontend.css": "/css/frontend.3af0a6cbd7d1d8d042f2a37e97008b7c.css",
"/css/backend.css": "/css/backend.f8550f50504e5b8ef6055285205f223a.css",
"/css/backend-custom.css": "/css/backend-custom.18e74fbe4c755b817a022d6d3d4e76b1.css",
"/js/backend-custom.js": "/js/backend-custom.694670b0d97bf54111bac3bd91ba3fcf.js",
"/js/backend-custom.js": "/js/backend-custom.e6ea05e1824d0dd8e7c62027c135b7f2.js",
"/js/dataTable.js": "/js/dataTable.f968d300a6a0b871f138f114361259c8.js"
}
\ No newline at end of file
......@@ -2,8 +2,10 @@
namespace Tests\Feature\Backend;
use App\Models\Access\User\User;
use Tests\TestCase;
use App\Models\Access\Role\Role;
use App\Models\Access\User\User;
use App\Models\Access\Permission\Permission;
class ManageUsersTest extends TestCase
{
......@@ -56,4 +58,25 @@ class ManageUsersTest extends TestCase
->assertSee($this->admin->last_name)
->assertSee($this->admin->email);
}
/** @test */
public function a_user_can_create_new_user()
{
$user = factory(User::class)->states('active','confirmed')->make()->toArray();
$role = create(Role::class);
$permission = create(Permission::class);
$user['password'] = 'Viral@1234';
$user['password_confirmation'] = 'Viral@1234';
$user['assignees_roles'] = [$role->id];
$user['permissions'] = [$permission->id];
$this->actingAs($this->admin)
->post(route('admin.access.user.store'), $user)
->assertRedirect(route('admin.access.user.index'));
$this->assertDatabaseHas('users', ['first_name' => $user['first_name'], 'last_name' => $user['last_name']]);
$this->assertDatabaseHas('roles', ['name' => $role->name]);
$this->assertDatabaseHas('permissions', ['name' => $permission->name]);
}
}
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