Create tests for app/actions/fortify/UpdateUserProfileInformation
This commit is contained in:
parent
618ae79cd0
commit
b04bdc960b
|
|
@ -44,17 +44,18 @@ class UpdateUserProfileInformation implements UpdatesUserProfileInformation
|
|||
'cell_phone' => $input['cell_phone'],
|
||||
'email' => $input['email'],
|
||||
])->save();
|
||||
$message = 'Updated user #'.$user->id.' - '.$user->email
|
||||
.'<br>Name: '.$user->full_name()
|
||||
.'<br>Judging Pref: '.$user->judging_preference
|
||||
.'<br>Cell Phone: '.$user->cell_phone;
|
||||
AuditLogEntry::create([
|
||||
'user' => auth()->user()->email,
|
||||
'ip_address' => request()->ip(),
|
||||
'message' => $message,
|
||||
'affected' => ['users' => [$user->id]],
|
||||
]);
|
||||
}
|
||||
$message = 'Updated user #'.$user->id.' - '.$user->email
|
||||
.'<br>Name: '.$user->full_name()
|
||||
.'<br>Judging Pref: '.$user->judging_preference
|
||||
.'<br>Cell Phone: '.$user->cell_phone;
|
||||
AuditLogEntry::create([
|
||||
'user' => auth()->user()->email,
|
||||
'ip_address' => request()->ip(),
|
||||
'message' => $message,
|
||||
'affected' => ['users' => [$user->id]],
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -0,0 +1,76 @@
|
|||
<?php
|
||||
|
||||
use App\Actions\Fortify\CreateNewUser;
|
||||
use App\Actions\Fortify\UpdateUserProfileInformation;
|
||||
use App\Models\AuditLogEntry;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
beforeEach(function () {
|
||||
$creator = app(CreateNewUser::class);
|
||||
$this->user = $creator->create([
|
||||
'registration_code' => auditionSetting('registrationCode'),
|
||||
'first_name' => 'Old',
|
||||
'last_name' => 'Name',
|
||||
'judging_preference' => 'oldPreference',
|
||||
'cell_phone' => '0123456789',
|
||||
'email' => 'old@email.com',
|
||||
'password' => 'password',
|
||||
'password_confirmation' => 'password',
|
||||
]);
|
||||
$this->changer = app(UpdateUserProfileInformation::class);
|
||||
$this->user->email_verified_at = Carbon::now();
|
||||
$this->user->save();
|
||||
$this->user->refresh();
|
||||
$this->actingAs($this->user);
|
||||
});
|
||||
|
||||
it('updates a user profile, maintains verification when retaining email', function () {
|
||||
$newdata = [
|
||||
'first_name' => 'New',
|
||||
'last_name' => 'Named',
|
||||
'judging_preference' => 'newPreference',
|
||||
'cell_phone' => '0987654321',
|
||||
'email' => 'old@email.com',
|
||||
];
|
||||
$this->changer->update($this->user, $newdata);
|
||||
expect($this->user->first_name)->toEqual('New')
|
||||
->and($this->user->last_name)->toEqual('Named')
|
||||
->and($this->user->judging_preference)->toEqual('newPreference')
|
||||
->and($this->user->cell_phone)->toEqual('0987654321')
|
||||
->and($this->user->email)->toEqual('old@email.com')
|
||||
->and($this->user->email_verified_at)->not()->toBeNull();
|
||||
});
|
||||
|
||||
it('updates a user profile, clears verification when changing email', function () {
|
||||
$newdata = [
|
||||
'first_name' => 'New',
|
||||
'last_name' => 'Named',
|
||||
'judging_preference' => 'newPreference',
|
||||
'cell_phone' => '0987654321',
|
||||
'email' => 'new@email.com',
|
||||
];
|
||||
$this->changer->update($this->user, $newdata);
|
||||
$this->user->refresh();
|
||||
expect($this->user->first_name)->toEqual('New')
|
||||
->and($this->user->last_name)->toEqual('Named')
|
||||
->and($this->user->judging_preference)->toEqual('newPreference')
|
||||
->and($this->user->cell_phone)->toEqual('0987654321')
|
||||
->and($this->user->email)->toEqual('new@email.com')
|
||||
->and($this->user->email_verified_at)->toBeNull();
|
||||
});
|
||||
|
||||
it('logs changes in use profile', function () {
|
||||
$newdata = [
|
||||
'first_name' => 'New',
|
||||
'last_name' => 'Named',
|
||||
'judging_preference' => 'newPreference',
|
||||
'cell_phone' => '0987654321',
|
||||
'email' => 'new@email.com',
|
||||
];
|
||||
$this->changer->update($this->user, $newdata);
|
||||
$this->user->refresh();
|
||||
expect(AuditLogEntry::where('message', 'like', 'Updated user %')->count())->toEqual(1);
|
||||
});
|
||||
Loading…
Reference in New Issue