"""worker.py — job_type 디스패처 (4 provider)."""
import pytest
from unittest.mock import patch

import worker


def test_dispatch_sora_calls_run_sora_generation():
    payload = {"task_id": "t1", "job_type": "sora_generation", "params": {"prompt": "x"}}
    with patch("worker.run_sora_generation") as m:
        worker._dispatch(payload)
        m.assert_called_once_with("t1", {"prompt": "x"})


def test_dispatch_veo_calls_run_veo_generation():
    payload = {"task_id": "t2", "job_type": "veo_generation", "params": {"prompt": "x"}}
    with patch("worker.run_veo_generation") as m:
        worker._dispatch(payload)
        m.assert_called_once_with("t2", {"prompt": "x"})


def test_dispatch_kling_calls_run_kling_generation():
    payload = {"task_id": "t3", "job_type": "kling_generation", "params": {"prompt": "x"}}
    with patch("worker.run_kling_generation") as m:
        worker._dispatch(payload)
        m.assert_called_once_with("t3", {"prompt": "x"})


def test_dispatch_seedance_calls_run_seedance_generation():
    payload = {"task_id": "t4", "job_type": "seedance_generation", "params": {"prompt": "x"}}
    with patch("worker.run_seedance_generation") as m:
        worker._dispatch(payload)
        m.assert_called_once_with("t4", {"prompt": "x"})


def test_dispatch_unknown_job_type_logs_error():
    payload = {"task_id": "t5", "job_type": "weird_type", "params": {}}
    with patch("worker.webhook_update_task") as m:
        worker._dispatch(payload)
        m.assert_called_once()
        args = m.call_args[0]
        assert args[0] == "t5"
        assert args[1] == "failed"
