aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/utils/videos/videos.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/utils/videos/videos.ts')
-rw-r--r--server/tests/utils/videos/videos.ts31
1 files changed, 24 insertions, 7 deletions
diff --git a/server/tests/utils/videos/videos.ts b/server/tests/utils/videos/videos.ts
index 095d4e29d..270a6042b 100644
--- a/server/tests/utils/videos/videos.ts
+++ b/server/tests/utils/videos/videos.ts
@@ -1,13 +1,13 @@
1/* tslint:disable:no-unused-expression */ 1/* tslint:disable:no-unused-expression */
2 2
3import { expect } from 'chai' 3import { expect } from 'chai'
4import { readFile } from 'fs' 4import { existsSync, readFile } from 'fs'
5import * as parseTorrent from 'parse-torrent' 5import * as parseTorrent from 'parse-torrent'
6import { extname, isAbsolute, join } from 'path' 6import { extname, isAbsolute, join } from 'path'
7import * as request from 'supertest' 7import * as request from 'supertest'
8import { getMyUserInformation, makeGetRequest, ServerInfo } from '../' 8import { getMyUserInformation, makeGetRequest, root, ServerInfo } from '../'
9import { VideoPrivacy } from '../../../../shared/models/videos' 9import { VideoPrivacy } from '../../../../shared/models/videos'
10import { readFileBufferPromise } from '../../../helpers/core-utils' 10import { readdirPromise, readFileBufferPromise } from '../../../helpers/core-utils'
11import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../initializers' 11import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../initializers'
12import { dateIsValid, webtorrentAdd } from '../index' 12import { dateIsValid, webtorrentAdd } from '../index'
13 13
@@ -203,7 +203,23 @@ function searchVideoWithSort (url: string, search: string, sort: string) {
203 .expect('Content-Type', /json/) 203 .expect('Content-Type', /json/)
204} 204}
205 205
206async function testVideoImage (url: string, imageName: string, imagePath: string, extension = '.jpg') { 206async function checkVideoFilesWereRemoved (videoUUID: string, serverNumber: number) {
207 const testDirectory = 'test' + serverNumber
208
209 for (const directory of [ 'videos', 'thumbnails', 'torrents', 'previews' ]) {
210 const directoryPath = join(root(), testDirectory, directory)
211
212 const directoryExists = existsSync(directoryPath)
213 expect(directoryExists).to.be.true
214
215 const files = await readdirPromise(directoryPath)
216 for (const file of files) {
217 expect(file).to.not.contain(videoUUID)
218 }
219 }
220}
221
222async function testImage (url: string, imageName: string, imagePath: string, extension = '.jpg') {
207 // Don't test images if the node env is not set 223 // Don't test images if the node env is not set
208 // Because we need a special ffmpeg version for this test 224 // Because we need a special ffmpeg version for this test
209 if (process.env['NODE_TEST_IMAGE']) { 225 if (process.env['NODE_TEST_IMAGE']) {
@@ -409,7 +425,7 @@ async function completeVideoCheck (
409 const maxSize = attributeFile.size + ((10 * attributeFile.size) / 100) 425 const maxSize = attributeFile.size + ((10 * attributeFile.size) / 100)
410 expect(file.size).to.be.above(minSize).and.below(maxSize) 426 expect(file.size).to.be.above(minSize).and.below(maxSize)
411 427
412 const test = await testVideoImage(url, attributes.fixture, videoDetails.thumbnailPath) 428 const test = await testImage(url, attributes.fixture, videoDetails.thumbnailPath)
413 expect(test).to.equal(true) 429 expect(test).to.equal(true)
414 430
415 const torrent = await webtorrentAdd(magnetUri, true) 431 const torrent = await webtorrentAdd(magnetUri, true)
@@ -437,11 +453,12 @@ export {
437 searchVideo, 453 searchVideo,
438 searchVideoWithPagination, 454 searchVideoWithPagination,
439 searchVideoWithSort, 455 searchVideoWithSort,
440 testVideoImage, 456 testImage,
441 uploadVideo, 457 uploadVideo,
442 updateVideo, 458 updateVideo,
443 rateVideo, 459 rateVideo,
444 viewVideo, 460 viewVideo,
445 parseTorrentVideo, 461 parseTorrentVideo,
446 completeVideoCheck 462 completeVideoCheck,
463 checkVideoFilesWereRemoved
447} 464}