"""Tests for the Workspace service. Covers workspace creation/update, with a focus on the `planning_mode` field (explicit solo/couple planning intent — not inferred from member count). """ from uuid import uuid4 import pytest from app.services.workspace_service import WorkspaceService from app.utils.errors import NotFoundError, ValidationError class TestWorkspacePlanningMode: """Test planning_mode defaults and validation.""" async def test_create_workspace_defaults_to_solo( self, workspace_service: WorkspaceService, ) -> None: """A newly created workspace defaults to solo planning mode.""" ws = await workspace_service.create_workspace("Test WS") assert ws.planning_mode == "solo" async def test_update_planning_mode_to_couple( self, workspace_service: WorkspaceService, ) -> None: """Updating planning_mode to a valid value ('couple') succeeds.""" ws = await workspace_service.create_workspace("Test WS") updated = await workspace_service.update_workspace(ws.id, planning_mode="couple") assert updated.planning_mode == "couple" async def test_update_planning_mode_back_to_solo( self, workspace_service: WorkspaceService, ) -> None: """Updating planning_mode back to 'solo' succeeds.""" ws = await workspace_service.create_workspace("Test WS") await workspace_service.update_workspace(ws.id, planning_mode="couple") updated = await workspace_service.update_workspace(ws.id, planning_mode="solo") assert updated.planning_mode == "solo" async def test_update_planning_mode_invalid_raises( self, workspace_service: WorkspaceService, ) -> None: """An invalid planning_mode value raises ValidationError.""" ws = await workspace_service.create_workspace("Test WS") with pytest.raises(ValidationError, match="planning_mode must be one of"): await workspace_service.update_workspace(ws.id, planning_mode="throuple") async def test_update_planning_mode_missing_workspace_raises( self, workspace_service: WorkspaceService, ) -> None: """Updating planning_mode on a missing workspace raises NotFoundError.""" with pytest.raises(NotFoundError): await workspace_service.update_workspace(uuid4(), planning_mode="couple") async def test_update_name_and_planning_mode_together( self, workspace_service: WorkspaceService, ) -> None: """Multiple fields can be updated in the same call.""" ws = await workspace_service.create_workspace("Old Name") updated = await workspace_service.update_workspace( ws.id, name="New Name", planning_mode="couple" ) assert updated.name == "New Name" assert updated.planning_mode == "couple"