defmodule ImageToolsTest do use ExUnit.Case @test_path Path.join(__DIR__, "assets/sample.jpg") @test_image File.read!(@test_path) test "rotate/1 rotates an image" do assert {:ok, @test_path} = ImageTools.rotate(@test_path) end test "rotate_right/1 rotates an image" do assert {:ok, @test_path} = ImageTools.rotate_right(@test_path) end test "rotate_left/1 rotates an image" do # do this twice so it undoes the right rotation assert {:ok, @test_path} = ImageTools.rotate_left(@test_path) assert {:ok, @test_path} = ImageTools.rotate_left(@test_path) end test "flip/1 rotates an image" do # do this twice so it undo itself assert {:ok, @test_path} = ImageTools.flip(@test_path) assert {:ok, @test_path} = ImageTools.flip(@test_path) end test "create_thumbnail/4 creates a thumbnail successfully" do assert {:ok, binary} = ImageTools.create_thumbnail(@test_image, 320, 240) assert is_binary(binary) end test "create_thumbnail/4 handles quality option" do assert {:ok, binary} = ImageTools.create_thumbnail(@test_image, 320, 240, quality: 50) assert is_binary(binary) end test "create_thumbnail/4 handles target_size option" do assert {:ok, binary} = ImageTools.create_thumbnail(@test_image, 320, 240, target_size: 12_000) assert is_binary(binary) end test "create_thumbnail/4 handles invalid input" do assert {:error, "width must be > 0"} = ImageTools.create_thumbnail(@test_image, 0, 240) assert {:error, "height must be > 0"} = ImageTools.create_thumbnail(@test_image, 320, 0) assert {:error, "quality must be >= 0"} = ImageTools.create_thumbnail(@test_image, 320, 240, quality: -1) assert {:error, "quality must be <= 100"} = ImageTools.create_thumbnail(@test_image, 320, 240, quality: 101) assert {:error, "target_size must be > 0"} = ImageTools.create_thumbnail(@test_image, 320, 240, target_size: 0) end end