|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require_relative "../../test_helper" |
| 4 | + |
| 5 | +class BuildTransformationStringTest < Minitest::Test |
| 6 | + def setup |
| 7 | + @client = Imagekit::Client.new( |
| 8 | + private_key: "test-key", |
| 9 | + password: "test_password" |
| 10 | + ) |
| 11 | + end |
| 12 | + |
| 13 | + def test_should_return_empty_string_for_empty_transformation_array |
| 14 | + result = @client.helper.build_transformation_string(nil) |
| 15 | + assert_equal("", result) |
| 16 | + |
| 17 | + result = @client.helper.build_transformation_string([]) |
| 18 | + assert_equal("", result) |
| 19 | + end |
| 20 | + |
| 21 | + def test_should_generate_transformation_string_for_width_only |
| 22 | + transformation = [ |
| 23 | + Imagekit::Models::Transformation.new( |
| 24 | + width: 300.0 |
| 25 | + ) |
| 26 | + ] |
| 27 | + |
| 28 | + result = @client.helper.build_transformation_string(transformation) |
| 29 | + expected = "w-300" |
| 30 | + assert_equal(expected, result) |
| 31 | + end |
| 32 | + |
| 33 | + def test_should_generate_transformation_string_for_multiple_parameters |
| 34 | + transformation = [ |
| 35 | + Imagekit::Models::Transformation.new( |
| 36 | + width: 300.0, |
| 37 | + height: 200.0 |
| 38 | + ) |
| 39 | + ] |
| 40 | + |
| 41 | + result = @client.helper.build_transformation_string(transformation) |
| 42 | + expected = "w-300,h-200" |
| 43 | + assert_equal(expected, result) |
| 44 | + end |
| 45 | + |
| 46 | + def test_should_generate_transformation_string_for_chained_transformations |
| 47 | + transformation = [ |
| 48 | + Imagekit::Models::Transformation.new( |
| 49 | + width: 300.0 |
| 50 | + ), |
| 51 | + Imagekit::Models::Transformation.new( |
| 52 | + height: 200.0 |
| 53 | + ) |
| 54 | + ] |
| 55 | + |
| 56 | + result = @client.helper.build_transformation_string(transformation) |
| 57 | + expected = "w-300:h-200" |
| 58 | + assert_equal(expected, result) |
| 59 | + end |
| 60 | + |
| 61 | + def test_should_handle_empty_transformation_object |
| 62 | + transformation = [ |
| 63 | + Imagekit::Models::Transformation.new |
| 64 | + ] |
| 65 | + |
| 66 | + result = @client.helper.build_transformation_string(transformation) |
| 67 | + expected = "" |
| 68 | + assert_equal(expected, result) |
| 69 | + end |
| 70 | + |
| 71 | + def test_should_handle_transformation_with_overlay |
| 72 | + transformation = [ |
| 73 | + Imagekit::Models::Transformation.new( |
| 74 | + overlay_text: "Hello" |
| 75 | + ) |
| 76 | + ] |
| 77 | + |
| 78 | + result = @client.helper.build_transformation_string(transformation) |
| 79 | + expected = "l-text,i-Hello,l-end" |
| 80 | + assert_equal(expected, result) |
| 81 | + end |
| 82 | + |
| 83 | + def test_should_handle_raw_transformation_parameter |
| 84 | + transformation = [ |
| 85 | + Imagekit::Models::Transformation.new( |
| 86 | + raw: "custom-transform-123" |
| 87 | + ) |
| 88 | + ] |
| 89 | + |
| 90 | + result = @client.helper.build_transformation_string(transformation) |
| 91 | + expected = "custom-transform-123" |
| 92 | + assert_equal(expected, result) |
| 93 | + end |
| 94 | + |
| 95 | + def test_should_handle_mixed_parameters_with_raw |
| 96 | + transformation = [ |
| 97 | + Imagekit::Models::Transformation.new( |
| 98 | + width: 300.0, |
| 99 | + raw: "custom-param-123" |
| 100 | + ) |
| 101 | + ] |
| 102 | + |
| 103 | + result = @client.helper.build_transformation_string(transformation) |
| 104 | + expected = "w-300,custom-param-123" |
| 105 | + assert_equal(expected, result) |
| 106 | + end |
| 107 | + |
| 108 | + def test_should_handle_quality_parameter |
| 109 | + transformation = [ |
| 110 | + Imagekit::Models::Transformation.new( |
| 111 | + quality: 80.0 |
| 112 | + ) |
| 113 | + ] |
| 114 | + |
| 115 | + result = @client.helper.build_transformation_string(transformation) |
| 116 | + expected = "q-80" |
| 117 | + assert_equal(expected, result) |
| 118 | + end |
| 119 | + |
| 120 | + def test_should_handle_aspect_ratio_parameter |
| 121 | + transformation = [ |
| 122 | + Imagekit::Models::Transformation.new( |
| 123 | + aspect_ratio: "4:3" |
| 124 | + ) |
| 125 | + ] |
| 126 | + |
| 127 | + result = @client.helper.build_transformation_string(transformation) |
| 128 | + expected = "ar-4:3" |
| 129 | + assert_equal(expected, result) |
| 130 | + end |
| 131 | +end |
0 commit comments