feat: add tests for deal stage rollback and forward transitions for owner and member roles
Test / test (push) Successful in 14s Details

This commit is contained in:
k1nq 2025-11-29 08:59:55 +05:00
parent ce652a7e48
commit 1c206323a2
1 changed files with 51 additions and 0 deletions

View File

@ -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)