aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/helpers')
-rw-r--r--server/tests/helpers/core-utils.ts65
-rw-r--r--server/tests/helpers/image.ts14
2 files changed, 48 insertions, 31 deletions
diff --git a/server/tests/helpers/core-utils.ts b/server/tests/helpers/core-utils.ts
index fa0a71341..e3e5eb45c 100644
--- a/server/tests/helpers/core-utils.ts
+++ b/server/tests/helpers/core-utils.ts
@@ -6,47 +6,64 @@ import { snakeCase } from 'lodash'
6import validator from 'validator' 6import validator from 'validator'
7import { getAverageBitrate, getMaxBitrate } from '@shared/core-utils' 7import { getAverageBitrate, getMaxBitrate } from '@shared/core-utils'
8import { VideoResolution } from '@shared/models' 8import { VideoResolution } from '@shared/models'
9import { objectConverter, parseBytes } from '../../helpers/core-utils' 9import { objectConverter, parseBytes, parseDurationToMs } from '../../helpers/core-utils'
10 10
11const expect = chai.expect 11const expect = chai.expect
12 12
13describe('Parse Bytes', function () { 13describe('Parse Bytes', function () {
14 14
15 it('Should pass when given valid value', async function () { 15 it('Should pass on valid value', async function () {
16 // just return it 16 // just return it
17 expect(parseBytes(1024)).to.be.eq(1024) 17 expect(parseBytes(-1024)).to.equal(-1024)
18 expect(parseBytes(1048576)).to.be.eq(1048576) 18 expect(parseBytes(1024)).to.equal(1024)
19 expect(parseBytes('1024')).to.be.eq(1024) 19 expect(parseBytes(1048576)).to.equal(1048576)
20 expect(parseBytes('1048576')).to.be.eq(1048576) 20 expect(parseBytes('1024')).to.equal(1024)
21 expect(parseBytes('1048576')).to.equal(1048576)
21 22
22 // sizes 23 // sizes
23 expect(parseBytes('1B')).to.be.eq(1024) 24 expect(parseBytes('1B')).to.equal(1024)
24 expect(parseBytes('1MB')).to.be.eq(1048576) 25 expect(parseBytes('1MB')).to.equal(1048576)
25 expect(parseBytes('1GB')).to.be.eq(1073741824) 26 expect(parseBytes('1GB')).to.equal(1073741824)
26 expect(parseBytes('1TB')).to.be.eq(1099511627776) 27 expect(parseBytes('1TB')).to.equal(1099511627776)
27 28
28 expect(parseBytes('5GB')).to.be.eq(5368709120) 29 expect(parseBytes('5GB')).to.equal(5368709120)
29 expect(parseBytes('5TB')).to.be.eq(5497558138880) 30 expect(parseBytes('5TB')).to.equal(5497558138880)
30 31
31 expect(parseBytes('1024B')).to.be.eq(1048576) 32 expect(parseBytes('1024B')).to.equal(1048576)
32 expect(parseBytes('1024MB')).to.be.eq(1073741824) 33 expect(parseBytes('1024MB')).to.equal(1073741824)
33 expect(parseBytes('1024GB')).to.be.eq(1099511627776) 34 expect(parseBytes('1024GB')).to.equal(1099511627776)
34 expect(parseBytes('1024TB')).to.be.eq(1125899906842624) 35 expect(parseBytes('1024TB')).to.equal(1125899906842624)
35 36
36 // with whitespace 37 // with whitespace
37 expect(parseBytes('1 GB')).to.be.eq(1073741824) 38 expect(parseBytes('1 GB')).to.equal(1073741824)
38 expect(parseBytes('1\tGB')).to.be.eq(1073741824) 39 expect(parseBytes('1\tGB')).to.equal(1073741824)
39 40
40 // sum value 41 // sum value
41 expect(parseBytes('1TB 1024MB')).to.be.eq(1100585369600) 42 expect(parseBytes('1TB 1024MB')).to.equal(1100585369600)
42 expect(parseBytes('4GB 1024MB')).to.be.eq(5368709120) 43 expect(parseBytes('4GB 1024MB')).to.equal(5368709120)
43 expect(parseBytes('4TB 1024GB')).to.be.eq(5497558138880) 44 expect(parseBytes('4TB 1024GB')).to.equal(5497558138880)
44 expect(parseBytes('4TB 1024GB 0MB')).to.be.eq(5497558138880) 45 expect(parseBytes('4TB 1024GB 0MB')).to.equal(5497558138880)
45 expect(parseBytes('1024TB 1024GB 1024MB')).to.be.eq(1127000492212224) 46 expect(parseBytes('1024TB 1024GB 1024MB')).to.equal(1127000492212224)
47 })
48
49 it('Should be invalid when given invalid value', async function () {
50 expect(parseBytes('6GB 1GB')).to.equal(6)
51 })
52})
53
54describe('Parse duration', function () {
55
56 it('Should pass when given valid value', async function () {
57 expect(parseDurationToMs(35)).to.equal(35)
58 expect(parseDurationToMs(-35)).to.equal(-35)
59 expect(parseDurationToMs('35 seconds')).to.equal(35 * 1000)
60 expect(parseDurationToMs('1 minute')).to.equal(60 * 1000)
61 expect(parseDurationToMs('1 hour')).to.equal(3600 * 1000)
62 expect(parseDurationToMs('35 hours')).to.equal(3600 * 35 * 1000)
46 }) 63 })
47 64
48 it('Should be invalid when given invalid value', async function () { 65 it('Should be invalid when given invalid value', async function () {
49 expect(parseBytes('6GB 1GB')).to.be.eq(6) 66 expect(parseBytes('35m 5s')).to.equal(35)
50 }) 67 })
51}) 68})
52 69
diff --git a/server/tests/helpers/image.ts b/server/tests/helpers/image.ts
index 475ca8fb2..7c5da69b5 100644
--- a/server/tests/helpers/image.ts
+++ b/server/tests/helpers/image.ts
@@ -37,28 +37,28 @@ describe('Image helpers', function () {
37 37
38 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 () {
39 const input = buildAbsoluteFixturePath('thumbnail.jpg') 39 const input = buildAbsoluteFixturePath('thumbnail.jpg')
40 await processImage(input, imageDestJPG, thumbnailSize, true) 40 await processImage({ path: input, destination: imageDestJPG, newSize: thumbnailSize, keepOriginal: true })
41 41
42 await checkBuffers(input, imageDestJPG, true) 42 await checkBuffers(input, imageDestJPG, true)
43 }) 43 })
44 44
45 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 () {
46 const input = buildAbsoluteFixturePath('thumbnail.png') 46 const input = buildAbsoluteFixturePath('thumbnail.png')
47 await processImage(input, imageDestJPG, thumbnailSize, true) 47 await processImage({ path: input, destination: imageDestJPG, newSize: thumbnailSize, keepOriginal: true })
48 48
49 await checkBuffers(input, imageDestJPG, false) 49 await checkBuffers(input, imageDestJPG, false)
50 }) 50 })
51 51
52 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 () {
53 const input = buildAbsoluteFixturePath('preview.jpg') 53 const input = buildAbsoluteFixturePath('preview.jpg')
54 await processImage(input, imageDestJPG, thumbnailSize, true) 54 await processImage({ path: input, destination: imageDestJPG, newSize: thumbnailSize, keepOriginal: true })
55 55
56 await checkBuffers(input, imageDestJPG, false) 56 await checkBuffers(input, imageDestJPG, false)
57 }) 57 })
58 58
59 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 () {
60 const input = buildAbsoluteFixturePath('thumbnail-big.jpg') 60 const input = buildAbsoluteFixturePath('thumbnail-big.jpg')
61 await processImage(input, imageDestJPG, thumbnailSize, true) 61 await processImage({ path: input, destination: imageDestJPG, newSize: thumbnailSize, keepOriginal: true })
62 62
63 await checkBuffers(input, imageDestJPG, false) 63 await checkBuffers(input, imageDestJPG, false)
64 }) 64 })
@@ -67,7 +67,7 @@ describe('Image helpers', function () {
67 const input = buildAbsoluteFixturePath('exif.jpg') 67 const input = buildAbsoluteFixturePath('exif.jpg')
68 expect(await hasTitleExif(input)).to.be.true 68 expect(await hasTitleExif(input)).to.be.true
69 69
70 await processImage(input, imageDestJPG, { width: 100, height: 100 }, true) 70 await processImage({ path: input, destination: imageDestJPG, newSize: { width: 100, height: 100 }, keepOriginal: true })
71 await checkBuffers(input, imageDestJPG, false) 71 await checkBuffers(input, imageDestJPG, false)
72 72
73 expect(await hasTitleExif(imageDestJPG)).to.be.false 73 expect(await hasTitleExif(imageDestJPG)).to.be.false
@@ -77,7 +77,7 @@ describe('Image helpers', function () {
77 const input = buildAbsoluteFixturePath('exif.jpg') 77 const input = buildAbsoluteFixturePath('exif.jpg')
78 expect(await hasTitleExif(input)).to.be.true 78 expect(await hasTitleExif(input)).to.be.true
79 79
80 await processImage(input, imageDestJPG, thumbnailSize, true) 80 await processImage({ path: input, destination: imageDestJPG, newSize: thumbnailSize, keepOriginal: true })
81 await checkBuffers(input, imageDestJPG, false) 81 await checkBuffers(input, imageDestJPG, false)
82 82
83 expect(await hasTitleExif(imageDestJPG)).to.be.false 83 expect(await hasTitleExif(imageDestJPG)).to.be.false
@@ -87,7 +87,7 @@ describe('Image helpers', function () {
87 const input = buildAbsoluteFixturePath('exif.png') 87 const input = buildAbsoluteFixturePath('exif.png')
88 expect(await hasTitleExif(input)).to.be.true 88 expect(await hasTitleExif(input)).to.be.true
89 89
90 await processImage(input, imageDestPNG, thumbnailSize, true) 90 await processImage({ path: input, destination: imageDestPNG, newSize: thumbnailSize, keepOriginal: true })
91 expect(await hasTitleExif(imageDestPNG)).to.be.false 91 expect(await hasTitleExif(imageDestPNG)).to.be.false
92 }) 92 })
93 93