diff --git a/backend/src/test/java/com/recipeapp/recipe/ImageCompressorTest.java b/backend/src/test/java/com/recipeapp/recipe/ImageCompressorTest.java index 8d2c7c5..c9f1522 100644 --- a/backend/src/test/java/com/recipeapp/recipe/ImageCompressorTest.java +++ b/backend/src/test/java/com/recipeapp/recipe/ImageCompressorTest.java @@ -80,6 +80,17 @@ class ImageCompressorTest { assertThat(compressor.compressToPreview("data:image/jpeg;base64,!!!not-valid!!!")).isNull(); } + @Test + void compressToPreview_acceptsJpegInput() throws Exception { + String dataUri = makeJpegDataUri(800, 600); + String result = compressor.compressToPreview(dataUri); + assertThat(result).startsWith("data:image/jpeg;base64,"); + String base64 = result.substring("data:image/jpeg;base64,".length()); + BufferedImage img = ImageIO.read(new ByteArrayInputStream(Base64.getDecoder().decode(base64))); + assertThat(img).isNotNull(); + assertThat(img.getWidth()).isLessThanOrEqualTo(400); + } + // ── helpers ── private String makePngDataUri(int width, int height) throws Exception { @@ -95,4 +106,15 @@ class ImageCompressorTest { ImageIO.write(img, "png", bos); return "data:image/png;base64," + Base64.getEncoder().encodeToString(bos.toByteArray()); } + + private String makeJpegDataUri(int width, int height) throws Exception { + BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); + java.awt.Graphics2D g = img.createGraphics(); + g.setColor(java.awt.Color.ORANGE); + g.fillRect(0, 0, width, height); + g.dispose(); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + ImageIO.write(img, "jpeg", bos); + return "data:image/jpeg;base64," + Base64.getEncoder().encodeToString(bos.toByteArray()); + } }