aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/fixtures/thumbnail-big.jpgbin0 -> 16286 bytes
-rw-r--r--server/tests/fixtures/thumbnail.pngbin0 -> 4221 bytes
-rw-r--r--server/tests/helpers/image.ts59
-rw-r--r--server/tests/helpers/index.ts1
4 files changed, 60 insertions, 0 deletions
diff --git a/server/tests/fixtures/thumbnail-big.jpg b/server/tests/fixtures/thumbnail-big.jpg
new file mode 100644
index 000000000..537720d24
--- /dev/null
+++ b/server/tests/fixtures/thumbnail-big.jpg
Binary files differ
diff --git a/server/tests/fixtures/thumbnail.png b/server/tests/fixtures/thumbnail.png
new file mode 100644
index 000000000..b331aba3b
--- /dev/null
+++ b/server/tests/fixtures/thumbnail.png
Binary files differ
diff --git a/server/tests/helpers/image.ts b/server/tests/helpers/image.ts
new file mode 100644
index 000000000..54911697f
--- /dev/null
+++ b/server/tests/helpers/image.ts
@@ -0,0 +1,59 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
4import { readFile, remove } from 'fs-extra'
5import { join } from 'path'
6import { processImage } from '../../../server/helpers/image-utils'
7import { buildAbsoluteFixturePath, root } from '../../../shared/extra-utils'
8import { expect } from 'chai'
9
10async function checkBuffers (path1: string, path2: string, equals: boolean) {
11 const [ buf1, buf2 ] = await Promise.all([
12 readFile(path1),
13 readFile(path2)
14 ])
15
16 if (equals) {
17 expect(buf1.equals(buf2)).to.be.true
18 } else {
19 expect(buf1.equals(buf2)).to.be.false
20 }
21}
22
23describe('Image helpers', function () {
24 const imageDestDir = join(root(), 'test-images')
25 const imageDest = join(imageDestDir, 'test.jpg')
26 const thumbnailSize = { width: 223, height: 122 }
27
28 it('Should skip processing if the source image is okay', async function () {
29 const input = buildAbsoluteFixturePath('thumbnail.jpg')
30 await processImage(input, imageDest, thumbnailSize, true)
31
32 await checkBuffers(input, imageDest, true)
33 })
34
35 it('Should not skip processing if the source image does not have the appropriate extension', async function () {
36 const input = buildAbsoluteFixturePath('thumbnail.png')
37 await processImage(input, imageDest, thumbnailSize, true)
38
39 await checkBuffers(input, imageDest, false)
40 })
41
42 it('Should not skip processing if the source image does not have the appropriate size', async function () {
43 const input = buildAbsoluteFixturePath('preview.jpg')
44 await processImage(input, imageDest, thumbnailSize, true)
45
46 await checkBuffers(input, imageDest, false)
47 })
48
49 it('Should not skip processing if the source image does not have the appropriate size', async function () {
50 const input = buildAbsoluteFixturePath('thumbnail-big.jpg')
51 await processImage(input, imageDest, thumbnailSize, true)
52
53 await checkBuffers(input, imageDest, false)
54 })
55
56 after(async function () {
57 await remove(imageDest)
58 })
59})
diff --git a/server/tests/helpers/index.ts b/server/tests/helpers/index.ts
index 03b971770..66db93c99 100644
--- a/server/tests/helpers/index.ts
+++ b/server/tests/helpers/index.ts
@@ -1,3 +1,4 @@
1import './image'
1import './core-utils' 2import './core-utils'
2import './comment-model' 3import './comment-model'
3import './request' 4import './request'