"""infer_mime_type_from_storage_key 纯逻辑单测.

Worker core 工具函数，从 storage_key 推断 MIME 类型。
"""

from __future__ import annotations

from worker_app.core.asset_types import infer_mime_type_from_storage_key


class TestInferMimeTypeFromStorageKey:
    """infer_mime_type_from_storage_key 测试."""

    def test_mp4_returns_video_mp4(self):
        """mp4 后缀返回 video/mp4."""
        assert infer_mime_type_from_storage_key("projects/abc/video.mp4") == "video/mp4"

    def test_mov_returns_quicktime(self):
        """mov 后缀返回 video/quicktime."""
        assert infer_mime_type_from_storage_key("uploads/test.mov") == "video/quicktime"

    def test_m4v_returns_video_mp4(self):
        """m4v 后缀返回 video/mp4."""
        assert infer_mime_type_from_storage_key("clip.m4v") == "video/mp4"

    def test_avi_returns_video_mp4(self):
        """avi 后缀返回 video/mp4."""
        assert infer_mime_type_from_storage_key("movie.avi") == "video/mp4"

    def test_mkv_returns_video_mp4(self):
        """mkv 后缀返回 video/mp4."""
        assert infer_mime_type_from_storage_key("video.mkv") == "video/mp4"

    def test_webm_returns_video_mp4(self):
        """webm 后缀返回 video/mp4."""
        assert infer_mime_type_from_storage_key("output.webm") == "video/mp4"

    def test_jpg_default_returns_image_jpeg(self):
        """jpg 等非视频后缀默认返回 image/jpeg."""
        assert infer_mime_type_from_storage_key("thumb.jpg") == "image/jpeg"

    def test_png_default_returns_image_jpeg(self):
        """png 也返回 image/jpeg（当前实现的默认值）."""
        assert infer_mime_type_from_storage_key("image.png") == "image/jpeg"

    def test_no_extension_returns_jpeg(self):
        """无扩展名返回 image/jpeg."""
        assert infer_mime_type_from_storage_key("random_file") == "image/jpeg"

    def test_case_insensitive(self):
        """大小写不敏感."""
        assert infer_mime_type_from_storage_key("VIDEO.MP4") == "video/mp4"
        assert infer_mime_type_from_storage_key("Clip.MOV") == "video/quicktime"

    def test_deep_path(self):
        """多级路径正常推断."""
        assert infer_mime_type_from_storage_key("generated/projects/abc/def/output.mp4") == "video/mp4"

    def test_empty_string(self):
        """空字符串返回 image/jpeg（默认值）."""
        assert infer_mime_type_from_storage_key("") == "image/jpeg"

    def test_filename_with_multiple_dots(self):
        """文件名含多个点时取最后一个扩展名."""
        assert infer_mime_type_from_storage_key("my.video.file.mp4") == "video/mp4"

    def test_mov_case_insensitive_upper(self):
        """MOV 大写也识别为 quicktime."""
        assert infer_mime_type_from_storage_key("video.MOV") == "video/quicktime"
