Create tests for app/Listeners/LogLogin
This commit is contained in:
parent
fad7e1199e
commit
dc552407c4
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
use App\Actions\Fortify\CreateNewUser;
|
||||
use App\Models\AuditLogEntry;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
beforeEach(function () {
|
||||
$creator = app(CreateNewUser::class);
|
||||
$this->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]);
|
||||
});
|
||||
Loading…
Reference in New Issue