add tests batch 20

This commit is contained in:
root
2026-06-09 01:03:53 -04:00
parent 95efb9652e
commit 6be4875c5e
1502 changed files with 13797 additions and 11313 deletions
@@ -7,7 +7,9 @@ use Illuminate\Support\Facades\DB;
class PreferencesCommandService
{
public function __construct(private PreferencesOptionsService $options) {}
public function __construct(private PreferencesOptionsService $options)
{
}
public function upsert(int $userId, array $payload): Preferences
{
@@ -20,7 +22,6 @@ class PreferencesCommandService
if ($existing) {
$existing->fill($data);
$existing->save();
return $existing->refresh();
}
@@ -28,23 +28,21 @@ class PreferencesOptionsService
public function normalizeStyle(?string $style): ?string
{
if (! $style) {
if (!$style) {
return null;
}
$style = trim($style);
return in_array($style, $this->styleOptions(), true) ? $style : null;
}
public function normalizeMenu(?string $menu): ?string
{
if (! $menu) {
if (!$menu) {
return null;
}
$menu = trim($menu);
return in_array($menu, $this->menuOptions(), true) ? $menu : null;
}
}
@@ -7,14 +7,16 @@ use Illuminate\Contracts\Pagination\LengthAwarePaginator;
class PreferencesQueryService
{
public function __construct(private PreferencesOptionsService $options) {}
public function __construct(private PreferencesOptionsService $options)
{
}
public function getForUser(int $userId): array
{
$row = Preferences::query()->where('user_id', $userId)->first();
$base = $this->options->defaultPreferences();
if (! $row) {
if (!$row) {
return [
'preferences' => $base,
'options' => $this->optionsPayload(),
@@ -33,12 +35,12 @@ class PreferencesQueryService
->leftJoin('users', 'users.id', '=', 'user_preferences.user_id')
->select('user_preferences.*', 'users.firstname', 'users.lastname', 'users.email');
if (! empty($filters['user_id'])) {
if (!empty($filters['user_id'])) {
$query->where('user_preferences.user_id', (int) $filters['user_id']);
}
if (! empty($filters['q'])) {
$term = '%'.strtolower(trim((string) $filters['q'])).'%';
if (!empty($filters['q'])) {
$term = '%' . strtolower(trim((string) $filters['q'])) . '%';
$query->where(function ($q) use ($term) {
$q->whereRaw('LOWER(users.firstname) LIKE ?', [$term])
->orWhereRaw('LOWER(users.lastname) LIKE ?', [$term])
@@ -51,7 +53,7 @@ class PreferencesQueryService
$allowedSorts = ['updated_at', 'created_at', 'user_id'];
if (in_array($sortBy, $allowedSorts, true)) {
$query->orderBy('user_preferences.'.$sortBy, $sortDir);
$query->orderBy('user_preferences.' . $sortBy, $sortDir);
} else {
$query->orderBy('user_preferences.updated_at', 'desc');
}