bmc_hub/tests/test_workflow_timer_registration.py
Christian 85e019783b Add comprehensive test coverage for case creation, assignment, and remote recovery
- Introduced tests for case creation commands, ensuring proper handling of UUIDs and payloads.
- Added tests for v5 assignment functionality, validating employee identification and group assignment.
- Implemented tests for remote recovery scenarios, including handling network failures and response validation.
- Created tests for hardware label generation and validation, ensuring proper URL formatting and QR code generation.
- Developed extensive tests for remote control functionality, covering connection isolation, command execution, and user permissions.
- Added tests for workflow timer registration, ensuring correct handling of timer states and ownership validation.
2026-10-15 12:17:09 +02:00

42 lines
2.0 KiB
Python

import asyncio
from datetime import datetime
import pytest
from fastapi import HTTPException
import importlib
r = importlib.import_module('app.timetracking.backend.router')
from app.core.config import settings
from app.workflows import integration, settlement
def setup(monkeypatch, **changes):
entry = dict(id=7, medarbejder_id=2, status='pending', aktiv_timer=False, slut_tid=datetime.now(), work_type='support')
entry.update(changes)
monkeypatch.setattr(r, 'execute_query_single', lambda *a: entry)
monkeypatch.setattr(r, '_resolve_current_user_id', lambda user: 2)
monkeypatch.setattr(r, '_can_view_all_team_timers', lambda user: False)
monkeypatch.setattr(settings, 'WORKFLOWS_ENABLED', True)
monkeypatch.setattr(settings, 'WORKFLOWS_MODE', 'active')
monkeypatch.setattr(integration, 'active_for_customer', lambda customer: True)
monkeypatch.setattr(settlement, 'workflow_customer', lambda time_id: 17)
return entry
def test_register_preserves_pending_and_billing(monkeypatch):
entry = setup(monkeypatch)
calls = []
monkeypatch.setattr(r, 'execute_query', lambda sql, params: calls.append((sql, params)) or [entry])
result = asyncio.run(r.register_workflow_timer_v1(7, {'work_type':'meeting','fakturerbar_tid_min':30}, {'id':2}))
sql, params = calls[0]
assert params == ('meeting',30,7)
assert 'approved_hours' not in sql and 'billing_method' not in sql
assert "status='pending'" in sql and "kilde='workflow_registered'" in sql
assert result['status'] == 'pending'
@pytest.mark.parametrize('changes', [{'medarbejder_id':3}, {'status':'approved'}, {'aktiv_timer':True}, {'economy_order_draft_id':9}])
def test_register_rejects_other_owner_or_processed_timer(monkeypatch, changes):
setup(monkeypatch, **changes)
monkeypatch.setattr(r, 'execute_query', lambda *a: pytest.fail('Must not write'))
with pytest.raises(HTTPException):
asyncio.run(r.register_workflow_timer_v1(7, {'fakturerbar_tid_min':30}, {'id':2}))