From 9ee83eb99e908c6038cbb6501bacfe18d092f0b6 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 24 Jan 2018 11:03:13 +0100 Subject: Fix tests --- server/tests/utils/miscs/miscs.ts | 27 +++++++++++++++++++++++++++ server/tests/utils/videos/videos.ts | 20 +------------------- 2 files changed, 28 insertions(+), 19 deletions(-) (limited to 'server') diff --git a/server/tests/utils/miscs/miscs.ts b/server/tests/utils/miscs/miscs.ts index e6666619b..f93e2372e 100644 --- a/server/tests/utils/miscs/miscs.ts +++ b/server/tests/utils/miscs/miscs.ts @@ -1,5 +1,10 @@ +/* tslint:disable:no-unused-expression */ + +import { expect } from 'chai' import { join } from 'path' +import * as request from 'supertest' import * as WebTorrent from 'webtorrent' +import { readFileBufferPromise } from '../../../helpers/core-utils' let webtorrent = new WebTorrent() @@ -30,6 +35,27 @@ function root () { return join(__dirname, '..', '..', '..', '..') } +async function testImage (url: string, imageName: string, imagePath: string, extension = '.jpg') { + // Don't test images if the node env is not set + // Because we need a special ffmpeg version for this test + if (process.env[ 'NODE_TEST_IMAGE' ]) { + const res = await request(url) + .get(imagePath) + .expect(200) + + const body = res.body + + const data = await readFileBufferPromise(join(__dirname, '..', '..', 'api', 'fixtures', imageName + extension)) + const minLength = body.length - ((50 * body.length) / 100) + const maxLength = body.length + ((50 * body.length) / 100) + + return data.length > minLength && data.length < maxLength + } else { + console.log('Do not test images. Enable it by setting NODE_TEST_IMAGE env variable.') + return true + } +} + // --------------------------------------------------------------------------- export { @@ -37,5 +63,6 @@ export { wait, webtorrentAdd, immutableAssign, + testImage, root } diff --git a/server/tests/utils/videos/videos.ts b/server/tests/utils/videos/videos.ts index 270a6042b..605acf565 100644 --- a/server/tests/utils/videos/videos.ts +++ b/server/tests/utils/videos/videos.ts @@ -5,7 +5,7 @@ import { existsSync, readFile } from 'fs' import * as parseTorrent from 'parse-torrent' import { extname, isAbsolute, join } from 'path' import * as request from 'supertest' -import { getMyUserInformation, makeGetRequest, root, ServerInfo } from '../' +import { getMyUserInformation, makeGetRequest, root, ServerInfo, testImage } from '../' import { VideoPrivacy } from '../../../../shared/models/videos' import { readdirPromise, readFileBufferPromise } from '../../../helpers/core-utils' import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../initializers' @@ -219,23 +219,6 @@ async function checkVideoFilesWereRemoved (videoUUID: string, serverNumber: numb } } -async function testImage (url: string, imageName: string, imagePath: string, extension = '.jpg') { - // Don't test images if the node env is not set - // Because we need a special ffmpeg version for this test - if (process.env['NODE_TEST_IMAGE']) { - const res = await request(url) - .get(imagePath) - .expect(200) - - const data = await readFileBufferPromise(join(__dirname, '..', '..', 'api', 'fixtures', imageName + extension)) - - return data.equals(res.body) - } else { - console.log('Do not test images. Enable it by setting NODE_TEST_IMAGE env variable.') - return true - } -} - async function uploadVideo (url: string, accessToken: string, videoAttributesArg: VideoAttributes, specialStatus = 200) { const path = '/api/v1/videos/upload' let defaultChannelId = '1' @@ -453,7 +436,6 @@ export { searchVideo, searchVideoWithPagination, searchVideoWithSort, - testImage, uploadVideo, updateVideo, rateVideo, -- cgit v1.2.3