From 96d5e072fe7f4469cb3053f7ff500ed4243ed698 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 17 Apr 2025 22:39:04 +0100 Subject: [PATCH] Fixed flaky tests on user creation Signed-off-by: snipe --- tests/Feature/Users/Ui/CreateUserTest.php | 34 +++++++++++++++++++---- tests/Feature/Users/Ui/IndexUsersTest.php | 2 +- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/tests/Feature/Users/Ui/CreateUserTest.php b/tests/Feature/Users/Ui/CreateUserTest.php index 456190ee3..d63dc40f9 100644 --- a/tests/Feature/Users/Ui/CreateUserTest.php +++ b/tests/Feature/Users/Ui/CreateUserTest.php @@ -7,14 +7,38 @@ use Tests\TestCase; class CreateUserTest extends TestCase { + + public function testPermissionRequiredToCreateUser() + { + $this->actingAs(User::factory()->create()) + ->get(route('users.create')) + ->assertForbidden(); + } + public function testPageRenders() { - $admin = User::factory()->createUsers()->create(); - $response = $this->actingAs(User::factory()->superuser()->create()) + $this->actingAs(User::factory()->createUsers()->create()) ->get(route('users.create')) ->assertOk(); - $response->assertDontSee($admin->first_name); - $response->assertDontSee($admin->last_name); - $response->assertDontSee($admin->email); + + } + + public function testCanCreateUser() + { + + $response = $this->actingAs(User::factory()->createUsers()->viewUsers()->create()) + ->from(route('users.index')) + ->post(route('users.store'), [ + 'first_name' => 'Test First Name', + 'last_name' => 'Test Last Name', + 'username' => 'testuser', + 'password' => 'testpassword1235!!', + //'notes' => 'Test Note', + ]) + ->assertStatus(302) + ->assertRedirect(route('users.index')); + + $this->followRedirects($response)->assertSee('Success'); + } } diff --git a/tests/Feature/Users/Ui/IndexUsersTest.php b/tests/Feature/Users/Ui/IndexUsersTest.php index 6730a3c95..020abdbcd 100644 --- a/tests/Feature/Users/Ui/IndexUsersTest.php +++ b/tests/Feature/Users/Ui/IndexUsersTest.php @@ -9,7 +9,7 @@ class IndexUsersTest extends TestCase { public function testPageRenders() { - $this->actingAs(User::factory()->superuser()->create()) + $this->actingAs(User::factory()->viewUsers()->create()) ->get(route('users.index')) ->assertOk(); }