async def test_create_and_run_sync_flow(
        self,
        mock_db,
        mock_user,
        complete_uow,
        mock_sync_dag,
        mock_collection,
        mock_source_connection
    ):
        """Test the full flow of creating and running a sync."""
        # Arrange
        sync_id = uuid.uuid4()

        # Mock the crud and DAG operations
        with (
            patch("airweave.crud.sync.create") as mock_create_sync,
            patch("airweave.core.dag_service.dag_service.create_initial_dag") as mock_create_dag,
            patch("airweave.core.sync_service.get_db_context") as mock_get_db_context,
            patch("airweave.platform.sync.factory.SyncFactory.create_orchestrator", new_callable=AsyncMock) as mock_create_orchestrator,
        ):
            # Setup mocks for create
            mock_sync = MagicMock(spec=schemas.Sync)
            mock_sync.id = sync_id
            mock_sync.name = "Test Integration Sync"
            mock_create_sync.return_value = mock_sync
            mock_create_dag.return_value = mock_sync_dag

            # Setup mocks for run
            mock_db_context = AsyncMock()
            mock_db_context.__aenter__.return_value = mock_db
            mock_get_db_context.return_value = mock_db_context

            mock_orchestrator = AsyncMock(spec=SyncOrchestrator)
            mock_orchestrator.run.return_value = mock_sync
            mock_create_orchestrator.return_value = mock_orchestrator

            # Create sync request
            sync_create = schemas.SyncCreate(
                name="Test Integration Sync",
                description="Integration test description",
                source_connection_id=uuid.uuid4(),
                destination_connection_ids=[uuid.uuid4()],
            )

            # Create sync job
            sync_job = schemas.SyncJob(
                id=uuid.uuid4(),
                sync_id=sync_id,
                status=SyncJobStatus.PENDING,
                progress=0,
                error=None,
                started_at=None,
                completed_at=None,
                created_at="2023-01-01T00:00:00",
                updated_at="2023-01-01T00:00:00",
                organization_id=uuid.uuid4(),
                created_by_email="test@example.com",
                modified_by_email="test@example.com",
                modified_at="2023-01-01T00:00:00",
                entities_detected=0,
                entities_inserted=0,
                entities_deleted=0,
                entities_skipped=0,
            )

            # Act - first create the sync
            service = SyncService()
            created_sync = await service.create(
                db=mock_db,
                sync=sync_create,
                current_user=mock_user,
                uow=complete_uow,
            )

            # Act - then run the sync
            run_result = await service.run(
                sync=created_sync,
                sync_job=sync_job,
                dag=mock_sync_dag,
                collection=mock_collection,
                source_connection=mock_source_connection,
                current_user=mock_user,
            )

            # Assert - Verify the flow
            # Creation assertions
            mock_create_sync.assert_called_once()
            complete_uow.session.flush.assert_called_once()
            mock_create_dag.assert_called_once_with(
                db=mock_db, sync_id=sync_id, current_user=mock_user, uow=complete_uow
            )

            # Run assertions
            mock_get_db_context.assert_called_once()
            mock_create_orchestrator.assert_called_once_with(
                db=mock_db,
                sync=created_sync,
                sync_job=sync_job,
                dag=mock_sync_dag,
                collection=mock_collection,
                source_connection=mock_source_connection,
                current_user=mock_user,
                access_token=None
            )
            mock_orchestrator.run.assert_called_once()

            # Final result assertions
            assert created_sync.id == sync_id
            assert run_result == mock_sync
Test the full flow of creating and running a sync.
backend/tests/unit/platform/sync/test_service_integration.py