diff options
Diffstat (limited to 'server/tests/helpers')
-rw-r--r-- | server/tests/helpers/image.ts | 59 | ||||
-rw-r--r-- | server/tests/helpers/index.ts | 1 |
2 files changed, 60 insertions, 0 deletions
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 | |||
3 | import 'mocha' | ||
4 | import { readFile, remove } from 'fs-extra' | ||
5 | import { join } from 'path' | ||
6 | import { processImage } from '../../../server/helpers/image-utils' | ||
7 | import { buildAbsoluteFixturePath, root } from '../../../shared/extra-utils' | ||
8 | import { expect } from 'chai' | ||
9 | |||
10 | async 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 | |||
23 | describe('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 @@ | |||
1 | import './image' | ||
1 | import './core-utils' | 2 | import './core-utils' |
2 | import './comment-model' | 3 | import './comment-model' |
3 | import './request' | 4 | import './request' |