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