diff options
Diffstat (limited to 'server/tests/helpers/image.ts')
-rw-r--r-- | server/tests/helpers/image.ts | 96 |
1 files changed, 0 insertions, 96 deletions
diff --git a/server/tests/helpers/image.ts b/server/tests/helpers/image.ts deleted file mode 100644 index 6021ffc48..000000000 --- a/server/tests/helpers/image.ts +++ /dev/null | |||
@@ -1,96 +0,0 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import { expect } from 'chai' | ||
4 | import { readFile, remove } from 'fs-extra' | ||
5 | import { join } from 'path' | ||
6 | import { execPromise } from '@server/helpers/core-utils' | ||
7 | import { buildAbsoluteFixturePath, root } from '@shared/core-utils' | ||
8 | import { processImage } from '../../../server/helpers/image-utils' | ||
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 | async function hasTitleExif (path: string) { | ||
24 | const result = JSON.parse(await execPromise(`exiftool -json ${path}`)) | ||
25 | |||
26 | return result[0]?.Title === 'should be removed' | ||
27 | } | ||
28 | |||
29 | describe('Image helpers', function () { | ||
30 | const imageDestDir = join(root(), 'test-images') | ||
31 | |||
32 | const imageDestJPG = join(imageDestDir, 'test.jpg') | ||
33 | const imageDestPNG = join(imageDestDir, 'test.png') | ||
34 | |||
35 | const thumbnailSize = { width: 280, height: 157 } | ||
36 | |||
37 | it('Should skip processing if the source image is okay', async function () { | ||
38 | const input = buildAbsoluteFixturePath('custom-thumbnail.jpg') | ||
39 | await processImage({ path: input, destination: imageDestJPG, newSize: thumbnailSize, keepOriginal: true }) | ||
40 | |||
41 | await checkBuffers(input, imageDestJPG, true) | ||
42 | }) | ||
43 | |||
44 | it('Should not skip processing if the source image does not have the appropriate extension', async function () { | ||
45 | const input = buildAbsoluteFixturePath('custom-thumbnail.png') | ||
46 | await processImage({ path: input, destination: imageDestJPG, newSize: thumbnailSize, keepOriginal: true }) | ||
47 | |||
48 | await checkBuffers(input, imageDestJPG, false) | ||
49 | }) | ||
50 | |||
51 | it('Should not skip processing if the source image does not have the appropriate size', async function () { | ||
52 | const input = buildAbsoluteFixturePath('custom-preview.jpg') | ||
53 | await processImage({ path: input, destination: imageDestJPG, newSize: thumbnailSize, keepOriginal: true }) | ||
54 | |||
55 | await checkBuffers(input, imageDestJPG, false) | ||
56 | }) | ||
57 | |||
58 | it('Should not skip processing if the source image does not have the appropriate size', async function () { | ||
59 | const input = buildAbsoluteFixturePath('custom-thumbnail-big.jpg') | ||
60 | await processImage({ path: input, destination: imageDestJPG, newSize: thumbnailSize, keepOriginal: true }) | ||
61 | |||
62 | await checkBuffers(input, imageDestJPG, false) | ||
63 | }) | ||
64 | |||
65 | it('Should strip exif for a jpg file that can not be copied', async function () { | ||
66 | const input = buildAbsoluteFixturePath('exif.jpg') | ||
67 | expect(await hasTitleExif(input)).to.be.true | ||
68 | |||
69 | await processImage({ path: input, destination: imageDestJPG, newSize: { width: 100, height: 100 }, keepOriginal: true }) | ||
70 | await checkBuffers(input, imageDestJPG, false) | ||
71 | |||
72 | expect(await hasTitleExif(imageDestJPG)).to.be.false | ||
73 | }) | ||
74 | |||
75 | it('Should strip exif for a jpg file that could be copied', async function () { | ||
76 | const input = buildAbsoluteFixturePath('exif.jpg') | ||
77 | expect(await hasTitleExif(input)).to.be.true | ||
78 | |||
79 | await processImage({ path: input, destination: imageDestJPG, newSize: thumbnailSize, keepOriginal: true }) | ||
80 | await checkBuffers(input, imageDestJPG, false) | ||
81 | |||
82 | expect(await hasTitleExif(imageDestJPG)).to.be.false | ||
83 | }) | ||
84 | |||
85 | it('Should strip exif for png', async function () { | ||
86 | const input = buildAbsoluteFixturePath('exif.png') | ||
87 | expect(await hasTitleExif(input)).to.be.true | ||
88 | |||
89 | await processImage({ path: input, destination: imageDestPNG, newSize: thumbnailSize, keepOriginal: true }) | ||
90 | expect(await hasTitleExif(imageDestPNG)).to.be.false | ||
91 | }) | ||
92 | |||
93 | after(async function () { | ||
94 | await remove(imageDestDir) | ||
95 | }) | ||
96 | }) | ||