Fix tests

pull/245/head
Chocobozzz 2018-01-24 11:03:13 +01:00
parent 1569a81894
commit 9ee83eb99e
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
3 changed files with 28 additions and 19 deletions

View File

@ -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
}

View File

@ -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,