From 72bcad0f4b5ec97abb10dfd1437f8e806a2cc877 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Pr=C3=A9vost?= Date: Wed, 1 Nov 2023 10:48:15 -0400 Subject: [PATCH] Fix internal error on info operation in pipeline (#4) --- lib/plug_image_processing/operations/info.ex | 4 +++ test/plug_image_processing/web_test.exs | 26 ++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/lib/plug_image_processing/operations/info.ex b/lib/plug_image_processing/operations/info.ex index 0c0e955..0fe060a 100644 --- a/lib/plug_image_processing/operations/info.ex +++ b/lib/plug_image_processing/operations/info.ex @@ -3,6 +3,10 @@ defmodule PlugImageProcessing.Operations.Info do alias Vix.Vips.Image + def new(_image, _params, _config) do + {:error, :invalid_operation} + end + defimpl PlugImageProcessing.Info do def process(operation) do {:ok, diff --git a/test/plug_image_processing/web_test.exs b/test/plug_image_processing/web_test.exs index 88f5bfe..b07c203 100644 --- a/test/plug_image_processing/web_test.exs +++ b/test/plug_image_processing/web_test.exs @@ -157,5 +157,31 @@ defmodule PlugImageProcessing.WebTest do assert image_metadata["has_alpha"] === false assert image_metadata["channels"] === 3 end + + test "pipeline", %{config: config} do + plug_opts = Web.init(config) + conn = conn(:get, "/imageproxy/pipeline", %{operations: Jason.encode!([%{operation: "crop", params: %{width: 20, height: 50}}]), url: "http://example.org/valid.jpg"}) + conn = Web.call(conn, plug_opts) + + {:ok, image} = conn_to_image(conn) + + assert Image.width(image) === 20 + assert Image.height(image) === 50 + end + + test "pipeline info", %{config: config} do + plug_opts = Web.init(config) + + conn = + conn(:get, "/imageproxy/pipeline", %{ + operations: Jason.encode!([%{operation: "crop", params: %{width: 20, height: 50}}, %{operation: "info"}]), + url: "http://example.org/valid.jpg" + }) + + conn = Web.call(conn, plug_opts) + + assert conn.status === 400 + assert conn.resp_body === "Bad request: :invalid_operation" + end end end