Respect home hubs setting for registration #580 (#581)

Respect home hubs setting for registration #580
This commit is contained in:
Nabeel S
2020-02-23 17:21:26 -05:00
committed by GitHub
parent b34dc4868e
commit a1d6fa17ad
11 changed files with 62 additions and 64 deletions

View File

@@ -1,7 +1,10 @@
<?php
use App\Events\UserRegistered;
use App\Models\Enums\UserState;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Notification;
class RegistrationTest extends TestCase
{
@@ -15,25 +18,26 @@ class RegistrationTest extends TestCase
public function testRegistration()
{
Event::fake();
Mail::fake();
Notification::fake();
$userSvc = app('App\Services\UserService');
setting('pilots.auto_accept', true);
$user = factory(App\Models\User::class)->create();
$user = $userSvc->createUser($user);
$attrs = factory(App\Models\User::class)->make()->toArray();
$attrs['password'] = Hash::make('secret');
$user = $userSvc->createUser($attrs);
$this->assertEquals(UserState::ACTIVE, $user->state);
Event::assertDispatched(\App\Events\UserRegistered::class, function ($e) use ($user) {
Event::assertDispatched(UserRegistered::class, function ($e) use ($user) {
return $e->user->id === $user->id
&& $e->user->state === $user->state;
});
/*Mail::assertSent(\App\Mail\UserRegistered::class, function ($mail) use ($user) {
return $mail->user->id === $user->id
&& $mail->user->state === $user->state;
});*/
/*Notification::assertSentTo(
[$user],
\App\Notifications\Messages\UserRegistered::class
);*/
}
}

View File

@@ -4,6 +4,7 @@ use App\Exceptions\UserPilotIdExists;
use App\Models\User;
use App\Repositories\SettingRepository;
use App\Services\UserService;
use Illuminate\Support\Facades\Hash;
class UserTest extends TestCase
{
@@ -208,12 +209,14 @@ class UserTest extends TestCase
*/
public function testUserPilotIdAdded()
{
$new_user = factory(App\Models\User::class)->create(['id' => 1]);
$new_user = factory(App\Models\User::class)->make()->toArray();
$new_user['password'] = Hash::make('secret');
$user = $this->userSvc->createUser($new_user);
$this->assertEquals($user->id, $user->pilot_id);
// Add a second user
$new_user = factory(App\Models\User::class)->create(['id' => 2]);
$new_user = factory(App\Models\User::class)->make()->toArray();
$new_user['password'] = Hash::make('secret');
$user2 = $this->userSvc->createUser($new_user);
$this->assertEquals($user2->id, $user2->pilot_id);
@@ -222,7 +225,7 @@ class UserTest extends TestCase
$this->assertEquals(3, $user->pilot_id);
// Create a new user and the pilot_id should be 4
$user3 = factory(App\Models\User::class)->create(['id' => 3]);
$user3 = factory(App\Models\User::class)->create();
$this->assertEquals(4, $user3->pilot_id);
}
}