Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/inikoo/aiku into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Ganes556 committed Jan 7, 2025
2 parents edd3237 + 1c766bc commit 3882ff3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
9 changes: 6 additions & 3 deletions app/Actions/SysAdmin/Guest/UpdateGuest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ public function handle(Guest $guest, array $modelData): Guest
}
}
}

if ($user = $guest->getUser()) {
if (!empty($credentials) && $user = $guest->getUser()) {
UpdateUser::run($user, $credentials);
}

Expand Down Expand Up @@ -122,7 +121,11 @@ public function rules(): array


];
$rules['password'] = ['sometimes', 'required', app()->isLocal() || app()->environment('testing') ? null : Password::min(8)->uncompromised()];
$rules['password'] = [
'sometimes',
'required',
app()->isLocal() || app()->environment('testing') ? 'min:8' : Password::min(8)->uncompromised(),
];
}


Expand Down
29 changes: 28 additions & 1 deletion tests/Feature/AikuSections/SysAdminTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,33 @@
return $guest;
})->depends('create guest from command');

test('update guest credentials', function ($guest) {
app()->instance('group', $guest->group);
setPermissionsTeamId($guest->group->id);

$guest = UpdateGuest::make()->action($guest, ['username' => 'testuser']);
expect($guest->getUser()->username)->toBe('testuser')
->and(Hash::check('hello1234', $guest->getUser()->password))->toBeTrue();

$guest = UpdateGuest::make()->action($guest, ['password' => 'testoooo']);
expect($guest->getUser()->username)->toBe('testuser')
->and(Hash::check('testoooo', $guest->getUser()->password))->toBeTrue();

return $guest;
})->depends('update guest');

test('update guest status', function ($guest) {
app()->instance('group', $guest->group);
setPermissionsTeamId($guest->group->id);

$guest = UpdateGuest::make()->action($guest, ['status' => true]);
expect($guest->getUser()->username)->toBe('testuser')
->and(Hash::check('testoooo', $guest->getUser()->password))->toBeTrue()
->and($guest->status)->toBeTrue();

return $guest;
})->depends('update guest credentials');

test('fail to create guest with invalid usernames', function (Group $group) {
app()->instance('group', $group);
setPermissionsTeamId($group->id);
Expand Down Expand Up @@ -380,7 +407,7 @@
})->depends('update guest');

test('update user username', function (User $user) {
expect($user->username)->toBe('pika');
expect($user->username)->toBe('testuser');
$user = UpdateUser::make()->action($user, [
'username' => 'new-username'
]);
Expand Down

0 comments on commit 3882ff3

Please sign in to comment.