auditionadmin/tests/Feature/app/Actions/Fortify/UpdateUserProfileInformatio...

63 lines
2.3 KiB
PHP

<?php
use App\Actions\Fortify\CreateNewUser;
use App\Actions\Fortify\UpdateUserProfileInformation;
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();
});