2017-12-23 02:46:46 +08:00
|
|
|
<?php
|
|
|
|
|
2020-05-23 23:43:29 +08:00
|
|
|
namespace Tests;
|
|
|
|
|
2018-02-21 12:33:09 +08:00
|
|
|
use App\Models\Enums\UserState;
|
2021-06-04 22:51:59 +08:00
|
|
|
use App\Models\User;
|
2022-02-09 04:07:02 +08:00
|
|
|
use App\Notifications\Messages\AdminUserRegistered;
|
2022-02-05 04:03:05 +08:00
|
|
|
use App\Services\UserService;
|
2020-02-24 06:21:26 +08:00
|
|
|
use Illuminate\Support\Facades\Hash;
|
|
|
|
use Illuminate\Support\Facades\Notification;
|
2017-12-23 02:46:46 +08:00
|
|
|
|
|
|
|
class RegistrationTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* A basic test example.
|
|
|
|
*
|
2020-05-23 23:43:29 +08:00
|
|
|
* @throws \Exception
|
2018-08-27 02:51:47 +08:00
|
|
|
*
|
|
|
|
* @return void
|
2017-12-23 02:46:46 +08:00
|
|
|
*/
|
|
|
|
public function testRegistration()
|
|
|
|
{
|
2022-02-09 04:07:02 +08:00
|
|
|
$admin = $this->createAdminUser(['name' => 'testRegistration Admin']);
|
2017-12-23 02:46:46 +08:00
|
|
|
|
2022-02-05 04:03:05 +08:00
|
|
|
/** @var UserService $userSvc */
|
|
|
|
$userSvc = app(UserService::class);
|
2017-12-23 02:46:46 +08:00
|
|
|
|
2022-02-09 04:07:02 +08:00
|
|
|
$this->updateSetting('pilots.auto_accept', true);
|
2017-12-23 02:46:46 +08:00
|
|
|
|
2022-02-05 04:03:05 +08:00
|
|
|
$attrs = factory(User::class)->make()->makeVisible(['api_key', 'name', 'email'])->toArray();
|
2020-02-24 06:21:26 +08:00
|
|
|
$attrs['password'] = Hash::make('secret');
|
|
|
|
$user = $userSvc->createUser($attrs);
|
2017-12-23 02:46:46 +08:00
|
|
|
|
2017-12-31 10:40:32 +08:00
|
|
|
$this->assertEquals(UserState::ACTIVE, $user->state);
|
2017-12-23 02:46:46 +08:00
|
|
|
|
2022-02-09 04:07:02 +08:00
|
|
|
Notification::assertSentTo([$admin], AdminUserRegistered::class);
|
|
|
|
Notification::assertNotSentTo([$user], AdminUserRegistered::class);
|
2017-12-23 02:46:46 +08:00
|
|
|
}
|
|
|
|
}
|