Fix first user not being set as admin

This commit is contained in:
Bubka 2023-03-24 17:18:28 +01:00
parent b8f290dc97
commit 16bf0e4e6d

View File

@ -2,6 +2,7 @@
namespace Tests\Feature\Http\Auth;
use App\Models\User;
use Illuminate\Support\Facades\DB;
use Tests\FeatureTestCase;
@ -94,4 +95,35 @@ public function test_register_with_invalid_data_returns_validation_error()
])
->assertStatus(422);
}
/**
* @test
*/
public function test_register_first_user_only_as_admin()
{
$this->assertDatabaseCount('users', 0);
$response = $this->json('POST', '/user', [
'name' => self::USERNAME,
'email' => self::EMAIL,
'password' => self::PASSWORD,
'password_confirmation' => self::PASSWORD,
]);
$this->assertDatabaseCount('users', 1);
$this->assertDatabaseHas('users', [
'name' => self::USERNAME,
'email' => self::EMAIL,
'is_admin' => true,
]);
$response = $this->json('POST', '/user', [
'name' => 'jane',
'email' => 'jane@example.org',
'password' => self::PASSWORD,
'password_confirmation' => self::PASSWORD,
]);
$this->assertEquals(1, User::admins()->count());
}
}