Reactoring + added new tests
parent
30775e7b41
commit
41d83e8b61
Binary file not shown.
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 110 KiB |
@ -0,0 +1,26 @@
|
|||||||
|
import app from "../index"
|
||||||
|
import resizeImg from "../utilities/imgProcessing"
|
||||||
|
import sizeOf from 'image-size'
|
||||||
|
import supertest from "supertest"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const request = supertest(app);
|
||||||
|
|
||||||
|
describe('Test on utilities', () => {
|
||||||
|
it('Image should have correct size after resize', async () => {
|
||||||
|
let outputImg = await resizeImg(400, 400, 'fjord');
|
||||||
|
let dimensions = sizeOf(outputImg);
|
||||||
|
expect(dimensions.width).toBe(400);
|
||||||
|
expect(dimensions.height).toBe(400);
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('Test on the image endpoint with resize', () => {
|
||||||
|
it('Resize working with filename and width/height parameters', async () => {
|
||||||
|
const response = await request.get('/api/image?filename=encenadaport&width=200&height=200');
|
||||||
|
expect(response.status).toBe(200);
|
||||||
|
})
|
||||||
|
})
|
@ -0,0 +1,20 @@
|
|||||||
|
import sharp from "sharp"
|
||||||
|
import path from "path"
|
||||||
|
|
||||||
|
const resizeImg = async (width: number, height: number, fileName: string): Promise<string> => {
|
||||||
|
// output file for resized img
|
||||||
|
let inputimgPath: string = path.resolve("images/full", `${fileName}.jpg`);
|
||||||
|
let outputImg: string = path.resolve("images/thumb", `${fileName}.jpg`);
|
||||||
|
await sharp(path.resolve(inputimgPath))
|
||||||
|
.resize(width, height)
|
||||||
|
.toFormat("jpeg")
|
||||||
|
.jpeg({
|
||||||
|
quality: 100,
|
||||||
|
mozjpeg: true
|
||||||
|
})
|
||||||
|
.toFile(path.resolve(outputImg))
|
||||||
|
|
||||||
|
return outputImg
|
||||||
|
}
|
||||||
|
|
||||||
|
export default resizeImg
|
Loading…
Reference in New Issue