diff --git a/tests/Feature/AdminLoginTest.php b/tests/Feature/AdminLoginTest.php new file mode 100644 index 0000000..ebe4d51 --- /dev/null +++ b/tests/Feature/AdminLoginTest.php @@ -0,0 +1,48 @@ + 'admin', 'display_name' => 'Admin', 'description' => 'Admin']); + $user = User::factory()->create([ + 'name' => 'testuser', + 'password' => bcrypt('password'), + ]); + $user->addRole($adminRole); + + Livewire::test(Login::class) + ->fillForm([ + 'name' => 'testuser', + 'password' => 'password', + ]) + ->call('authenticate') + ->assertHasNoFormErrors() + ->assertRedirect('/admin'); + + $this->assertAuthenticatedAs($user); +}); + +it('cannot login with email anymore', function () { + $user = User::factory()->create([ + 'name' => 'testuser', + 'email' => 'test@example.com', + 'password' => bcrypt('password'), + ]); + + Livewire::test(Login::class) + ->fillForm([ + 'email' => 'test@example.com', + 'password' => 'password', + ]) + ->call('authenticate') + ->assertHasFormErrors(['name']); + + $this->assertGuest(); +});