diff options
author | Chocobozzz <me@florianbigard.com> | 2018-01-24 11:03:13 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-01-24 11:03:13 +0100 |
commit | 9ee83eb99e908c6038cbb6501bacfe18d092f0b6 (patch) | |
tree | 644a629298a1cee3aa0100d0562f7aa863a0f23b /server/tests | |
parent | 1569a81894b75a8e4ec481ea94e6148b090882f5 (diff) | |
download | PeerTube-9ee83eb99e908c6038cbb6501bacfe18d092f0b6.tar.gz PeerTube-9ee83eb99e908c6038cbb6501bacfe18d092f0b6.tar.zst PeerTube-9ee83eb99e908c6038cbb6501bacfe18d092f0b6.zip |
Fix tests
Diffstat (limited to 'server/tests')
-rw-r--r-- | server/tests/utils/miscs/miscs.ts | 27 | ||||
-rw-r--r-- | server/tests/utils/videos/videos.ts | 20 |
2 files changed, 28 insertions, 19 deletions
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 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import { expect } from 'chai' | ||
1 | import { join } from 'path' | 4 | import { join } from 'path' |
5 | import * as request from 'supertest' | ||
2 | import * as WebTorrent from 'webtorrent' | 6 | import * as WebTorrent from 'webtorrent' |
7 | import { readFileBufferPromise } from '../../../helpers/core-utils' | ||
3 | 8 | ||
4 | let webtorrent = new WebTorrent() | 9 | let webtorrent = new WebTorrent() |
5 | 10 | ||
@@ -30,6 +35,27 @@ function root () { | |||
30 | return join(__dirname, '..', '..', '..', '..') | 35 | return join(__dirname, '..', '..', '..', '..') |
31 | } | 36 | } |
32 | 37 | ||
38 | async function testImage (url: string, imageName: string, imagePath: string, extension = '.jpg') { | ||
39 | // Don't test images if the node env is not set | ||
40 | // Because we need a special ffmpeg version for this test | ||
41 | if (process.env[ 'NODE_TEST_IMAGE' ]) { | ||
42 | const res = await request(url) | ||
43 | .get(imagePath) | ||
44 | .expect(200) | ||
45 | |||
46 | const body = res.body | ||
47 | |||
48 | const data = await readFileBufferPromise(join(__dirname, '..', '..', 'api', 'fixtures', imageName + extension)) | ||
49 | const minLength = body.length - ((50 * body.length) / 100) | ||
50 | const maxLength = body.length + ((50 * body.length) / 100) | ||
51 | |||
52 | return data.length > minLength && data.length < maxLength | ||
53 | } else { | ||
54 | console.log('Do not test images. Enable it by setting NODE_TEST_IMAGE env variable.') | ||
55 | return true | ||
56 | } | ||
57 | } | ||
58 | |||
33 | // --------------------------------------------------------------------------- | 59 | // --------------------------------------------------------------------------- |
34 | 60 | ||
35 | export { | 61 | export { |
@@ -37,5 +63,6 @@ export { | |||
37 | wait, | 63 | wait, |
38 | webtorrentAdd, | 64 | webtorrentAdd, |
39 | immutableAssign, | 65 | immutableAssign, |
66 | testImage, | ||
40 | root | 67 | root |
41 | } | 68 | } |
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' | |||
5 | import * as parseTorrent from 'parse-torrent' | 5 | import * as parseTorrent from 'parse-torrent' |
6 | import { extname, isAbsolute, join } from 'path' | 6 | import { extname, isAbsolute, join } from 'path' |
7 | import * as request from 'supertest' | 7 | import * as request from 'supertest' |
8 | import { getMyUserInformation, makeGetRequest, root, ServerInfo } from '../' | 8 | import { getMyUserInformation, makeGetRequest, root, ServerInfo, testImage } from '../' |
9 | import { VideoPrivacy } from '../../../../shared/models/videos' | 9 | import { VideoPrivacy } from '../../../../shared/models/videos' |
10 | import { readdirPromise, readFileBufferPromise } from '../../../helpers/core-utils' | 10 | import { readdirPromise, readFileBufferPromise } from '../../../helpers/core-utils' |
11 | import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../initializers' | 11 | import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../initializers' |
@@ -219,23 +219,6 @@ async function checkVideoFilesWereRemoved (videoUUID: string, serverNumber: numb | |||
219 | } | 219 | } |
220 | } | 220 | } |
221 | 221 | ||
222 | async function testImage (url: string, imageName: string, imagePath: string, extension = '.jpg') { | ||
223 | // Don't test images if the node env is not set | ||
224 | // Because we need a special ffmpeg version for this test | ||
225 | if (process.env['NODE_TEST_IMAGE']) { | ||
226 | const res = await request(url) | ||
227 | .get(imagePath) | ||
228 | .expect(200) | ||
229 | |||
230 | const data = await readFileBufferPromise(join(__dirname, '..', '..', 'api', 'fixtures', imageName + extension)) | ||
231 | |||
232 | return data.equals(res.body) | ||
233 | } else { | ||
234 | console.log('Do not test images. Enable it by setting NODE_TEST_IMAGE env variable.') | ||
235 | return true | ||
236 | } | ||
237 | } | ||
238 | |||
239 | async function uploadVideo (url: string, accessToken: string, videoAttributesArg: VideoAttributes, specialStatus = 200) { | 222 | async function uploadVideo (url: string, accessToken: string, videoAttributesArg: VideoAttributes, specialStatus = 200) { |
240 | const path = '/api/v1/videos/upload' | 223 | const path = '/api/v1/videos/upload' |
241 | let defaultChannelId = '1' | 224 | let defaultChannelId = '1' |
@@ -453,7 +436,6 @@ export { | |||
453 | searchVideo, | 436 | searchVideo, |
454 | searchVideoWithPagination, | 437 | searchVideoWithPagination, |
455 | searchVideoWithSort, | 438 | searchVideoWithSort, |
456 | testImage, | ||
457 | uploadVideo, | 439 | uploadVideo, |
458 | updateVideo, | 440 | updateVideo, |
459 | rateVideo, | 441 | rateVideo, |