From 1c206323a22a00bc266b38091d047193273596bb Mon Sep 17 00:00:00 2001 From: k1nq Date: Sat, 29 Nov 2025 08:59:55 +0500 Subject: [PATCH] feat: add tests for deal stage rollback and forward transitions for owner and member roles --- tests/services/test_deal_service.py | 51 +++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/tests/services/test_deal_service.py b/tests/services/test_deal_service.py index 3a789c1..4c126ec 100644 --- a/tests/services/test_deal_service.py +++ b/tests/services/test_deal_service.py @@ -163,6 +163,57 @@ async def test_stage_rollback_allowed_for_admin(session: AsyncSession) -> None: assert updated.stage == DealStage.PROPOSAL +@pytest.mark.asyncio +async def test_stage_rollback_allowed_for_owner(session: AsyncSession) -> None: + context, contact, repo = await _persist_base(session, role=OrganizationRole.OWNER) + service = DealService(repository=repo) + + deal = await service.create_deal( + DealCreate( + organization_id=context.organization_id, + contact_id=contact.id, + owner_id=context.user_id, + title="Owner Rollback", + amount=Decimal("2500"), + ), + context=context, + ) + deal.stage = DealStage.CLOSED + + updated = await service.update_deal( + deal, + DealUpdateData(stage=DealStage.NEGOTIATION), + context=context, + ) + + assert updated.stage == DealStage.NEGOTIATION + + +@pytest.mark.asyncio +async def test_stage_forward_allowed_for_member(session: AsyncSession) -> None: + context, contact, repo = await _persist_base(session, role=OrganizationRole.MEMBER) + service = DealService(repository=repo) + + deal = await service.create_deal( + DealCreate( + organization_id=context.organization_id, + contact_id=contact.id, + owner_id=context.user_id, + title="Forward Move", + amount=Decimal("1000"), + ), + context=context, + ) + + updated = await service.update_deal( + deal, + DealUpdateData(stage=DealStage.PROPOSAL), + context=context, + ) + + assert updated.stage == DealStage.PROPOSAL + + @pytest.mark.asyncio async def test_status_won_requires_positive_amount(session: AsyncSession) -> None: context, contact, repo = await _persist_base(session)