From dc552407c439707ce8f727057a987a3a60e57d20 Mon Sep 17 00:00:00 2001 From: Matt Young Date: Thu, 3 Jul 2025 00:27:39 -0500 Subject: [PATCH] Create tests for app/Listeners/LogLogin --- tests/Feature/app/Listeners/LogLoginTest.php | 38 ++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 tests/Feature/app/Listeners/LogLoginTest.php diff --git a/tests/Feature/app/Listeners/LogLoginTest.php b/tests/Feature/app/Listeners/LogLoginTest.php new file mode 100644 index 0000000..c4d9f37 --- /dev/null +++ b/tests/Feature/app/Listeners/LogLoginTest.php @@ -0,0 +1,38 @@ +user = $creator->create([ + 'registration_code' => 'secret', + 'first_name' => 'Percy', + 'last_name' => 'Grainger', + 'judging_preference' => 'Sarrousaphone', + 'cell_phone' => '0123456789', + 'email' => 'audition@admin.com', + 'password' => 'password', + 'password_confirmation' => 'password', + ]); + $this->user->email_verified_at = now(); + $this->user->save(); + $this->user->refresh(); +}); + +test('Logins are logged', function () { + $response = $this->post('/login', [ + 'email' => 'audition@admin.com', + 'password' => 'password', + ], [ + 'REMOTE_ADDR' => '123.123.123.123', + ]); + $lastLog = AuditLogEntry::orderBy('id', 'desc')->first(); + expect($lastLog->message)->toEqual('Logged In') + ->and($lastLog->user)->toEqual($this->user->email) + ->and($lastLog->ip_address)->toEqual('123.123.123.123') + ->and($lastLog->affected['users'])->toEqual([$this->user->id]); +});