admin()->create(); $manager = User::factory()->manager()->create(); $catalogItem = CommonCatalogItem::factory()->create(); $this->enableEvent($manager, ProductionOrderNotificationEvent::Created); $this->actingAs($admin) ->post(route('schedule.orders.store'), [ 'order_number' => 'УВ-001', 'order_year' => 2026, 'customer_name' => 'Заказчик', 'object_address' => 'ул. Тестовая, 1', 'invoice_number' => 'СЧ-1', 'payment_date' => '2026-09-01', 'supply_working_days' => 5, 'status' => ProductionOrderStatus::Placed->value, 'execution_type' => ProductionOrderExecutionType::Delivery->value, 'manager_id' => $manager->id, 'items' => [[ 'common_catalog_item_id' => $catalogItem->id, 'order_item_number' => 'МАФ-1', ]], ]) ->assertRedirect(); $this->assertDatabaseHas('user_notifications', [ 'user_id' => $manager->id, 'type' => UserNotification::TYPE_PRODUCTION_ORDER, 'event' => ProductionOrderNotificationEvent::Created->value, ]); Queue::assertPushed(SendUserNotificationChannelJob::class); } public function test_delivery_and_installation_notify_bound_driver_and_brigadier(): void { $admin = User::factory()->admin()->create(); $manager = User::factory()->manager()->create(); $driver = User::factory()->driver()->create(); $brigadier = User::factory()->brigadier()->create(); $order = ProductionOrder::factory()->create(['manager_id' => $manager->id]); $this->enableEvent($driver, ProductionOrderNotificationEvent::DeliveryAdded); $this->enableEvent($brigadier, ProductionOrderNotificationEvent::InstallationAdded); $this->actingAs($admin) ->post(route('schedule.orders.deliveries.store', $order), [ 'delivery_date' => '2026-09-10', 'driver_id' => $driver->id, 'has_passports_and_certificates' => true, ]) ->assertRedirect(); $this->actingAs($admin) ->post(route('schedule.orders.installations.store', $order), [ 'installation_date' => '2026-09-12', 'installation_days' => 2, 'brigadier_id' => $brigadier->id, ]) ->assertRedirect(); $this->assertDatabaseHas('user_notifications', [ 'user_id' => $driver->id, 'event' => ProductionOrderNotificationEvent::DeliveryAdded->value, ]); $this->assertDatabaseHas('user_notifications', [ 'user_id' => $brigadier->id, 'event' => ProductionOrderNotificationEvent::InstallationAdded->value, ]); $this->assertDatabaseMissing('user_notifications', [ 'user_id' => $manager->id, 'type' => UserNotification::TYPE_PRODUCTION_ORDER, ]); } public function test_admin_can_configure_production_order_events_for_user(): void { $admin = User::factory()->admin()->create(); $manager = User::factory()->manager()->create(); $this->actingAs($admin) ->get(route('user.show', $manager)) ->assertOk() ->assertSee('График заказов') ->assertSee('Добавлена доставка'); $this->actingAs($admin) ->post(route('user.store'), [ 'id' => $manager->id, 'name' => $manager->name, 'email' => $manager->email, 'role_id' => $manager->role_id, 'notification_settings' => [ 'production_orders' => [ ProductionOrderNotificationEvent::StatusChanged->value => ['browser' => '1'], ], ], ]) ->assertRedirect(route('user.index')); $settings = UserNotificationSetting::query()->where('user_id', $manager->id)->firstOrFail(); $this->assertTrue($settings->production_order_settings['status_changed']['browser']); $this->assertFalse($settings->production_order_settings['created']['browser']); } private function enableEvent(User $user, ProductionOrderNotificationEvent $event): void { UserNotificationSetting::query()->create([ 'user_id' => $user->id, 'production_order_settings' => [ $event->value => ['browser' => true, 'push' => false, 'email' => false], ], ]); } }