f55b91cfa4
Закрывает архитектурное расхождение v1.28 — Tab сохранял prefs только локально без API. Backend events не совпадали с handoff'ом. Backend: - PATCH /api/auth/me/notification-preferences под auth:sanctum. - Replace-семантика: незадекларированные events/channels отбрасываются. - userResource расширен: notification_preferences + sound_enabled. - UserFactory с schema-default JSON (Eloquent не перечитывает после INSERT, DB-DEFAULT JSONB виден как null без явного override). - Pest +10: 401 / replace / неизвестные events/channels отбрасываются / 422 без prefs / sound_enabled опционален / bool-cast 1/'1' / replace- семантика (отсутствующие events исчезают). Frontend: - api/auth.ts: типы NotificationChannel/EventKey/Preferences + updateNotificationPreferences helper. AuthUser получил optional поля. - NotificationsTab.vue переписан под schema: 8 событий (new_lead/reminder/low_balance/zero_balance/topup_success/ invoice_paid/new_device_login/marketing) × 3 канала (inapp/push/email, НЕ sms). Sync-init prefs (без onMounted — иначе v-if блокирует рендер и тесты mount-then-find падают). dirty через computed-сравнение с originalPrefs snapshot. save async + success/error alerts. - SettingsView.spec.ts: legacy event-имена → schema-aligned. - Vitest +10: 8 schema events / 3 channels (НЕ sms) / legacy отсутствуют / читает prefs из user / save calls API + alerts / Отменить возвращает. cspell-words: +prefs. PHPStan baseline регенерирован. Pest 315/315 (+10) за 36.73 сек, 1130 assertions. Vitest 349/349 (+10) за 20.42 сек. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
65 lines
2.1 KiB
PHP
65 lines
2.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Models\Tenant;
|
|
use App\Models\User;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
use Illuminate\Support\Facades\Hash;
|
|
|
|
/**
|
|
* @extends Factory<User>
|
|
*/
|
|
class UserFactory extends Factory
|
|
{
|
|
protected static ?string $password = null;
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function definition(): array
|
|
{
|
|
return [
|
|
'tenant_id' => Tenant::factory(),
|
|
'email' => fake()->unique()->safeEmail(),
|
|
'password_hash' => static::$password ??= Hash::make('password'),
|
|
'first_name' => fake()->firstName(),
|
|
'last_name' => fake()->lastName(),
|
|
'timezone' => 'Europe/Moscow',
|
|
'is_active' => true,
|
|
'totp_enabled' => false,
|
|
'sound_enabled' => true,
|
|
'email_verified_at' => now(),
|
|
// Schema-default matrix (см. schema.sql:699). Eloquent не перечитывает
|
|
// строку после INSERT, поэтому колонки с DB-DEFAULT'ами видны как
|
|
// null на свежесозданной модели — нужно явно задать здесь.
|
|
'notification_preferences' => [
|
|
'new_lead' => ['inapp' => true, 'push' => true, 'email' => false],
|
|
'reminder' => ['inapp' => true, 'push' => true, 'email' => true],
|
|
'low_balance' => ['email' => true],
|
|
'zero_balance' => ['email' => true],
|
|
'topup_success' => ['email' => true],
|
|
'invoice_paid' => ['email' => true],
|
|
'new_device_login' => ['email' => true],
|
|
'marketing' => ['email' => false],
|
|
],
|
|
];
|
|
}
|
|
|
|
public function unverified(): static
|
|
{
|
|
return $this->state(fn (array $attributes) => [
|
|
'email_verified_at' => null,
|
|
]);
|
|
}
|
|
|
|
public function inactive(): static
|
|
{
|
|
return $this->state(fn (array $attributes) => [
|
|
'is_active' => false,
|
|
]);
|
|
}
|
|
}
|