diff --git a/app/Http/Controllers/Auth/RegisteredUserController.php b/app/Http/Controllers/Auth/RegisteredUserController.php index 88dbc08..c0c9454 100644 --- a/app/Http/Controllers/Auth/RegisteredUserController.php +++ b/app/Http/Controllers/Auth/RegisteredUserController.php @@ -38,6 +38,7 @@ class RegisteredUserController extends Controller $user = User::create([ 'name' => $request->name, 'email' => $request->email, + 'department_id' => null, 'password' => Hash::make($request->password), ]); diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index 15860f5..99d1d1f 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -16,7 +16,7 @@ class UserFactory extends Factory 'name' => fake()->name(), 'email' => fake()->unique()->safeEmail(), 'email_verified_at' => now(), - 'department_id' => 1, + 'department_id' => null, 'password' => static::$password ??= Hash::make('password'), 'remember_token' => Str::random(10), ]; diff --git a/database/migrations/0001_01_01_000000_create_users_table.php b/database/migrations/0001_01_01_000000_create_users_table.php index 7931a6d..6b85972 100644 --- a/database/migrations/0001_01_01_000000_create_users_table.php +++ b/database/migrations/0001_01_01_000000_create_users_table.php @@ -12,7 +12,7 @@ return new class extends Migration $table->id(); $table->string('name'); $table->string('email')->unique(); - $table->foreignId('department_id')->constrained('departments'); + $table->foreignId('department_id')->nullable()->constrained('departments'); $table->timestamp('email_verified_at')->nullable(); $table->string('password'); $table->rememberToken(); diff --git a/tests/Feature/Auth/AuthenticationTest.php b/tests/Feature/Auth/AuthenticationTest.php index 253f02f..80b6de0 100644 --- a/tests/Feature/Auth/AuthenticationTest.php +++ b/tests/Feature/Auth/AuthenticationTest.php @@ -2,6 +2,7 @@ namespace Tests\Feature\Auth; +use App\Models\Department; use App\Models\User; use Illuminate\Foundation\Testing\RefreshDatabase; use Tests\TestCase; @@ -10,6 +11,11 @@ class AuthenticationTest extends TestCase { use RefreshDatabase; + public function setUp(): void + { + parent::setUp(); + Department::factory()->create(); + } public function testLoginScreenCanBeRendered(): void { $response = $this->get('/login'); diff --git a/tests/Feature/Auth/EmailVerificationTest.php b/tests/Feature/Auth/EmailVerificationTest.php index f8ae874..0e2d6e7 100644 --- a/tests/Feature/Auth/EmailVerificationTest.php +++ b/tests/Feature/Auth/EmailVerificationTest.php @@ -2,6 +2,7 @@ namespace Tests\Feature\Auth; +use App\Models\Department; use App\Models\User; use Illuminate\Auth\Events\Verified; use Illuminate\Foundation\Testing\RefreshDatabase; @@ -13,6 +14,12 @@ class EmailVerificationTest extends TestCase { use RefreshDatabase; + public function setUp(): void + { + parent::setUp(); + Department::factory()->create(); + } + public function testEmailVerificationScreenCanBeRendered(): void { $user = User::factory()->unverified()->create(); diff --git a/tests/Feature/Auth/PasswordConfirmationTest.php b/tests/Feature/Auth/PasswordConfirmationTest.php index 322c2cc..7348201 100644 --- a/tests/Feature/Auth/PasswordConfirmationTest.php +++ b/tests/Feature/Auth/PasswordConfirmationTest.php @@ -2,6 +2,7 @@ namespace Tests\Feature\Auth; +use App\Models\Department; use App\Models\User; use Illuminate\Foundation\Testing\RefreshDatabase; use Tests\TestCase; @@ -10,6 +11,11 @@ class PasswordConfirmationTest extends TestCase { use RefreshDatabase; + public function setUp(): void + { + parent::setUp(); + Department::factory()->create(); + } public function testConfirmPasswordScreenCanBeRendered(): void { $user = User::factory()->create(); diff --git a/tests/Feature/Auth/PasswordResetTest.php b/tests/Feature/Auth/PasswordResetTest.php index 5c3f0f1..2c6330b 100644 --- a/tests/Feature/Auth/PasswordResetTest.php +++ b/tests/Feature/Auth/PasswordResetTest.php @@ -2,6 +2,7 @@ namespace Tests\Feature\Auth; +use App\Models\Department; use App\Models\User; use Illuminate\Auth\Notifications\ResetPassword; use Illuminate\Foundation\Testing\RefreshDatabase; @@ -12,6 +13,12 @@ class PasswordResetTest extends TestCase { use RefreshDatabase; + public function setUp(): void + { + parent::setUp(); + Department::factory()->create(); + } + public function testResetPasswordLinkScreenCanBeRendered(): void { $response = $this->get('/forgot-password'); diff --git a/tests/Feature/Auth/PasswordUpdateTest.php b/tests/Feature/Auth/PasswordUpdateTest.php index b22369c..895ec66 100644 --- a/tests/Feature/Auth/PasswordUpdateTest.php +++ b/tests/Feature/Auth/PasswordUpdateTest.php @@ -2,6 +2,7 @@ namespace Tests\Feature\Auth; +use App\Models\Department; use App\Models\User; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Support\Facades\Hash; @@ -11,6 +12,12 @@ class PasswordUpdateTest extends TestCase { use RefreshDatabase; + public function setUp(): void + { + parent::setUp(); + Department::factory()->create(); + } + public function testPasswordCanBeUpdated(): void { $user = User::factory()->create(); diff --git a/tests/Feature/Auth/RegistrationTest.php b/tests/Feature/Auth/RegistrationTest.php index 5d86533..3a12ac3 100644 --- a/tests/Feature/Auth/RegistrationTest.php +++ b/tests/Feature/Auth/RegistrationTest.php @@ -2,6 +2,7 @@ namespace Tests\Feature\Auth; +use App\Models\Department; use Illuminate\Foundation\Testing\RefreshDatabase; use Tests\TestCase;