@@ -230,3 +230,41 @@ async def test_remove_project_documents_as_admin_with_known_opened_projects(
230230 )
231231 == 0
232232 ), "Project 2 should be removed because it's not in known opened projects and has no socket connections"
233+
234+
235+ @pytest .mark .parametrize (
236+ "user_role" ,
237+ [
238+ UserRole .USER ,
239+ ],
240+ )
241+ async def test_remove_project_documents_as_admin_mixed_state (
242+ client : TestClient ,
243+ logged_user : UserInfoDict ,
244+ redis_document_client : Any ,
245+ sample_project_uuids : list [ProjectID ],
246+ create_project_socketio_connections ,
247+ ):
248+ """Test mixed state: some projects have documents, some have connections without documents."""
249+ # Setup: Create document only for first project
250+ test_key = f"projects:{ sample_project_uuids [0 ]} :version"
251+ await increment_and_return_project_document_version (
252+ redis_client = redis_document_client , project_uuid = sample_project_uuids [0 ]
253+ )
254+
255+ # Create SocketIO connection for second project (no document)
256+ await create_project_socketio_connections (
257+ project_uuids = sample_project_uuids [1 :2 ], # Only second project
258+ connected_project_indices = [0 ], # Connect it to room
259+ )
260+
261+ # Execute the function
262+ await _project_document_service .remove_project_documents_as_admin (client .app )
263+
264+ # Verify: First project document should be removed (no connections)
265+ assert (
266+ await redis_document_client .redis .exists (test_key ) == 0
267+ ), "Project 0 document should be removed (no active connections)"
268+
269+ # Cleanup
270+ await redis_document_client .redis .delete (test_key )
0 commit comments