user factory

This commit is contained in:
denisdulici 2019-12-22 19:27:10 +03:00
parent abc39c4f63
commit d4efb90251
2 changed files with 10 additions and 26 deletions

View File

@ -40,9 +40,9 @@ class TestCompany extends Seeder
'locale' => 'en-GB',
'enabled' => '1',
'settings' => [
'wizard.completed' => '1',
'schedule.send_invoice_reminder' => '1',
'schedule.send_bill_reminder' => '1',
'wizard.completed' => '1',
],
]));

View File

@ -3,7 +3,7 @@
namespace Tests\Feature\Auth;
use App\Jobs\Auth\CreateUser;
use App\Models\Auth\Role;
use App\Models\Auth\User;
use Tests\Feature\FeatureTestCase;
class UsersTest extends FeatureTestCase
@ -27,7 +27,7 @@ class UsersTest extends FeatureTestCase
public function testItShouldCreateUser()
{
$this->loginAs()
->post(route('users.store'), $this->getUserRequest())
->post(route('users.store'), factory(User::class)->raw())
->assertStatus(200);
$this->assertFlashLevel('success');
@ -35,7 +35,7 @@ class UsersTest extends FeatureTestCase
public function testItShouldSeeUserUpdatePage()
{
$user = $this->dispatch(new CreateUser($this->getUserRequest()));
$user = $this->dispatch(new CreateUser(factory(User::class)->raw()));
$this->loginAs()
->get(route('users.edit', ['user' => $user->id]))
@ -45,7 +45,7 @@ class UsersTest extends FeatureTestCase
public function testItShouldUpdateUser()
{
$request = $this->getUserRequest();
$request = factory(User::class)->raw();
$user = $this->dispatch(new CreateUser($request));
@ -60,7 +60,7 @@ class UsersTest extends FeatureTestCase
public function testItShouldDeleteUser()
{
$user = $this->dispatch(new CreateUser($this->getUserRequest()));
$user = $this->dispatch(new CreateUser(factory(User::class)->raw()));
$this->loginAs()
->delete(route('users.destroy', $user->id))
@ -78,7 +78,7 @@ class UsersTest extends FeatureTestCase
public function testItShouldLoginUser()
{
$user = $this->dispatch(new CreateUser($this->getUserRequest()));
$user = $this->dispatch(new CreateUser(factory(User::class)->raw()));
$this->post(route('login'), ['email' => $user->email, 'password' => $user->password])
->assertStatus(200);
@ -88,7 +88,7 @@ class UsersTest extends FeatureTestCase
public function testItShouldNotLoginUser()
{
$user = $this->dispatch(new CreateUser($this->getUserRequest()));
$user = $this->dispatch(new CreateUser(factory(User::class)->raw()));
$this->post(route('login'), ['email' => $user->email, 'password' => $this->faker->password()])
->assertStatus(200);
@ -98,7 +98,7 @@ class UsersTest extends FeatureTestCase
public function testItShouldLogoutUser()
{
$user = $this->dispatch(new CreateUser($this->getUserRequest()));
$user = $this->dispatch(new CreateUser(factory(User::class)->raw()));
$this->loginAs()
->get(route('logout', $user->id))
@ -107,20 +107,4 @@ class UsersTest extends FeatureTestCase
$this->assertGuest();
}
private function getUserRequest()
{
$password = $this->faker->password();
return [
'name' => $this->faker->name,
'email' => $this->faker->email,
'password' => $password,
'password_confirmation' => $password,
'locale' => 'en-GB',
'companies' => [$this->company->id],
'roles' => ['1'],
'enabled' => 1,
];
}
}
}